Skip to content

Commit a79db2a

Browse files
committed
Auto merge of #12401 - MarcusGrass:dedup-nonminimal-bool, r=blyxyas
Remove double expr lint Related to #12379. Previously the code manually checked nested binop exprs in unary exprs, but those were caught anyway by `check_expr`. Removed that code path, the path is used in the tests. --- changelog: [`nonminimal_bool`] Remove duplicate output on nested Binops in Unary exprs.
2 parents e485a02 + 8e3ad2e commit a79db2a

File tree

3 files changed

+29
-52
lines changed

3 files changed

+29
-52
lines changed

Diff for: clippy_lints/src/booleans.rs

-22
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
8888

8989
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
9090
match expr.kind {
91-
ExprKind::Unary(UnOp::Not, sub) => check_inverted_condition(cx, expr.span, sub),
9291
// This check the case where an element in a boolean comparison is inverted, like:
9392
//
9493
// ```
@@ -119,27 +118,6 @@ fn bin_op_eq_str(op: BinOpKind) -> Option<&'static str> {
119118
}
120119
}
121120

122-
fn check_inverted_condition(cx: &LateContext<'_>, expr_span: Span, sub_expr: &Expr<'_>) {
123-
if !expr_span.from_expansion()
124-
&& let ExprKind::Binary(op, left, right) = sub_expr.kind
125-
&& let Some(left) = snippet_opt(cx, left.span)
126-
&& let Some(right) = snippet_opt(cx, right.span)
127-
{
128-
let Some(op) = inverted_bin_op_eq_str(op.node) else {
129-
return;
130-
};
131-
span_lint_and_sugg(
132-
cx,
133-
NONMINIMAL_BOOL,
134-
expr_span,
135-
"this boolean expression can be simplified",
136-
"try",
137-
format!("{left} {op} {right}",),
138-
Applicability::MachineApplicable,
139-
);
140-
}
141-
}
142-
143121
fn check_inverted_bool_in_condition(
144122
cx: &LateContext<'_>,
145123
expr_span: Span,

Diff for: tests/ui/nonminimal_bool.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@no-rustfix: overlapping suggestions
2-
//@compile-flags: -Zdeduplicate-diagnostics=yes
32

43
#![feature(lint_reasons)]
54
#![allow(

Diff for: tests/ui/nonminimal_bool.stderr

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this boolean expression can be simplified
2-
--> tests/ui/nonminimal_bool.rs:20:13
2+
--> tests/ui/nonminimal_bool.rs:19:13
33
|
44
LL | let _ = !true;
55
| ^^^^^ help: try: `false`
@@ -8,43 +8,43 @@ LL | let _ = !true;
88
= help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]`
99

1010
error: this boolean expression can be simplified
11-
--> tests/ui/nonminimal_bool.rs:23:13
11+
--> tests/ui/nonminimal_bool.rs:22:13
1212
|
1313
LL | let _ = !false;
1414
| ^^^^^^ help: try: `true`
1515

1616
error: this boolean expression can be simplified
17-
--> tests/ui/nonminimal_bool.rs:25:13
17+
--> tests/ui/nonminimal_bool.rs:24:13
1818
|
1919
LL | let _ = !!a;
2020
| ^^^ help: try: `a`
2121

2222
error: this boolean expression can be simplified
23-
--> tests/ui/nonminimal_bool.rs:27:13
23+
--> tests/ui/nonminimal_bool.rs:26:13
2424
|
2525
LL | let _ = false || a;
2626
| ^^^^^^^^^^ help: try: `a`
2727

2828
error: this boolean expression can be simplified
29-
--> tests/ui/nonminimal_bool.rs:32:13
29+
--> tests/ui/nonminimal_bool.rs:31:13
3030
|
3131
LL | let _ = !(!a && b);
3232
| ^^^^^^^^^^ help: try: `a || !b`
3333

3434
error: this boolean expression can be simplified
35-
--> tests/ui/nonminimal_bool.rs:34:13
35+
--> tests/ui/nonminimal_bool.rs:33:13
3636
|
3737
LL | let _ = !(!a || b);
3838
| ^^^^^^^^^^ help: try: `a && !b`
3939

4040
error: this boolean expression can be simplified
41-
--> tests/ui/nonminimal_bool.rs:36:13
41+
--> tests/ui/nonminimal_bool.rs:35:13
4242
|
4343
LL | let _ = !a && !(b && c);
4444
| ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)`
4545

