negations around expressions can make things simpler
This commit is contained in:
parent
03833f666f
commit
37cee84c44
2 changed files with 8 additions and 3 deletions
|
@ -207,6 +207,10 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
||||||
let stats = terminal_stats(&expr);
|
let stats = terminal_stats(&expr);
|
||||||
let mut simplified = expr.simplify();
|
let mut simplified = expr.simplify();
|
||||||
for simple in Bool::Not(Box::new(expr.clone())).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);
|
let simple_negated = simple_negate(simple);
|
||||||
if simplified.iter().any(|s| *s == simple_negated) {
|
if simplified.iter().any(|s| *s == simple_negated) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -6,14 +6,13 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
let a: bool = unimplemented!();
|
let a: bool = unimplemented!();
|
||||||
let b: bool = unimplemented!();
|
let b: bool = unimplemented!();
|
||||||
|
let c: bool = unimplemented!();
|
||||||
let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug
|
let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug
|
||||||
//|~ HELP for further information visit
|
//|~ HELP for further information visit
|
||||||
//|~ HELP this expression can be optimized out
|
//|~ HELP this expression can be optimized out
|
||||||
//|~ HELP it would look like the following
|
//|~ HELP it would look like the following
|
||||||
//|~ SUGGESTION let _ = a;
|
//|~ SUGGESTION let _ = a;
|
||||||
let _ = !(a && b); //~ ERROR this boolean expression can be simplified
|
let _ = !(a && b);
|
||||||
//|~ HELP for further information visit
|
|
||||||
//|~ SUGGESTION let _ = !b || !a;
|
|
||||||
let _ = !true; //~ ERROR this boolean expression can be simplified
|
let _ = !true; //~ ERROR this boolean expression can be simplified
|
||||||
//|~ HELP for further information visit
|
//|~ HELP for further information visit
|
||||||
//|~ SUGGESTION let _ = false;
|
//|~ SUGGESTION let _ = false;
|
||||||
|
@ -36,4 +35,6 @@ fn main() {
|
||||||
|
|
||||||
// don't lint on cfgs
|
// don't lint on cfgs
|
||||||
let _ = cfg!(you_shall_not_not_pass) && a;
|
let _ = cfg!(you_shall_not_not_pass) && a;
|
||||||
|
|
||||||
|
let _ = !(a && b || c);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue