about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-04-17 02:35:02 +0000
committerbors <bors@rust-lang.org>2019-04-17 02:35:02 +0000
commitea25f044ec0c0758e5ca26dfeb596b08236cb20f (patch)
treef7b0f680fc5068c4d63ea707f37419c9ebb25aa3
parent1936368da1321efdd29ff939797fdf6741ebb5f6 (diff)
parent90ddf0da6ce8c2aa0ebb9d8d96de4077efd5ca0c (diff)
downloadrust-ea25f044ec0c0758e5ca26dfeb596b08236cb20f.tar.gz
rust-ea25f044ec0c0758e5ca26dfeb596b08236cb20f.zip
Auto merge of #3977 - phansch:add_rustfix_bool_comparison, r=flip1995
Add run-rustfix for bool_comparison lint

cc #3630
-rw-r--r--tests/ui/bool_comparison.fixed113
-rw-r--r--tests/ui/bool_comparison.rs2
-rw-r--r--tests/ui/bool_comparison.stderr28
3 files changed, 129 insertions, 14 deletions
diff --git a/tests/ui/bool_comparison.fixed b/tests/ui/bool_comparison.fixed
new file mode 100644
index 00000000000..0bd73ec2c10
--- /dev/null
+++ b/tests/ui/bool_comparison.fixed
@@ -0,0 +1,113 @@
+// run-rustfix
+
+#[warn(clippy::bool_comparison)]
+fn main() {
+    let x = true;
+    if x {
+        "yes"
+    } else {
+        "no"
+    };
+    if !x {
+        "yes"
+    } else {
+        "no"
+    };
+    if x {
+        "yes"
+    } else {
+        "no"
+    };
+    if !x {
+        "yes"
+    } else {
+        "no"
+    };
+    if !x {
+        "yes"
+    } else {
+        "no"
+    };
+    if x {
+        "yes"
+    } else {
+        "no"
+    };
+    if !x {
+        "yes"
+    } else {
+        "no"
+    };
+    if x {
+        "yes"
+    } else {
+        "no"
+    };
+    if !x {
+        "yes"
+    } else {
+        "no"
+    };
+    if x {
+        "yes"
+    } else {
+        "no"
+    };
+    if x {
+        "yes"
+    } else {
+        "no"
+    };
+    if !x {
+        "yes"
+    } else {
+        "no"
+    };
+    let y = true;
+    if !x & y {
+        "yes"
+    } else {
+        "no"
+    };
+    if x & !y {
+        "yes"
+    } else {
+        "no"
+    };
+}
+
+#[allow(dead_code)]
+fn issue3703() {
+    struct Foo;
+    impl PartialEq<bool> for Foo {
+        fn eq(&self, _: &bool) -> bool {
+            true
+        }
+    }
+    impl PartialEq<Foo> for bool {
+        fn eq(&self, _: &Foo) -> bool {
+            true
+        }
+    }
+    impl PartialOrd<bool> for Foo {
+        fn partial_cmp(&self, _: &bool) -> Option<std::cmp::Ordering> {
+            None
+        }
+    }
+    impl PartialOrd<Foo> for bool {
+        fn partial_cmp(&self, _: &Foo) -> Option<std::cmp::Ordering> {
+            None
+        }
+    }
+
+    if Foo == true {}
+    if true == Foo {}
+    if Foo != true {}
+    if true != Foo {}
+    if Foo == false {}
+    if false == Foo {}
+    if Foo != false {}
+    if false != Foo {}
+    if Foo < false {}
+    if false < Foo {}
+}
diff --git a/tests/ui/bool_comparison.rs b/tests/ui/bool_comparison.rs
index 36d31aa043b..74f504edfd0 100644
--- a/tests/ui/bool_comparison.rs
+++ b/tests/ui/bool_comparison.rs
@@ -1,3 +1,5 @@
+// run-rustfix
+
 #[warn(clippy::bool_comparison)]
 fn main() {
     let x = true;
diff --git a/tests/ui/bool_comparison.stderr b/tests/ui/bool_comparison.stderr
index 2d473d91d66..2aa070a00f3 100644
--- a/tests/ui/bool_comparison.stderr
+++ b/tests/ui/bool_comparison.stderr
@@ -1,5 +1,5 @@
 error: equality checks against true are unnecessary
-  --> $DIR/bool_comparison.rs:4:8
+  --> $DIR/bool_comparison.rs:6:8
    |
 LL |     if x == true {
    |        ^^^^^^^^^ help: try simplifying it as shown: `x`
@@ -7,79 +7,79 @@ 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/bool_comparison.rs:9:8
+  --> $DIR/bool_comparison.rs:11:8
    |
 LL |     if x == false {
    |        ^^^^^^^^^^ help: try simplifying it as shown: `!x`
 
 error: equality checks against true are unnecessary
-  --> $DIR/bool_comparison.rs:14:8
+  --> $DIR/bool_comparison.rs:16:8
    |
 LL |     if true == x {
    |        ^^^^^^^^^ help: try simplifying it as shown: `x`
 
 error: equality checks against false can be replaced by a negation
-  --> $DIR/bool_comparison.rs:19:8
+  --> $DIR/bool_comparison.rs:21:8
    |
 LL |     if false == x {
    |        ^^^^^^^^^^ help: try simplifying it as shown: `!x`
 
 error: inequality checks against true can be replaced by a negation
-  --> $DIR/bool_comparison.rs:24:8
+  --> $DIR/bool_comparison.rs:26:8
    |
 LL |     if x != true {
    |        ^^^^^^^^^ help: try simplifying it as shown: `!x`
 
 error: inequality checks against false are unnecessary
-  --> $DIR/bool_comparison.rs:29:8
+  --> $DIR/bool_comparison.rs:31:8
    |
 LL |     if x != false {
    |        ^^^^^^^^^^ help: try simplifying it as shown: `x`
 
 error: inequality checks against true can be replaced by a negation
-  --> $DIR/bool_comparison.rs:34:8
+  --> $DIR/bool_comparison.rs:36:8
    |
 LL |     if true != x {
    |        ^^^^^^^^^ help: try simplifying it as shown: `!x`
 
 error: inequality checks against false are unnecessary
-  --> $DIR/bool_comparison.rs:39:8
+  --> $DIR/bool_comparison.rs:41:8
    |
 LL |     if false != x {
    |        ^^^^^^^^^^ help: try simplifying it as shown: `x`
 
 error: less than comparison against true can be replaced by a negation
-  --> $DIR/bool_comparison.rs:44:8
+  --> $DIR/bool_comparison.rs:46:8
    |
 LL |     if x < true {
    |        ^^^^^^^^ help: try simplifying it as shown: `!x`
 
 error: greater than checks against false are unnecessary
-  --> $DIR/bool_comparison.rs:49:8
+  --> $DIR/bool_comparison.rs:51:8
    |
 LL |     if false < x {
    |        ^^^^^^^^^ help: try simplifying it as shown: `x`
 
 error: greater than checks against false are unnecessary
-  --> $DIR/bool_comparison.rs:54:8
+  --> $DIR/bool_comparison.rs:56:8
    |
 LL |     if x > false {
    |        ^^^^^^^^^ help: try simplifying it as shown: `x`
 
 error: less than comparison against true can be replaced by a negation
-  --> $DIR/bool_comparison.rs:59:8
+  --> $DIR/bool_comparison.rs:61:8
    |
 LL |     if true > x {
    |        ^^^^^^^^ help: try simplifying it as shown: `!x`
 
 error: order comparisons between booleans can be simplified
-  --> $DIR/bool_comparison.rs:65:8
+  --> $DIR/bool_comparison.rs:67:8
    |
 LL |     if x < y {
    |        ^^^^^ help: try simplifying it as shown: `!x & y`
 
 error: order comparisons between booleans can be simplified
-  --> $DIR/bool_comparison.rs:70:8
+  --> $DIR/bool_comparison.rs:72:8
    |
 LL |     if x > y {
    |        ^^^^^ help: try simplifying it as shown: `x & !y`