4646
error: this boolean expression can be simplified
47-
--> tests/ui/nonminimal_bool.rs:45:13
47+
--> tests/ui/nonminimal_bool.rs:44:13
4848
|
4949
LL | let _ = a == b && c == 5 && a == b;
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -57,7 +57,7 @@ LL | let _ = a == b && c == 5;
5757
| ~~~~~~~~~~~~~~~~
5858

5959
error: this boolean expression can be simplified
60-
--> tests/ui/nonminimal_bool.rs:47:13
60+
--> tests/ui/nonminimal_bool.rs:46:13
6161
|
6262
LL | let _ = a == b || c == 5 || a == b;
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -70,7 +70,7 @@ LL | let _ = a == b || c == 5;
7070
| ~~~~~~~~~~~~~~~~
7171

7272
error: this boolean expression can be simplified
73-
--> tests/ui/nonminimal_bool.rs:49:13
73+
--> tests/ui/nonminimal_bool.rs:48:13
7474
|
7575
LL | let _ = a == b && c == 5 && b == a;
7676
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -83,7 +83,7 @@ LL | let _ = a == b && c == 5;
8383
| ~~~~~~~~~~~~~~~~
8484

8585
error: this boolean expression can be simplified
86-
--> tests/ui/nonminimal_bool.rs:51:13
86+
--> tests/ui/nonminimal_bool.rs:50:13
8787
|
8888
LL | let _ = a != b || !(a != b || c == d);
8989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -96,7 +96,7 @@ LL | let _ = a != b || c != d;
9696
| ~~~~~~~~~~~~~~~~
9797

9898
error: this boolean expression can be simplified
99-
--> tests/ui/nonminimal_bool.rs:53:13
99+
--> tests/ui/nonminimal_bool.rs:52:13
100100
|
101101
LL | let _ = a != b && !(a != b && c == d);
102102
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -109,43 +109,43 @@ LL | let _ = a != b && c != d;
109109
| ~~~~~~~~~~~~~~~~
110110

111111
error: this boolean expression can be simplified
112-
--> tests/ui/nonminimal_bool.rs:84:8
112+
--> tests/ui/nonminimal_bool.rs:83:8
113113
|
114114
LL | if matches!(true, true) && true {
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)`
116116

117117
error: this boolean expression can be simplified
118-
--> tests/ui/nonminimal_bool.rs:164:8
118+
--> tests/ui/nonminimal_bool.rs:163:8
119119
|
120120
LL | if !(12 == a) {}
121121
| ^^^^^^^^^^ help: try: `12 != a`
122122

123123
error: this boolean expression can be simplified
124-
--> tests/ui/nonminimal_bool.rs:165:8
124+
--> tests/ui/nonminimal_bool.rs:164:8
125125
|
126126
LL | if !(a == 12) {}
127127
| ^^^^^^^^^^ help: try: `a != 12`
128128

129129
error: this boolean expression can be simplified
130-
--> tests/ui/nonminimal_bool.rs:166:8
130+
--> tests/ui/nonminimal_bool.rs:165:8
131131
|
132132
LL | if !(12 != a) {}
133133
| ^^^^^^^^^^ help: try: `12 == a`
134134

135135
error: this boolean expression can be simplified
136-
--> tests/ui/nonminimal_bool.rs:167:8
136+
--> tests/ui/nonminimal_bool.rs:166:8
137137
|
138138
LL | if !(a != 12) {}
139139
| ^^^^^^^^^^ help: try: `a == 12`
140140

141141
error: this boolean expression can be simplified
142-
--> tests/ui/nonminimal_bool.rs:171:8
142+
--> tests/ui/nonminimal_bool.rs:170:8
143143
|
144144
LL | if !b == true {}
145145
| ^^^^^^^^^^ help: try: `b != true`
146146

147147
error: this comparison might be written more concisely
148-
--> tests/ui/nonminimal_bool.rs:171:8
148+
--> tests/ui/nonminimal_bool.rs:170:8
149149
|
150150
LL | if !b == true {}
151151
| ^^^^^^^^^^ help: try simplifying it as shown: `b != true`
@@ -154,61 +154,61 @@ LL | if !b == true {}
154154
= help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]`
155155

