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