negations around expressions can make things simpler

This commit is contained in:
Oliver Schneider 2016-03-24 10:54:48 +01:00
parent 03833f666f
commit 37cee84c44
2 changed files with 8 additions and 3 deletions

View file

@ -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;

View file

@ -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);
}