]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/bool_comparison.fixed
Rollup merge of #71633 - a1phyr:infallible_error, r=dtolnay
[rust.git] / src / tools / clippy / tests / ui / bool_comparison.fixed
1 // run-rustfix
2
3 #[warn(clippy::bool_comparison)]
4 fn main() {
5     let x = true;
6     if x {
7         "yes"
8     } else {
9         "no"
10     };
11     if !x {
12         "yes"
13     } else {
14         "no"
15     };
16     if x {
17         "yes"
18     } else {
19         "no"
20     };
21     if !x {
22         "yes"
23     } else {
24         "no"
25     };
26     if !x {
27         "yes"
28     } else {
29         "no"
30     };
31     if x {
32         "yes"
33     } else {
34         "no"
35     };
36     if !x {
37         "yes"
38     } else {
39         "no"
40     };
41     if x {
42         "yes"
43     } else {
44         "no"
45     };
46     if !x {
47         "yes"
48     } else {
49         "no"
50     };
51     if x {
52         "yes"
53     } else {
54         "no"
55     };
56     if x {
57         "yes"
58     } else {
59         "no"
60     };
61     if !x {
62         "yes"
63     } else {
64         "no"
65     };
66     let y = true;
67     if !x & y {
68         "yes"
69     } else {
70         "no"
71     };
72     if x & !y {
73         "yes"
74     } else {
75         "no"
76     };
77 }
78
79 #[allow(dead_code)]
80 fn issue3703() {
81     struct Foo;
82     impl PartialEq<bool> for Foo {
83         fn eq(&self, _: &bool) -> bool {
84             true
85         }
86     }
87     impl PartialEq<Foo> for bool {
88         fn eq(&self, _: &Foo) -> bool {
89             true
90         }
91     }
92     impl PartialOrd<bool> for Foo {
93         fn partial_cmp(&self, _: &bool) -> Option<std::cmp::Ordering> {
94             None
95         }
96     }
97     impl PartialOrd<Foo> for bool {
98         fn partial_cmp(&self, _: &Foo) -> Option<std::cmp::Ordering> {
99             None
100         }
101     }
102
103     if Foo == true {}
104     if true == Foo {}
105     if Foo != true {}
106     if true != Foo {}
107     if Foo == false {}
108     if false == Foo {}
109     if Foo != false {}
110     if false != Foo {}
111     if Foo < false {}
112     if false < Foo {}
113 }
114
115 #[allow(dead_code)]
116 fn issue4983() {
117     let a = true;
118     let b = false;
119
120     if a != b {};
121     if a != b {};
122     if a == b {};
123     if !a == !b {};
124
125     if b != a {};
126     if b != a {};
127     if b == a {};
128     if !b == !a {};
129 }