]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/comparison_chain.rs
Rollup merge of #71806 - lcnr:patch-3, r=jonas-schievink
[rust.git] / src / tools / clippy / tests / ui / comparison_chain.rs
1 #![allow(dead_code)]
2 #![warn(clippy::comparison_chain)]
3
4 fn a() {}
5 fn b() {}
6 fn c() {}
7
8 fn f(x: u8, y: u8, z: u8) {
9     // Ignored: Only one branch
10     if x > y {
11         a()
12     }
13
14     if x > y {
15         a()
16     } else if x < y {
17         b()
18     }
19
20     // Ignored: Only one explicit conditional
21     if x > y {
22         a()
23     } else {
24         b()
25     }
26
27     if x > y {
28         a()
29     } else if x < y {
30         b()
31     } else {
32         c()
33     }
34
35     if x > y {
36         a()
37     } else if y > x {
38         b()
39     } else {
40         c()
41     }
42
43     if x > 1 {
44         a()
45     } else if x < 1 {
46         b()
47     } else if x == 1 {
48         c()
49     }
50
51     // Ignored: Binop args are not equivalent
52     if x > 1 {
53         a()
54     } else if y > 1 {
55         b()
56     } else {
57         c()
58     }
59
60     // Ignored: Binop args are not equivalent
61     if x > y {
62         a()
63     } else if x > z {
64         b()
65     } else if y > z {
66         c()
67     }
68
69     // Ignored: Not binary comparisons
70     if true {
71         a()
72     } else if false {
73         b()
74     } else {
75         c()
76     }
77 }
78
79 #[allow(clippy::float_cmp)]
80 fn g(x: f64, y: f64, z: f64) {
81     // Ignored: f64 doesn't implement Ord
82     if x > y {
83         a()
84     } else if x < y {
85         b()
86     }
87
88     // Ignored: f64 doesn't implement Ord
89     if x > y {
90         a()
91     } else if x < y {
92         b()
93     } else {
94         c()
95     }
96
97     // Ignored: f64 doesn't implement Ord
98     if x > y {
99         a()
100     } else if y > x {
101         b()
102     } else {
103         c()
104     }
105
106     // Ignored: f64 doesn't implement Ord
107     if x > 1.0 {
108         a()
109     } else if x < 1.0 {
110         b()
111     } else if x == 1.0 {
112         c()
113     }
114 }
115
116 fn h<T: Ord>(x: T, y: T, z: T) {
117     if x > y {
118         a()
119     } else if x < y {
120         b()
121     }
122
123     if x > y {
124         a()
125     } else if x < y {
126         b()
127     } else {
128         c()
129     }
130
131     if x > y {
132         a()
133     } else if y > x {
134         b()
135     } else {
136         c()
137     }
138 }
139
140 fn main() {}