fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
2.8 KiB167 linesraw
1#![allow(clippy::needless_if)]
2#![warn(clippy::bool_comparison)]
3#![allow(clippy::non_canonical_partial_ord_impl)]
4
5fn main() {
6    let x = true;
7    if x {
8        "yes"
9    } else {
10        "no"
11    };
12    if !x {
13        "yes"
14    } else {
15        "no"
16    };
17    if x {
18        "yes"
19    } else {
20        "no"
21    };
22    if !x {
23        "yes"
24    } else {
25        "no"
26    };
27    if !x {
28        "yes"
29    } else {
30        "no"
31    };
32    if x {
33        "yes"
34    } else {
35        "no"
36    };
37    if !x {
38        "yes"
39    } else {
40        "no"
41    };
42    if x {
43        "yes"
44    } else {
45        "no"
46    };
47    if !x {
48        "yes"
49    } else {
50        "no"
51    };
52    if x {
53        "yes"
54    } else {
55        "no"
56    };
57    if x {
58        "yes"
59    } else {
60        "no"
61    };
62    if !x {
63        "yes"
64    } else {
65        "no"
66    };
67    let y = true;
68    if !x & y {
69        "yes"
70    } else {
71        "no"
72    };
73    if x & !y {
74        "yes"
75    } else {
76        "no"
77    };
78}
79
80#[allow(dead_code)]
81fn issue3703() {
82    struct Foo;
83    impl PartialEq<bool> for Foo {
84        fn eq(&self, _: &bool) -> bool {
85            true
86        }
87    }
88    impl PartialEq<Foo> for bool {
89        fn eq(&self, _: &Foo) -> bool {
90            true
91        }
92    }
93    impl PartialOrd<bool> for Foo {
94        fn partial_cmp(&self, _: &bool) -> Option<std::cmp::Ordering> {
95            None
96        }
97    }
98    impl PartialOrd<Foo> for bool {
99        fn partial_cmp(&self, _: &Foo) -> Option<std::cmp::Ordering> {
100            None
101        }
102    }
103
104    if Foo == true {}
105    if true == Foo {}
106    if Foo != true {}
107    if true != Foo {}
108    if Foo == false {}
109    if false == Foo {}
110    if Foo != false {}
111    if false != Foo {}
112    if Foo < false {}
113    if false < Foo {}
114}
115
116#[allow(dead_code)]
117fn issue4983() {
118    let a = true;
119    let b = false;
120
121    if a != b {};
122    if a != b {};
123    if a == b {};
124    if !a == !b {};
125
126    if b != a {};
127    if b != a {};
128    if b == a {};
129    if !b == !a {};
130}
131
132macro_rules! m {
133    ($func:ident) => {
134        $func()
135    };
136}
137
138fn func() -> bool {
139    true
140}
141
142#[allow(dead_code)]
143fn issue3973() {
144    // ok, don't lint on `cfg` invocation
145    if false == cfg!(feature = "debugging") {}
146    if cfg!(feature = "debugging") == false {}
147    if true == cfg!(feature = "debugging") {}
148    if cfg!(feature = "debugging") == true {}
149
150    // lint, could be simplified
151    if !m!(func) {}
152    if !m!(func) {}
153    if m!(func) {}
154    if m!(func) {}
155
156    // no lint with a variable
157    let is_debug = false;
158    if is_debug == cfg!(feature = "debugging") {}
159    if cfg!(feature = "debugging") == is_debug {}
160    if is_debug == m!(func) {}
161    if m!(func) == is_debug {}
162    let is_debug = true;
163    if is_debug == cfg!(feature = "debugging") {}
164    if cfg!(feature = "debugging") == is_debug {}
165    if is_debug == m!(func) {}
166    if m!(func) == is_debug {}
167}