about summary refs log tree commit diff
path: root/tests/ui/needless_bool
diff options
context:
space:
mode:
authorflip1995 <philipp.krones@embecosm.com>2021-12-30 14:04:13 +0100
committerflip1995 <philipp.krones@embecosm.com>2021-12-30 14:17:53 +0100
commite45842e3602e806345b3355ed0955e604daef49c (patch)
treedb4d1481f0b49bae4bdeedea435b5cfc0ceb6e38 /tests/ui/needless_bool
parent01217f6f4c752700754e8e66eb02d763c4c55c72 (diff)
parentc1cd64b9c6b29ed2a577fc174a50c76267a966e2 (diff)
downloadrust-e45842e3602e806345b3355ed0955e604daef49c.tar.gz
rust-e45842e3602e806345b3355ed0955e604daef49c.zip
Merge remote-tracking branch 'upstream/master' into rustup
Diffstat (limited to 'tests/ui/needless_bool')
-rw-r--r--tests/ui/needless_bool/fixable.fixed9
-rw-r--r--tests/ui/needless_bool/fixable.rs33
-rw-r--r--tests/ui/needless_bool/fixable.stderr86
3 files changed, 115 insertions, 13 deletions
diff --git a/tests/ui/needless_bool/fixable.fixed b/tests/ui/needless_bool/fixable.fixed
index 85da1f4e104..89dc13fd5b1 100644
--- a/tests/ui/needless_bool/fixable.fixed
+++ b/tests/ui/needless_bool/fixable.fixed
@@ -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 {
diff --git a/tests/ui/needless_bool/fixable.rs b/tests/ui/needless_bool/fixable.rs
index add60630251..c11d9472e8d 100644
--- a/tests/ui/needless_bool/fixable.rs
+++ b/tests/ui/needless_bool/fixable.rs
@@ -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 {
diff --git a/tests/ui/needless_bool/fixable.stderr b/tests/ui/needless_bool/fixable.stderr
index 22c0a7bb491..d2c48376f76 100644
--- a/tests/ui/needless_bool/fixable.stderr
+++ b/tests/ui/needless_bool/fixable.stderr
@@ -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