156156
error: equality checks against true are unnecessary
157-
--> tests/ui/nonminimal_bool.rs:171:8
157+
--> tests/ui/nonminimal_bool.rs:170:8
158158
|
159159
LL | if !b == true {}
160160
| ^^^^^^^^^^ help: try simplifying it as shown: `!b`
161161

162162
error: this boolean expression can be simplified
163-
--> tests/ui/nonminimal_bool.rs:172:8
163+
--> tests/ui/nonminimal_bool.rs:171:8
164164
|
165165
LL | if !b != true {}
166166
| ^^^^^^^^^^ help: try: `b == true`
167167

168168
error: inequality checks against true can be replaced by a negation
169-
--> tests/ui/nonminimal_bool.rs:172:8
169+
--> tests/ui/nonminimal_bool.rs:171:8
170170
|
171171
LL | if !b != true {}
172172
| ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)`
173173

174174
error: this boolean expression can be simplified
175-
--> tests/ui/nonminimal_bool.rs:173:8
175+
--> tests/ui/nonminimal_bool.rs:172:8
176176
|
177177
LL | if true == !b {}
178178
| ^^^^^^^^^^ help: try: `true != b`
179179

180180
error: this comparison might be written more concisely
181-
--> tests/ui/nonminimal_bool.rs:173:8
181+
--> tests/ui/nonminimal_bool.rs:172:8
182182
|
183183
LL | if true == !b {}
184184
| ^^^^^^^^^^ help: try simplifying it as shown: `true != b`
185185

186186
error: equality checks against true are unnecessary
187-
--> tests/ui/nonminimal_bool.rs:173:8
187+
--> tests/ui/nonminimal_bool.rs:172:8
188188
|
189189
LL | if true == !b {}
190190
| ^^^^^^^^^^ help: try simplifying it as shown: `!b`
191191

192192
error: this boolean expression can be simplified
193-
--> tests/ui/nonminimal_bool.rs:174:8
193+
--> tests/ui/nonminimal_bool.rs:173:8
194194
|
195195
LL | if true != !b {}
196196
| ^^^^^^^^^^ help: try: `true == b`
197197

198198
error: inequality checks against true can be replaced by a negation
199-
--> tests/ui/nonminimal_bool.rs:174:8
199+
--> tests/ui/nonminimal_bool.rs:173:8
200200
|
201201
LL | if true != !b {}
202202
| ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)`
203203

204204
error: this boolean expression can be simplified
205-
--> tests/ui/nonminimal_bool.rs:175:8
205+
--> tests/ui/nonminimal_bool.rs:174:8
206206
|
207207
LL | if !b == !c {}
208208
| ^^^^^^^^ help: try: `b == c`
209209

210210
error: this boolean expression can be simplified
211-
--> tests/ui/nonminimal_bool.rs:176:8
211+
--> tests/ui/nonminimal_bool.rs:175:8
212212
|
213213
LL | if !b != !c {}
214214
| ^^^^^^^^ help: try: `b != c`

0 commit comments

Comments
 (0)