diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index b0969f363..cce59df80 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -218,13 +218,8 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { self.output.push_str(&str) } else { self.output.push('!'); - if let ExprBinary(..) = terminal.node { - self.output.push('('); - } - self.recurse(inner); - if let ExprBinary(..) = terminal.node { - self.output.push(';'); - } + let snip = self.snip(terminal); + self.output.push_str(&snip); } }, True | False | Not(_) => { diff --git a/tests/ui/booleans.rs b/tests/ui/booleans.rs index 52ce90dd6..b3463d03c 100644 --- a/tests/ui/booleans.rs +++ b/tests/ui/booleans.rs @@ -53,4 +53,5 @@ fn methods_with_negation() { let _ = !b.is_ok(); let c = false; let _ = !(a.is_some() && !c); + let _ = !(!c ^ c) || !a.is_some(); } diff --git a/tests/ui/booleans.stderr b/tests/ui/booleans.stderr index 05696ba0f..f38e55860 100644 --- a/tests/ui/booleans.stderr +++ b/tests/ui/booleans.stderr @@ -160,3 +160,9 @@ error: this boolean expression can be simplified 55 | let _ = !(a.is_some() && !c); | ^^^^^^^^^^^^^^^^^^^^ help: try: `c || a.is_none()` +error: this boolean expression can be simplified + --> $DIR/booleans.rs:56:13 + | +56 | let _ = !(!c ^ c) || !a.is_some(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!(!c ^ c) || a.is_none()` +