diff --git a/src/booleans.rs b/src/booleans.rs index 49371de5c..e290b896b 100644 --- a/src/booleans.rs +++ b/src/booleans.rs @@ -207,6 +207,10 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { let stats = terminal_stats(&expr); let mut simplified = expr.simplify(); for simple in Bool::Not(Box::new(expr.clone())).simplify() { + match simple { + Bool::Not(_) | Bool::True | Bool::False => {}, + _ => simplified.push(Bool::Not(Box::new(simple.clone()))), + } let simple_negated = simple_negate(simple); if simplified.iter().any(|s| *s == simple_negated) { continue; diff --git a/tests/compile-fail/booleans.rs b/tests/compile-fail/booleans.rs index 31c160980..4630a4635 100644 --- a/tests/compile-fail/booleans.rs +++ b/tests/compile-fail/booleans.rs @@ -6,14 +6,13 @@ fn main() { let a: bool = unimplemented!(); let b: bool = unimplemented!(); + let c: bool = unimplemented!(); let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug //|~ HELP for further information visit //|~ HELP this expression can be optimized out //|~ HELP it would look like the following //|~ SUGGESTION let _ = a; - let _ = !(a && b); //~ ERROR this boolean expression can be simplified - //|~ HELP for further information visit - //|~ SUGGESTION let _ = !b || !a; + let _ = !(a && b); let _ = !true; //~ ERROR this boolean expression can be simplified //|~ HELP for further information visit //|~ SUGGESTION let _ = false; @@ -36,4 +35,6 @@ fn main() { // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; + + let _ = !(a && b || c); }