Skip to content

Commit f467012

Browse files
Move code comments to prevent having weird clippy fmt issues
1 parent a05d3a4 commit f467012

File tree

2 files changed

+69
-56
lines changed

2 files changed

+69
-56
lines changed

tests/ui/const_comparisons.rs

+26-13
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ fn main() {
4040
let status_code = 500; // Value doesn't matter for the lint
4141
let status = Status { code: status_code };
4242

43-
status_code >= 400 && status_code < 500; // Correct
43+
// Correct
44+
status_code >= 400 && status_code < 500;
4445
status_code <= 400 && status_code > 500;
4546
//~^ ERROR: boolean expression will never evaluate to 'true'
4647
//~| NOTE: since `400` < `500`, the expression evaluates to false for any value of `st
@@ -80,22 +81,30 @@ fn main() {
8081
//~| NOTE: `status` cannot simultaneously be greater than and less than `STATUS_SERVER
8182

8283
// Yoda conditions
83-
500 <= status_code && 600 > status_code; // Correct
84-
500 <= status_code && status_code <= 600; // Correct
85-
500 >= status_code && 600 < status_code; // Incorrect
84+
// Correct
85+
500 <= status_code && 600 > status_code;
86+
// Correct
87+
500 <= status_code && status_code <= 600;
88+
// Incorrect
89+
500 >= status_code && 600 < status_code;
8690
//~^ ERROR: boolean expression will never evaluate to 'true'
8791
//~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st
88-
500 >= status_code && status_code > 600; // Incorrect
92+
// Incorrect
93+
500 >= status_code && status_code > 600;
8994
//~^ ERROR: boolean expression will never evaluate to 'true'
9095
//~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st
9196

9297
// Yoda conditions, comparing two different types
93-
500 <= status && 600 > status; // Correct
94-
500 <= status && status <= 600; // Correct
95-
500 >= status && 600 < status; // Incorrect
98+
// Correct
99+
500 <= status && 600 > status;
100+
// Correct
101+
500 <= status && status <= 600;
102+
// Incorrect
103+
500 >= status && 600 < status;
96104
//~^ ERROR: boolean expression will never evaluate to 'true'
97105
//~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st
98-
500 >= status && status > 600; // Incorrect
106+
// Incorrect
107+
500 >= status && status > 600;
99108
//~^ ERROR: boolean expression will never evaluate to 'true'
100109
//~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st
101110

@@ -105,13 +114,17 @@ fn main() {
105114
status_code > 200 && status_code >= 299;
106115
//~^ ERROR: left-hand side of `&&` operator has no effect
107116

108-
status_code >= 500 && status_code > 500; // Useless left
117+
// Useless left
118+
status_code >= 500 && status_code > 500;
109119
//~^ ERROR: left-hand side of `&&` operator has no effect
110-
status_code > 500 && status_code >= 500; // Useless right
120+
// Useless right
121+
status_code > 500 && status_code >= 500;
111122
//~^ ERROR: right-hand side of `&&` operator has no effect
112-
status_code <= 500 && status_code < 500; // Useless left
123+
// Useless left
124+
status_code <= 500 && status_code < 500;
113125
//~^ ERROR: left-hand side of `&&` operator has no effect
114-
status_code < 500 && status_code <= 500; // Useless right
126+
// Useless right
127+
status_code < 500 && status_code <= 500;
115128
//~^ ERROR: right-hand side of `&&` operator has no effect
116129

117130
// Other types

tests/ui/const_comparisons.stderr

+43-43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: boolean expression will never evaluate to 'true'
2-
--> $DIR/const_comparisons.rs:44:5
2+
--> $DIR/const_comparisons.rs:45:5
33
|
44
LL | status_code <= 400 && status_code > 500;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,216 +8,216 @@ LL | status_code <= 400 && status_code > 500;
88
= note: `-D clippy::impossible-comparisons` implied by `-D warnings`
99

1010
error: boolean expression will never evaluate to 'true'
11-
--> $DIR/const_comparisons.rs:47:5
11+
--> $DIR/const_comparisons.rs:48:5
1212
|
1313
LL | status_code > 500 && status_code < 400;
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
1616
= note: since `500` > `400`, the expression evaluates to false for any value of `status_code`
1717

1818
error: boolean expression will never evaluate to 'true'
19-
--> $DIR/const_comparisons.rs:50:5
19+
--> $DIR/const_comparisons.rs:51:5
2020
|
2121
LL | status_code < 500 && status_code > 500;
2222
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2323
|
2424
= note: `status_code` cannot simultaneously be greater than and less than `500`
2525

2626
error: boolean expression will never evaluate to 'true'
27-
--> $DIR/const_comparisons.rs:55:5
27+
--> $DIR/const_comparisons.rs:56:5
2828
|
2929
LL | status_code < { 400 } && status_code > { 500 };
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3131
|
3232
= note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code`
3333

3434
error: boolean expression will never evaluate to 'true'
35-
--> $DIR/const_comparisons.rs:58:5
35+
--> $DIR/const_comparisons.rs:59:5
3636
|
3737
LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR;
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939
|
4040
= note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code`
4141

4242
error: boolean expression will never evaluate to 'true'
43-
--> $DIR/const_comparisons.rs:61:5
43+
--> $DIR/const_comparisons.rs:62:5
4444
|
4545
LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR;
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4747
|
4848
= note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code`
4949

5050
error: boolean expression will never evaluate to 'true'
51-
--> $DIR/const_comparisons.rs:64:5
51+
--> $DIR/const_comparisons.rs:65:5
5252
|
5353
LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR;
5454
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5555
|
5656
= note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR`
5757

5858
error: boolean expression will never evaluate to 'true'
59-
--> $DIR/const_comparisons.rs:69:5
59+
--> $DIR/const_comparisons.rs:70:5
6060
|
6161
LL | status < { 400 } && status > { 500 };
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363
|
6464
= note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status`
6565

6666
error: boolean expression will never evaluate to 'true'
67-
--> $DIR/const_comparisons.rs:72:5
67+
--> $DIR/const_comparisons.rs:73:5
6868
|
6969
LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR;
7070
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7171
|
7272
= note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status`
7373

7474
error: boolean expression will never evaluate to 'true'
75-
--> $DIR/const_comparisons.rs:75:5
75+
--> $DIR/const_comparisons.rs:76:5
7676
|
7777
LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR;
7878
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7979
|
8080
= note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status`
8181

8282
error: boolean expression will never evaluate to 'true'
83-
--> $DIR/const_comparisons.rs:78:5
83+
--> $DIR/const_comparisons.rs:79:5
8484
|
8585
LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR;
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787
|
8888
= note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR`
8989

9090
error: boolean expression will never evaluate to 'true'
91-
--> $DIR/const_comparisons.rs:85:5
91+
--> $DIR/const_comparisons.rs:89:5
9292
|
93-
LL | 500 >= status_code && 600 < status_code; // Incorrect
93+
LL | 500 >= status_code && 600 < status_code;
9494
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9595
|
9696
= note: since `500` < `600`, the expression evaluates to false for any value of `status_code`
9797

9898
error: boolean expression will never evaluate to 'true'
99-
--> $DIR/const_comparisons.rs:88:5
99+
--> $DIR/const_comparisons.rs:93:5
100100
|
101-
LL | 500 >= status_code && status_code > 600; // Incorrect
101+
LL | 500 >= status_code && status_code > 600;
102102
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103103
|
104104
= note: since `500` < `600`, the expression evaluates to false for any value of `status_code`
105105

106106
error: boolean expression will never evaluate to 'true'
107-
--> $DIR/const_comparisons.rs:95:5
107+
--> $DIR/const_comparisons.rs:103:5
108108
|
109-
LL | 500 >= status && 600 < status; // Incorrect
109+
LL | 500 >= status && 600 < status;
110110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111111
|
112112
= note: since `500` < `600`, the expression evaluates to false for any value of `status`
113113

114114
error: boolean expression will never evaluate to 'true'
115-
--> $DIR/const_comparisons.rs:98:5
115+
--> $DIR/const_comparisons.rs:107:5
116116
|
117-
LL | 500 >= status && status > 600; // Incorrect
117+
LL | 500 >= status && status > 600;
118118
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119119
|
120120
= note: since `500` < `600`, the expression evaluates to false for any value of `status`
121121

122122
error: right-hand side of `&&` operator has no effect
123-
--> $DIR/const_comparisons.rs:103:5
123+
--> $DIR/const_comparisons.rs:112:5
124124
|
125125
LL | status_code < 200 && status_code <= 299;
126126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127127
|
128128
note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well
129-
--> $DIR/const_comparisons.rs:103:23
129+
--> $DIR/const_comparisons.rs:112:23
130130
|
131131
LL | status_code < 200 && status_code <= 299;
132132
| ^^^^^^^^^^^^^^^^^^^^^
133133
= note: `-D clippy::redundant-comparisons` implied by `-D warnings`
134134

135135
error: left-hand side of `&&` operator has no effect
136-
--> $DIR/const_comparisons.rs:105:5
136+
--> $DIR/const_comparisons.rs:114:5
137137
|
138138
LL | status_code > 200 && status_code >= 299;
139139
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140140
|
141141
note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well
142-
--> $DIR/const_comparisons.rs:105:5
142+
--> $DIR/const_comparisons.rs:114:5
143143
|
144144
LL | status_code > 200 && status_code >= 299;
145145
| ^^^^^^^^^^^^^^^^^^^^^
146146

147147
error: left-hand side of `&&` operator has no effect
148-
--> $DIR/const_comparisons.rs:108:5
148+
--> $DIR/const_comparisons.rs:118:5
149149
|
150-
LL | status_code >= 500 && status_code > 500; // Useless left
150+
LL | status_code >= 500 && status_code > 500;
151151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152152
|
153153
note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well
154-
--> $DIR/const_comparisons.rs:108:5
154+
--> $DIR/const_comparisons.rs:118:5
155155
|
156-
LL | status_code >= 500 && status_code > 500; // Useless left
156+
LL | status_code >= 500 && status_code > 500;
157157
| ^^^^^^^^^^^^^^^^^^^^^^
158158

159159
error: right-hand side of `&&` operator has no effect
160-
--> $DIR/const_comparisons.rs:110:5
160+
--> $DIR/const_comparisons.rs:121:5
161161
|
162-
LL | status_code > 500 && status_code >= 500; // Useless right
162+
LL | status_code > 500 && status_code >= 500;
163163
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
164164
|
165165
note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well
166-
--> $DIR/const_comparisons.rs:110:23
166+
--> $DIR/const_comparisons.rs:121:23
167167
|
168-
LL | status_code > 500 && status_code >= 500; // Useless right
168+
LL | status_code > 500 && status_code >= 500;
169169
| ^^^^^^^^^^^^^^^^^^^^^
170170

171171
error: left-hand side of `&&` operator has no effect
172-
--> $DIR/const_comparisons.rs:112:5
172+
--> $DIR/const_comparisons.rs:124:5
173173
|
174-
LL | status_code <= 500 && status_code < 500; // Useless left
174+
LL | status_code <= 500 && status_code < 500;
175175
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176176
|
177177
note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well
178-
--> $DIR/const_comparisons.rs:112:5
178+
--> $DIR/const_comparisons.rs:124:5
179179
|
180-
LL | status_code <= 500 && status_code < 500; // Useless left
180+
LL | status_code <= 500 && status_code < 500;
181181
| ^^^^^^^^^^^^^^^^^^^^^^
182182

183183
error: right-hand side of `&&` operator has no effect
184-
--> $DIR/const_comparisons.rs:114:5
184+
--> $DIR/const_comparisons.rs:127:5
185185
|
186-
LL | status_code < 500 && status_code <= 500; // Useless right
186+
LL | status_code < 500 && status_code <= 500;
187187
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188188
|
189189
note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well
190-
--> $DIR/const_comparisons.rs:114:23
190+
--> $DIR/const_comparisons.rs:127:23
191191
|
192-
LL | status_code < 500 && status_code <= 500; // Useless right
192+
LL | status_code < 500 && status_code <= 500;
193193
| ^^^^^^^^^^^^^^^^^^^^^
194194

195195
error: boolean expression will never evaluate to 'true'
196-
--> $DIR/const_comparisons.rs:119:5
196+
--> $DIR/const_comparisons.rs:132:5
197197
|
198198
LL | name < "Jennifer" && name > "Shannon";
199199
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200200
|
201201
= note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name`
202202

203203
error: boolean expression will never evaluate to 'true'
204-
--> $DIR/const_comparisons.rs:124:5
204+
--> $DIR/const_comparisons.rs:137:5
205205
|
206206
LL | numbers < [3, 4] && numbers > [5, 6];
207207
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
208208
|
209209
= note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers`
210210

211211
error: boolean expression will never evaluate to 'true'
212-
--> $DIR/const_comparisons.rs:129:5
212+
--> $DIR/const_comparisons.rs:142:5
213213
|
214214
LL | letter < 'b' && letter > 'c';
215215
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
216216
|
217217
= note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter`
218218

219219
error: boolean expression will never evaluate to 'true'
220-
--> $DIR/const_comparisons.rs:134:5
220+
--> $DIR/const_comparisons.rs:147:5
221221
|
222222
LL | area < std::f32::consts::E && area > std::f32::consts::PI;
223223
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)