Skip to content

Commit 5ccf543

Browse files
committedAug 8, 2024·
Auto merge of #11441 - Jarcho:issue_11365, r=xFrednet
`single_match`: fix checking of explicitly matched enums fixes #11365 This approach has false-negatives, but fixing them will require a significant amount of additional state tracking. The comment in `add_and_pats` has the explanation. changelog: `single_match`: correct checking if the match explicitly matches all of an enum's variants.
2 parents bfb10f4 + 8bcecff commit 5ccf543

File tree

12 files changed

+437
-195
lines changed

12 files changed

+437
-195
lines changed
 

‎clippy_lints/src/matches/match_wild_enum.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ enum CommonPrefixSearcher<'a> {
180180
}
181181
impl<'a> CommonPrefixSearcher<'a> {
182182
fn with_path(&mut self, path: &'a [PathSegment<'a>]) {
183-
match path {
184-
[path @ .., _] => self.with_prefix(path),
185-
[] => (),
183+
if let [path @ .., _] = path {
184+
self.with_prefix(path);
186185
}
187186
}
188187

‎clippy_lints/src/matches/overlapping_arms.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,17 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
3333
.filter_map(|arm| {
3434
if let Arm { pat, guard: None, .. } = *arm {
3535
if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind {
36-
let lhs_const = match lhs {
37-
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?,
38-
None => {
39-
let min_val_const = ty.numeric_min_val(cx.tcx)?;
40-
mir_to_const(cx, mir::Const::from_ty_const(min_val_const, ty, cx.tcx))?
41-
},
36+
let lhs_const = if let Some(lhs) = lhs {
37+
constant(cx, cx.typeck_results(), lhs)?
38+
} else {
39+
let min_val_const = ty.numeric_min_val(cx.tcx)?;
40+
mir_to_const(cx, mir::Const::from_ty_const(min_val_const, ty, cx.tcx))?
4241
};
43-
let rhs_const = match rhs {
44-
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?,
45-
None => {
46-
let max_val_const = ty.numeric_max_val(cx.tcx)?;
47-
mir_to_const(cx, mir::Const::from_ty_const(max_val_const, ty, cx.tcx))?
48-
},
42+
let rhs_const = if let Some(rhs) = rhs {
43+
constant(cx, cx.typeck_results(), rhs)?
44+
} else {
45+
let max_val_const = ty.numeric_max_val(cx.tcx)?;
46+
mir_to_const(cx, mir::Const::from_ty_const(max_val_const, ty, cx.tcx))?
4947
};
5048
let lhs_val = lhs_const.int_value(cx, ty)?;
5149
let rhs_val = rhs_const.int_value(cx, ty)?;

‎clippy_lints/src/matches/single_match.rs

Lines changed: 260 additions & 130 deletions
Large diffs are not rendered by default.

‎tests/ui-toml/excessive_nesting/excessive_nesting.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
//@aux-build:../../ui/auxiliary/proc_macros.rs
22
#![rustfmt::skip]
33
#![feature(custom_inner_attributes)]
4-
#![allow(unused)]
5-
#![allow(clippy::let_and_return)]
6-
#![allow(clippy::redundant_closure_call)]
7-
#![allow(clippy::no_effect)]
8-
#![allow(clippy::unnecessary_operation)]
9-
#![allow(clippy::never_loop)]
10-
#![allow(clippy::needless_if)]
114
#![warn(clippy::excessive_nesting)]
12-
#![allow(clippy::collapsible_if, clippy::blocks_in_conditions)]
5+
#![allow(
6+
unused,
7+
clippy::let_and_return,
8+
clippy::redundant_closure_call,
9+
clippy::no_effect,
10+
clippy::unnecessary_operation,
11+
clippy::never_loop,
12+
clippy::needless_if,
13+
clippy::collapsible_if,
14+
clippy::blocks_in_conditions,
15+
clippy::single_match,
16+
)]
1317

1418
#[macro_use]
1519
extern crate proc_macros;

‎tests/ui-toml/excessive_nesting/excessive_nesting.stderr

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this block is too nested
2-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:21:25
2+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:25:25
33
|
44
LL | let w = { 3 };
55
| ^^^^^
@@ -9,7 +9,7 @@ LL | let w = { 3 };
99
= help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]`
1010

1111
error: this block is too nested
12-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:67:17
12+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:71:17
1313
|
1414
LL | / impl C {
1515
LL | | pub fn c() {}
@@ -19,15 +19,15 @@ LL | | }
1919
= help: try refactoring your code to minimize nesting
2020

2121
error: this block is too nested
22-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:81:25
22+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:85:25
2323
|
2424
LL | let x = { 1 }; // not a warning, but cc is
2525
| ^^^^^
2626
|
2727
= help: try refactoring your code to minimize nesting
2828

2929
error: this block is too nested
30-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:98:17
30+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:102:17
3131
|
3232
LL | / pub mod e {
3333
LL | | pub mod f {}
@@ -37,31 +37,31 @@ LL | | } // not here
3737
= help: try refactoring your code to minimize nesting
3838

3939
error: this block is too nested
40-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:111:18
40+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:115:18
4141
|
4242
LL | a_but_not({{{{{{{{0}}}}}}}});
4343
| ^^^^^^^^^^^
4444
|
4545
= help: try refactoring your code to minimize nesting
4646

4747
error: this block is too nested
48-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:112:12
48+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:116:12
4949
|
5050
LL | a.a({{{{{{{{{0}}}}}}}}});
5151
| ^^^^^^^^^^^^^
5252
|
5353
= help: try refactoring your code to minimize nesting
5454

5555
error: this block is too nested
56-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:113:12
56+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:117:12
5757
|
5858
LL | (0, {{{{{{{1}}}}}}});
5959
| ^^^^^^^^^
6060
|
6161
= help: try refactoring your code to minimize nesting
6262

6363
error: this block is too nested
64-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:118:25
64+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:122:25
6565
|
6666
LL | if true {
6767
| _________________________^
@@ -74,7 +74,7 @@ LL | | }
7474
= help: try refactoring your code to minimize nesting
7575

7676
error: this block is too nested
77-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:130:29
77+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:134:29
7878
|
7979
LL | let z = (|| {
8080
| _____________________________^
@@ -86,207 +86,207 @@ LL | | })();
8686
= help: try refactoring your code to minimize nesting
8787

8888
error: this block is too nested
89-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:149:13
89+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:153:13
9090
|
9191
LL | y += {{{{{5}}}}};
9292
| ^^^^^
9393
|
9494
= help: try refactoring your code to minimize nesting
9595

9696
error: this block is too nested
97-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:150:20
97+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:154:20
9898
|
9999
LL | let z = y + {{{{{{{{{5}}}}}}}}};
100100
| ^^^^^^^^^^^^^
101101
|
102102
= help: try refactoring your code to minimize nesting
103103

104104
error: this block is too nested
105-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:151:12
105+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:155:12
106106
|
107107
LL | [0, {{{{{{{{{{0}}}}}}}}}}];
108108
| ^^^^^^^^^^^^^^^
109109
|
110110
= help: try refactoring your code to minimize nesting
111111

112112
error: this block is too nested
113-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:152:25
113+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:156:25
114114
|
115115
LL | let mut xx = [0; {{{{{{{{100}}}}}}}}];
116116
| ^^^^^^^^^^^^^
117117
|
118118
= help: try refactoring your code to minimize nesting
119119

120120
error: this block is too nested
121-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:153:11
121+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:157:11
122122
|
123123
LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}];
124124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125125
|
126126
= help: try refactoring your code to minimize nesting
127127

128128
error: this block is too nested
129-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:154:13
129+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:158:13
130130
|
131131
LL | &mut {{{{{{{{{{y}}}}}}}}}};
132132
| ^^^^^^^^^^^^^^^
133133
|
134134
= help: try refactoring your code to minimize nesting
135135

136136
error: this block is too nested
137-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:156:17
137+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:17
138138
|
139139
LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}}
140140
| ^^^^
141141
|
142142
= help: try refactoring your code to minimize nesting
143143

144144
error: this block is too nested
145-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:156:28
145+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:28
146146
|
147147
LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}}
148148
| ^^^^^^^^^^
149149
|
150150
= help: try refactoring your code to minimize nesting
151151

152152
error: this block is too nested
153-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:158:28
153+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:28
154154
|
155155
LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}}
156156
| ^^^^^^^^^^^^^
157157
|
158158
= help: try refactoring your code to minimize nesting
159159

160160
error: this block is too nested
161-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:158:48
161+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:48
162162
|
163163
LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}}
164164
| ^^^^^^^^
165165
|
166166
= help: try refactoring your code to minimize nesting
167167

168168
error: this block is too nested
169-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:14
169+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:14
170170
|
171171
LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}}
172172
| ^^^^^^^^^^^^^^
173173
|
174174
= help: try refactoring your code to minimize nesting
175175

176176
error: this block is too nested
177-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:35
177+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:35
178178
|
179179
LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}}
180180
| ^^^^^^^^^^^^
181181
|
182182
= help: try refactoring your code to minimize nesting
183183

184184
error: this block is too nested
185-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:23
185+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:166:23
186186
|
187187
LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} };
188188
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189189
|
190190
= help: try refactoring your code to minimize nesting
191191

192192
error: this block is too nested
193-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:8
193+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:8
194194
|
195195
LL | {{{{1;}}}}..{{{{{{3}}}}}};
196196
| ^^^^
197197
|
198198
= help: try refactoring your code to minimize nesting
199199

200200
error: this block is too nested
201-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:20
201+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:20
202202
|
203203
LL | {{{{1;}}}}..{{{{{{3}}}}}};
204204
| ^^^^^^^
205205
|
206206
= help: try refactoring your code to minimize nesting
207207

208208
error: this block is too nested
209-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:165:8
209+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:169:8
210210
|
211211
LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}};
212212
| ^^^^
213213
|
214214
= help: try refactoring your code to minimize nesting
215215

216216
error: this block is too nested
217-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:165:21
217+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:169:21
218218
|
219219
LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}};
220220
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221221
|
222222
= help: try refactoring your code to minimize nesting
223223

224224
error: this block is too nested
225-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:166:10
225+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:170:10
226226
|
227227
LL | ..{{{{{{{5}}}}}}};
228228
| ^^^^^^^^^
229229
|
230230
= help: try refactoring your code to minimize nesting
231231

232232
error: this block is too nested
233-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:167:11
233+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:171:11
234234
|
235235
LL | ..={{{{{3}}}}};
236236
| ^^^^^
237237
|
238238
= help: try refactoring your code to minimize nesting
239239

240240
error: this block is too nested
241-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:8
241+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:172:8
242242
|
243243
LL | {{{{{1;}}}}}..;
244244
| ^^^^^^
245245
|
246246
= help: try refactoring your code to minimize nesting
247247

248248
error: this block is too nested
249-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:170:20
249+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:174:20
250250
|
251251
LL | loop { break {{{{1}}}} };
252252
| ^^^^^
253253
|
254254
= help: try refactoring your code to minimize nesting
255255

256256
error: this block is too nested
257-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:171:13
257+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:13
258258
|
259259
LL | loop {{{{{{}}}}}}
260260
| ^^^^^^
261261
|
262262
= help: try refactoring your code to minimize nesting
263263

264264
error: this block is too nested
265-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:173:14
265+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:177:14
266266
|
267267
LL | match {{{{{{true}}}}}} {
268268
| ^^^^^^^^^^
269269
|
270270
= help: try refactoring your code to minimize nesting
271271

272272
error: this block is too nested
273-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:174:20
273+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:178:20
274274
|
275275
LL | true => {{{{}}}},
276276
| ^^
277277
|
278278
= help: try refactoring your code to minimize nesting
279279

280280
error: this block is too nested
281-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:21
281+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:179:21
282282
|
283283
LL | false => {{{{}}}},
284284
| ^^
285285
|
286286
= help: try refactoring your code to minimize nesting
287287

288288
error: this block is too nested
289-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:181:17
289+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:185:17
290290
|
291291
LL | / {
292292
LL | | println!("warning! :)");
@@ -296,15 +296,15 @@ LL | | }
296296
= help: try refactoring your code to minimize nesting
297297

298298
error: this block is too nested
299-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:190:28
299+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:194:28
300300
|
301301
LL | async fn c() -> u32 {{{{{{{0}}}}}}}
302302
| ^^^^^^^^^
303303
|
304304
= help: try refactoring your code to minimize nesting
305305

306306
error: this block is too nested
307-
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:196:8
307+
--> tests/ui-toml/excessive_nesting/excessive_nesting.rs:200:8
308308
|
309309
LL | {{{{b().await}}}};
310310
| ^^^^^^^^^^^

‎tests/ui/crashes/ice-6254.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())',
33
// compiler/rustc_mir_build/src/thir/pattern/_match.rs:2030:5
44

5-
#[allow(clippy::derive_partial_eq_without_eq)]
5+
#![allow(clippy::derive_partial_eq_without_eq, clippy::single_match)]
6+
67
#[derive(PartialEq)]
78
struct Foo(i32);
89
const FOO_REF_REF: &&Foo = &&Foo(42);

‎tests/ui/patterns.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@aux-build:proc_macros.rs
22
#![warn(clippy::all)]
33
#![allow(unused)]
4-
#![allow(clippy::uninlined_format_args)]
4+
#![allow(clippy::uninlined_format_args, clippy::single_match)]
55

66
#[macro_use]
77
extern crate proc_macros;

‎tests/ui/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@aux-build:proc_macros.rs
22
#![warn(clippy::all)]
33
#![allow(unused)]
4-
#![allow(clippy::uninlined_format_args)]
4+
#![allow(clippy::uninlined_format_args, clippy::single_match)]
55

66
#[macro_use]
77
extern crate proc_macros;

‎tests/ui/single_match.fixed

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,46 @@ mod issue8634 {
253253
}
254254
}
255255
}
256+
257+
fn issue11365() {
258+
enum Foo {
259+
A,
260+
B,
261+
C,
262+
}
263+
use Foo::{A, B, C};
264+
265+
match Some(A) {
266+
Some(A | B | C) => println!(),
267+
None => {},
268+
}
269+
270+
match Some(A) {
271+
Some(A | B) => println!(),
272+
Some { 0: C } | None => {},
273+
}
274+
275+
match [A, A] {
276+
[A, _] => println!(),
277+
[_, A | B | C] => {},
278+
}
279+
280+
match Ok::<_, u32>(Some(A)) {
281+
Ok(Some(A)) => println!(),
282+
Err(_) | Ok(None | Some(B | C)) => {},
283+
}
284+
285+
if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() }
286+
287+
match &Some(A) {
288+
Some(A | B | C) => println!(),
289+
None => {},
290+
}
291+
292+
match &Some(A) {
293+
&Some(A | B | C) => println!(),
294+
None => {},
295+
}
296+
297+
if let Some(A | B) = &Some(A) { println!() }
298+
}

‎tests/ui/single_match.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,52 @@ mod issue8634 {
311311
}
312312
}
313313
}
314+
315+
fn issue11365() {
316+
enum Foo {
317+
A,
318+
B,
319+
C,
320+
}
321+
use Foo::{A, B, C};
322+
323+
match Some(A) {
324+
Some(A | B | C) => println!(),
325+
None => {},
326+
}
327+
328+
match Some(A) {
329+
Some(A | B) => println!(),
330+
Some { 0: C } | None => {},
331+
}
332+
333+
match [A, A] {
334+
[A, _] => println!(),
335+
[_, A | B | C] => {},
336+
}
337+
338+
match Ok::<_, u32>(Some(A)) {
339+
Ok(Some(A)) => println!(),
340+
Err(_) | Ok(None | Some(B | C)) => {},
341+
}
342+
343+
match Ok::<_, u32>(Some(A)) {
344+
Ok(Some(A)) => println!(),
345+
Err(_) | Ok(None | Some(_)) => {},
346+
}
347+
348+
match &Some(A) {
349+
Some(A | B | C) => println!(),
350+
None => {},
351+
}
352+
353+
match &Some(A) {
354+
&Some(A | B | C) => println!(),
355+
None => {},
356+
}
357+
358+
match &Some(A) {
359+
Some(A | B) => println!(),
360+
None | Some(_) => {},
361+
}
362+
}

‎tests/ui/single_match.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,23 @@ LL + }
198198
LL + }
199199
|
200200

201-
error: aborting due to 18 previous errors
201+
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
202+
--> tests/ui/single_match.rs:343:5
203+
|
204+
LL | / match Ok::<_, u32>(Some(A)) {
205+
LL | | Ok(Some(A)) => println!(),
206+
LL | | Err(_) | Ok(None | Some(_)) => {},
207+
LL | | }
208+
| |_____^ help: try: `if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() }`
209+
210+
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
211+
--> tests/ui/single_match.rs:358:5
212+
|
213+
LL | / match &Some(A) {
214+
LL | | Some(A | B) => println!(),
215+
LL | | None | Some(_) => {},
216+
LL | | }
217+
| |_____^ help: try: `if let Some(A | B) = &Some(A) { println!() }`
218+
219+
error: aborting due to 20 previous errors
202220

‎tests/ui/unneeded_field_pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@aux-build:proc_macros.rs
22
#![warn(clippy::unneeded_field_pattern)]
3-
#![allow(dead_code, unused)]
3+
#![allow(dead_code, unused, clippy::single_match)]
44

55
#[macro_use]
66
extern crate proc_macros;

0 commit comments

Comments
 (0)
Please sign in to comment.