mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 22:46:50 +00:00
negations around expressions can make things simpler
This commit is contained in:
parent
03833f666f
commit
37cee84c44
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user