Skip to content

Commit 73e5250

Browse files
committed
Fix the ordering on nonminimal_bool
1 parent 920cdb5 commit 73e5250

File tree

3 files changed

+70
-28
lines changed

3 files changed

+70
-28
lines changed

clippy_lints/src/booleans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
207207
}
208208
},
209209
Or(v) => {
210-
for (index, inner) in v.iter().enumerate() {
210+
for (index, inner) in v.iter().rev().enumerate() {
211211
if index > 0 {
212212
self.output.push_str(" || ");
213213
}

tests/ui/booleans.rs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn main() {
1919
let _ = a || !b || !c || !d || !e;
2020
let _ = !(a && b || c);
2121
let _ = !(!a && b);
22+
let _ = !(!a || b);
2223
}
2324

2425
#[allow(unused, clippy::many_single_char_names)]
@@ -30,11 +31,13 @@ fn equality_stuff() {
3031
let e: i32 = unimplemented!();
3132
let _ = a == b && a != b;
3233
let _ = a == b && c == 5 && a == b;
34+
let _ = a == b || c == 5 || a == b;
3335
let _ = a == b && c == 5 && b == a;
3436
let _ = a < b && a >= b;
3537
let _ = a > b && a <= b;
3638
let _ = a > b && a == b;
3739
let _ = a != b || !(a != b || c == d);
40+
let _ = a != b && !(a != b && c == d);
3841
}
3942

4043
#[allow(unused, clippy::many_single_char_names)]
@@ -51,6 +54,7 @@ fn methods_with_negation() {
5154
let _ = !b.is_ok();
5255
let c = false;
5356
let _ = !(a.is_some() && !c);
57+
let _ = !(a.is_some() || !c);
5458
let _ = !(!c ^ c) || !a.is_some();
5559
let _ = (!c ^ c) || !a.is_some();
5660
let _ = !c ^ c || !a.is_some();

tests/ui/booleans.stderr

+65-27
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,28 @@ error: this boolean expression can be simplified
5353
--> $DIR/booleans.rs:21:13
5454
|
5555
LL | let _ = !(!a && b);
56-
| ^^^^^^^^^^ help: try: `!b || a`
56+
| ^^^^^^^^^^ help: try: `a || !b`
57+
58+
error: this boolean expression can be simplified
59+
--> $DIR/booleans.rs:22:13
60+
|
61+
LL | let _ = !(!a || b);
62+
| ^^^^^^^^^^ help: try: `a && !b`
5763

5864
error: this boolean expression contains a logic bug
59-
--> $DIR/booleans.rs:31:13
65+
--> $DIR/booleans.rs:32:13
6066
|
6167
LL | let _ = a == b && a != b;
6268
| ^^^^^^^^^^^^^^^^ help: it would look like the following: `false`
6369
|
6470
help: this expression can be optimized out by applying boolean operations to the outer expression
65-
--> $DIR/booleans.rs:31:13
71+
--> $DIR/booleans.rs:32:13
6672
|
6773
LL | let _ = a == b && a != b;
6874
| ^^^^^^
6975

7076
error: this boolean expression can be simplified
71-
--> $DIR/booleans.rs:32:13
77+
--> $DIR/booleans.rs:33:13
7278
|
7379
LL | let _ = a == b && c == 5 && a == b;
7480
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,11 +83,24 @@ help: try
7783
|
7884
LL | let _ = a == b && c == 5;
7985
| ^^^^^^^^^^^^^^^^
80-
LL | let _ = !(c != 5 || a != b);
86+
LL | let _ = !(a != b || c != 5);
8187
| ^^^^^^^^^^^^^^^^^^^
8288

8389
error: this boolean expression can be simplified
84-
--> $DIR/booleans.rs:33:13
90+
--> $DIR/booleans.rs:34:13
91+
|
92+
LL | let _ = a == b || c == 5 || a == b;
93+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
|
95+
help: try
96+
|
97+
LL | let _ = a == b || c == 5;
98+
| ^^^^^^^^^^^^^^^^
99+
LL | let _ = !(a != b && c != 5);
100+
| ^^^^^^^^^^^^^^^^^^^
101+
102+
error: this boolean expression can be simplified
103+
--> $DIR/booleans.rs:35:13
85104
|
86105
LL | let _ = a == b && c == 5 && b == a;
87106
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -90,117 +109,136 @@ help: try
90109
|
91110
LL | let _ = a == b && c == 5;
92111
| ^^^^^^^^^^^^^^^^
93-
LL | let _ = !(c != 5 || a != b);
112+
LL | let _ = !(a != b || c != 5);
94113
| ^^^^^^^^^^^^^^^^^^^
95114

96115
error: this boolean expression contains a logic bug
97-
--> $DIR/booleans.rs:34:13
116+
--> $DIR/booleans.rs:36:13
98117
|
99118
LL | let _ = a < b && a >= b;
100119
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
101120
|
102121
help: this expression can be optimized out by applying boolean operations to the outer expression
103-
--> $DIR/booleans.rs:34:13
122+
--> $DIR/booleans.rs:36:13
104123
|
105124
LL | let _ = a < b && a >= b;
106125
| ^^^^^
107126

108127
error: this boolean expression contains a logic bug
109-
--> $DIR/booleans.rs:35:13
128+
--> $DIR/booleans.rs:37:13
110129
|
111130
LL | let _ = a > b && a <= b;
112131
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
113132
|
114133
help: this expression can be optimized out by applying boolean operations to the outer expression
115-
--> $DIR/booleans.rs:35:13
134+
--> $DIR/booleans.rs:37:13
116135
|
117136
LL | let _ = a > b && a <= b;
118137
| ^^^^^
119138

120139
error: this boolean expression can be simplified
121-
--> $DIR/booleans.rs:37:13
140+
--> $DIR/booleans.rs:39:13
122141
|
123142
LL | let _ = a != b || !(a != b || c == d);
124143
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125144
|
126145
help: try
127146
|
128-
LL | let _ = c != d || a != b;
147+
LL | let _ = a != b || c != d;
129148
| ^^^^^^^^^^^^^^^^
130149
LL | let _ = !(a == b && c == d);
131150
| ^^^^^^^^^^^^^^^^^^^
132151

133152
error: this boolean expression can be simplified
134-
--> $DIR/booleans.rs:45:13
153+
--> $DIR/booleans.rs:40:13
154+
|
155+
LL | let _ = a != b && !(a != b && c == d);
156+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
157+
|
158+
help: try
159+
|
160+
LL | let _ = a != b && c != d;
161+
| ^^^^^^^^^^^^^^^^
162+
LL | let _ = !(a == b || c == d);
163+
| ^^^^^^^^^^^^^^^^^^^
164+
165+
error: this boolean expression can be simplified
166+
--> $DIR/booleans.rs:48:13
135167
|
136168
LL | let _ = !a.is_some();
137169
| ^^^^^^^^^^^^ help: try: `a.is_none()`
138170

139171
error: this boolean expression can be simplified
140-
--> $DIR/booleans.rs:47:13
172+
--> $DIR/booleans.rs:50:13
141173
|
142174
LL | let _ = !a.is_none();
143175
| ^^^^^^^^^^^^ help: try: `a.is_some()`
144176

145177
error: this boolean expression can be simplified
146-
--> $DIR/booleans.rs:49:13
178+
--> $DIR/booleans.rs:52:13
147179
|
148180
LL | let _ = !b.is_err();
149181
| ^^^^^^^^^^^ help: try: `b.is_ok()`
150182

151183
error: this boolean expression can be simplified
152-
--> $DIR/booleans.rs:51:13
184+
--> $DIR/booleans.rs:54:13
153185
|
154186
LL | let _ = !b.is_ok();
155187
| ^^^^^^^^^^ help: try: `b.is_err()`
156188

157189
error: this boolean expression can be simplified
158-
--> $DIR/booleans.rs:53:13
190+
--> $DIR/booleans.rs:56:13
159191
|
160192
LL | let _ = !(a.is_some() && !c);
161-
| ^^^^^^^^^^^^^^^^^^^^ help: try: `c || a.is_none()`
193+
| ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() || c`
194+
195+
error: this boolean expression can be simplified
196+
--> $DIR/booleans.rs:57:13
197+
|
198+
LL | let _ = !(a.is_some() || !c);
199+
| ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() && c`
162200

163201
error: this boolean expression can be simplified
164-
--> $DIR/booleans.rs:54:26
202+
--> $DIR/booleans.rs:58:26
165203
|
166204
LL | let _ = !(!c ^ c) || !a.is_some();
167205
| ^^^^^^^^^^^^ help: try: `a.is_none()`
168206

169207
error: this boolean expression can be simplified
170-
--> $DIR/booleans.rs:55:25
208+
--> $DIR/booleans.rs:59:25
171209
|
172210
LL | let _ = (!c ^ c) || !a.is_some();
173211
| ^^^^^^^^^^^^ help: try: `a.is_none()`
174212

175213
error: this boolean expression can be simplified
176-
--> $DIR/booleans.rs:56:23
214+
--> $DIR/booleans.rs:60:23
177215
|
178216
LL | let _ = !c ^ c || !a.is_some();
179217
| ^^^^^^^^^^^^ help: try: `a.is_none()`
180218

181219
error: this boolean expression can be simplified
182-
--> $DIR/booleans.rs:128:8
220+
--> $DIR/booleans.rs:132:8
183221
|
184222
LL | if !res.is_ok() {}
185223
| ^^^^^^^^^^^^ help: try: `res.is_err()`
186224

187225
error: this boolean expression can be simplified
188-
--> $DIR/booleans.rs:129:8
226+
--> $DIR/booleans.rs:133:8
189227
|
190228
LL | if !res.is_err() {}
191229
| ^^^^^^^^^^^^^ help: try: `res.is_ok()`
192230

193231
error: this boolean expression can be simplified
194-
--> $DIR/booleans.rs:132:8
232+
--> $DIR/booleans.rs:136:8
195233
|
196234
LL | if !res.is_some() {}
197235
| ^^^^^^^^^^^^^^ help: try: `res.is_none()`
198236

199237
error: this boolean expression can be simplified
200-
--> $DIR/booleans.rs:133:8
238+
--> $DIR/booleans.rs:137:8
201239
|
202240
LL | if !res.is_none() {}
203241
| ^^^^^^^^^^^^^^ help: try: `res.is_some()`
204242

205-
error: aborting due to 25 previous errors
243+
error: aborting due to 29 previous errors
206244

0 commit comments

Comments
 (0)