Fix the ordering on nonminimal_bool

This commit is contained in:
Yuki Okushi 2020-01-14 07:08:45 +09:00
parent 920cdb59e1
commit 73e525019d
3 changed files with 70 additions and 28 deletions

View File

@ -207,7 +207,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
}
},
Or(v) => {
for (index, inner) in v.iter().enumerate() {
for (index, inner) in v.iter().rev().enumerate() {
if index > 0 {
self.output.push_str(" || ");
}

View File

@ -19,6 +19,7 @@ fn main() {
let _ = a || !b || !c || !d || !e;
let _ = !(a && b || c);
let _ = !(!a && b);
let _ = !(!a || b);
}
#[allow(unused, clippy::many_single_char_names)]
@ -30,11 +31,13 @@ fn equality_stuff() {
let e: i32 = unimplemented!();
let _ = a == b && a != b;
let _ = a == b && c == 5 && a == b;
let _ = a == b || c == 5 || a == b;
let _ = a == b && c == 5 && b == a;
let _ = a < b && a >= b;
let _ = a > b && a <= b;
let _ = a > b && a == b;
let _ = a != b || !(a != b || c == d);
let _ = a != b && !(a != b && c == d);
}
#[allow(unused, clippy::many_single_char_names)]
@ -51,6 +54,7 @@ fn methods_with_negation() {
let _ = !b.is_ok();
let c = false;
let _ = !(a.is_some() && !c);
let _ = !(a.is_some() || !c);
let _ = !(!c ^ c) || !a.is_some();
let _ = (!c ^ c) || !a.is_some();
let _ = !c ^ c || !a.is_some();

View File

@ -53,22 +53,28 @@ error: this boolean expression can be simplified
--> $DIR/booleans.rs:21:13
|
LL | let _ = !(!a && b);
| ^^^^^^^^^^ help: try: `!b || a`
| ^^^^^^^^^^ help: try: `a || !b`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:22:13
|
LL | let _ = !(!a || b);
| ^^^^^^^^^^ help: try: `a && !b`
error: this boolean expression contains a logic bug
--> $DIR/booleans.rs:31:13
--> $DIR/booleans.rs:32:13
|
LL | let _ = a == b && a != b;
| ^^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/booleans.rs:31:13
--> $DIR/booleans.rs:32:13
|
LL | let _ = a == b && a != b;
| ^^^^^^
error: this boolean expression can be simplified
--> $DIR/booleans.rs:32:13
--> $DIR/booleans.rs:33:13
|
LL | let _ = a == b && c == 5 && a == b;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -77,11 +83,24 @@ help: try
|
LL | let _ = a == b && c == 5;
| ^^^^^^^^^^^^^^^^
LL | let _ = !(c != 5 || a != b);
LL | let _ = !(a != b || c != 5);
| ^^^^^^^^^^^^^^^^^^^
error: this boolean expression can be simplified
--> $DIR/booleans.rs:33:13
--> $DIR/booleans.rs:34:13
|
LL | let _ = a == b || c == 5 || a == b;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: try
|
LL | let _ = a == b || c == 5;
| ^^^^^^^^^^^^^^^^
LL | let _ = !(a != b && c != 5);
| ^^^^^^^^^^^^^^^^^^^
error: this boolean expression can be simplified
--> $DIR/booleans.rs:35:13
|
LL | let _ = a == b && c == 5 && b == a;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -90,117 +109,136 @@ help: try
|
LL | let _ = a == b && c == 5;
| ^^^^^^^^^^^^^^^^
LL | let _ = !(c != 5 || a != b);
LL | let _ = !(a != b || c != 5);
| ^^^^^^^^^^^^^^^^^^^
error: this boolean expression contains a logic bug
--> $DIR/booleans.rs:34:13
--> $DIR/booleans.rs:36:13
|
LL | let _ = a < b && a >= b;
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/booleans.rs:34:13
--> $DIR/booleans.rs:36:13
|
LL | let _ = a < b && a >= b;
| ^^^^^
error: this boolean expression contains a logic bug
--> $DIR/booleans.rs:35:13
--> $DIR/booleans.rs:37:13
|
LL | let _ = a > b && a <= b;
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/booleans.rs:35:13
--> $DIR/booleans.rs:37:13
|
LL | let _ = a > b && a <= b;
| ^^^^^
error: this boolean expression can be simplified
--> $DIR/booleans.rs:37:13
--> $DIR/booleans.rs:39:13
|
LL | let _ = a != b || !(a != b || c == d);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: try
|
LL | let _ = c != d || a != b;
LL | let _ = a != b || c != d;
| ^^^^^^^^^^^^^^^^
LL | let _ = !(a == b && c == d);
| ^^^^^^^^^^^^^^^^^^^
error: this boolean expression can be simplified
--> $DIR/booleans.rs:45:13
--> $DIR/booleans.rs:40:13
|
LL | let _ = a != b && !(a != b && c == d);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: try
|
LL | let _ = a != b && c != d;
| ^^^^^^^^^^^^^^^^
LL | let _ = !(a == b || c == d);
| ^^^^^^^^^^^^^^^^^^^
error: this boolean expression can be simplified
--> $DIR/booleans.rs:48:13
|
LL | let _ = !a.is_some();
| ^^^^^^^^^^^^ help: try: `a.is_none()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:47:13
--> $DIR/booleans.rs:50:13
|
LL | let _ = !a.is_none();
| ^^^^^^^^^^^^ help: try: `a.is_some()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:49:13
--> $DIR/booleans.rs:52:13
|
LL | let _ = !b.is_err();
| ^^^^^^^^^^^ help: try: `b.is_ok()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:51:13
--> $DIR/booleans.rs:54:13
|
LL | let _ = !b.is_ok();
| ^^^^^^^^^^ help: try: `b.is_err()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:53:13
--> $DIR/booleans.rs:56:13
|
LL | let _ = !(a.is_some() && !c);
| ^^^^^^^^^^^^^^^^^^^^ help: try: `c || a.is_none()`
| ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() || c`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:54:26
--> $DIR/booleans.rs:57:13
|
LL | let _ = !(a.is_some() || !c);
| ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() && c`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:58:26
|
LL | let _ = !(!c ^ c) || !a.is_some();
| ^^^^^^^^^^^^ help: try: `a.is_none()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:55:25
--> $DIR/booleans.rs:59:25
|
LL | let _ = (!c ^ c) || !a.is_some();
| ^^^^^^^^^^^^ help: try: `a.is_none()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:56:23
--> $DIR/booleans.rs:60:23
|
LL | let _ = !c ^ c || !a.is_some();
| ^^^^^^^^^^^^ help: try: `a.is_none()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:128:8
--> $DIR/booleans.rs:132:8
|
LL | if !res.is_ok() {}
| ^^^^^^^^^^^^ help: try: `res.is_err()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:129:8
--> $DIR/booleans.rs:133:8
|
LL | if !res.is_err() {}
| ^^^^^^^^^^^^^ help: try: `res.is_ok()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:132:8
--> $DIR/booleans.rs:136:8
|
LL | if !res.is_some() {}
| ^^^^^^^^^^^^^^ help: try: `res.is_none()`
error: this boolean expression can be simplified
--> $DIR/booleans.rs:133:8
--> $DIR/booleans.rs:137:8
|
LL | if !res.is_none() {}
| ^^^^^^^^^^^^^^ help: try: `res.is_some()`
error: aborting due to 25 previous errors
error: aborting due to 29 previous errors