Auto merge of #8117 - hotate29:issue7320, r=camsteffen
update: ```Sugg::not()``` replacing the comparison operator. #7320 fixes #7320 changelog: ```needless_bool```: Changed to make a smart suggestion.
This commit is contained in:
commit
c1cd64b9c6
11 changed files with 307 additions and 128 deletions
|
|
@ -43,7 +43,7 @@ LL | / for i in 3..(3 + src.len()) {
|
|||
LL | | dst[i] = src[count];
|
||||
LL | | count += 1;
|
||||
LL | | }
|
||||
| |_____^ help: try replacing the loop by: `dst[3..(3 + src.len())].clone_from_slice(&src[..((3 + src.len()) - 3)]);`
|
||||
| |_____^ help: try replacing the loop by: `dst[3..(3 + src.len())].clone_from_slice(&src[..(3 + src.len() - 3)]);`
|
||||
|
||||
error: it looks like you're manually copying between slices
|
||||
--> $DIR/with_loop_counters.rs:35:5
|
||||
|
|
|
|||
|
|
@ -41,6 +41,15 @@ fn main() {
|
|||
x;
|
||||
!x;
|
||||
!(x && y);
|
||||
let a = 0;
|
||||
let b = 1;
|
||||
|
||||
a != b;
|
||||
a == b;
|
||||
a >= b;
|
||||
a > b;
|
||||
a <= b;
|
||||
a < b;
|
||||
if x {
|
||||
x
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,39 @@ fn main() {
|
|||
} else {
|
||||
true
|
||||
};
|
||||
let a = 0;
|
||||
let b = 1;
|
||||
|
||||
if a == b {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if a != b {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if a < b {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if a <= b {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if a > b {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if a >= b {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if x {
|
||||
x
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,67 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `!(x && y)`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:72:5
|
||||
--> $DIR/fixable.rs:59:5
|
||||
|
|
||||
LL | / if a == b {
|
||||
LL | | false
|
||||
LL | | } else {
|
||||
LL | | true
|
||||
LL | | };
|
||||
| |_____^ help: you can reduce it to: `a != b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:64:5
|
||||
|
|
||||
LL | / if a != b {
|
||||
LL | | false
|
||||
LL | | } else {
|
||||
LL | | true
|
||||
LL | | };
|
||||
| |_____^ help: you can reduce it to: `a == b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:69:5
|
||||
|
|
||||
LL | / if a < b {
|
||||
LL | | false
|
||||
LL | | } else {
|
||||
LL | | true
|
||||
LL | | };
|
||||
| |_____^ help: you can reduce it to: `a >= b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:74:5
|
||||
|
|
||||
LL | / if a <= b {
|
||||
LL | | false
|
||||
LL | | } else {
|
||||
LL | | true
|
||||
LL | | };
|
||||
| |_____^ help: you can reduce it to: `a > b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:79:5
|
||||
|
|
||||
LL | / if a > b {
|
||||
LL | | false
|
||||
LL | | } else {
|
||||
LL | | true
|
||||
LL | | };
|
||||
| |_____^ help: you can reduce it to: `a <= b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:84:5
|
||||
|
|
||||
LL | / if a >= b {
|
||||
LL | | false
|
||||
LL | | } else {
|
||||
LL | | true
|
||||
LL | | };
|
||||
| |_____^ help: you can reduce it to: `a < b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:105:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | return true;
|
||||
|
|
@ -41,7 +101,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `return x`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:80:5
|
||||
--> $DIR/fixable.rs:113:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | return false;
|
||||
|
|
@ -51,7 +111,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `return !x`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:88:5
|
||||
--> $DIR/fixable.rs:121:5
|
||||
|
|
||||
LL | / if x && y {
|
||||
LL | | return true;
|
||||
|
|
@ -61,7 +121,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `return x && y`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:96:5
|
||||
--> $DIR/fixable.rs:129:5
|
||||
|
|
||||
LL | / if x && y {
|
||||
LL | | return false;
|
||||
|
|
@ -71,7 +131,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `return !(x && y)`
|
||||
|
||||
error: equality checks against true are unnecessary
|
||||
--> $DIR/fixable.rs:104:8
|
||||
--> $DIR/fixable.rs:137:8
|
||||
|
|
||||
LL | if x == true {};
|
||||
| ^^^^^^^^^ help: try simplifying it as shown: `x`
|
||||
|
|
@ -79,25 +139,25 @@ LL | if x == true {};
|
|||
= note: `-D clippy::bool-comparison` implied by `-D warnings`
|
||||
|
||||
error: equality checks against false can be replaced by a negation
|
||||
--> $DIR/fixable.rs:108:8
|
||||
--> $DIR/fixable.rs:141:8
|
||||
|
|
||||
LL | if x == false {};
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: equality checks against true are unnecessary
|
||||
--> $DIR/fixable.rs:118:8
|
||||
--> $DIR/fixable.rs:151:8
|
||||
|
|
||||
LL | if x == true {};
|
||||
| ^^^^^^^^^ help: try simplifying it as shown: `x`
|
||||
|
||||
error: equality checks against false can be replaced by a negation
|
||||
--> $DIR/fixable.rs:119:8
|
||||
--> $DIR/fixable.rs:152:8
|
||||
|
|
||||
LL | if x == false {};
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:128:12
|
||||
--> $DIR/fixable.rs:161:12
|
||||
|
|
||||
LL | } else if returns_bool() {
|
||||
| ____________^
|
||||
|
|
@ -108,7 +168,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `{ !returns_bool() }`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:141:5
|
||||
--> $DIR/fixable.rs:174:5
|
||||
|
|
||||
LL | / if unsafe { no(4) } & 1 != 0 {
|
||||
LL | | true
|
||||
|
|
@ -118,16 +178,16 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:146:30
|
||||
--> $DIR/fixable.rs:179:30
|
||||
|
|
||||
LL | let _brackets_unneeded = if unsafe { no(4) } & 1 != 0 { true } else { false };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `unsafe { no(4) } & 1 != 0`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:149:9
|
||||
--> $DIR/fixable.rs:182:9
|
||||
|
|
||||
LL | if unsafe { no(4) } & 1 != 0 { true } else { false }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
error: aborting due to 21 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
fn main() {
|
||||
if f() { g(); }
|
||||
if !f() { g(); }
|
||||
if !(1 == 2) { g(); }
|
||||
if 1 != 2 { g(); }
|
||||
}
|
||||
|
||||
fn f() -> bool {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ error: boolean short circuit operator in statement may be clearer using an expli
|
|||
--> $DIR/short_circuit_statement.rs:9:5
|
||||
|
|
||||
LL | 1 == 2 || g();
|
||||
| ^^^^^^^^^^^^^^ help: replace it with: `if !(1 == 2) { g(); }`
|
||||
| ^^^^^^^^^^^^^^ help: replace it with: `if 1 != 2 { g(); }`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue