Skip to content

Commit 7ce6e0d

Browse files
committed
Auto merge of #11670 - lengyijun:ignored_unit_pattern_ref, r=dswij
[`ignored_unit_patterns`]: check &(), &&(), ... changelog: [`ignored_unit_patterns`]: check &(), &&(), ...
2 parents 4eb4192 + 536114c commit 7ce6e0d

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

clippy_lints/src/ignored_unit_patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
5252
},
5353
_ => {},
5454
}
55-
if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).is_unit() {
55+
if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).peel_refs().is_unit() {
5656
span_lint_and_sugg(
5757
cx,
5858
IGNORED_UNIT_PATTERNS,

tests/ui/ignored_unit_patterns.fixed

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,19 @@ pub fn moo(_: ()) {
3838
let _: () = foo().unwrap();
3939
let _: () = ();
4040
}
41+
42+
fn test_unit_ref_1() {
43+
let x: (usize, &&&&&()) = (1, &&&&&&());
44+
match x {
45+
(1, ()) => unimplemented!(),
46+
//~^ ERROR: matching over `()` is more explicit
47+
_ => unimplemented!(),
48+
};
49+
}
50+
51+
fn test_unit_ref_2(v: &[(usize, ())]) {
52+
for (x, ()) in v {
53+
//~^ ERROR: matching over `()` is more explicit
54+
let _ = x;
55+
}
56+
}

tests/ui/ignored_unit_patterns.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,19 @@ pub fn moo(_: ()) {
3838
let _: () = foo().unwrap();
3939
let _: () = ();
4040
}
41+
42+
fn test_unit_ref_1() {
43+
let x: (usize, &&&&&()) = (1, &&&&&&());
44+
match x {
45+
(1, _) => unimplemented!(),
46+
//~^ ERROR: matching over `()` is more explicit
47+
_ => unimplemented!(),
48+
};
49+
}
50+
51+
fn test_unit_ref_2(v: &[(usize, ())]) {
52+
for (x, _) in v {
53+
//~^ ERROR: matching over `()` is more explicit
54+
let _ = x;
55+
}
56+
}

tests/ui/ignored_unit_patterns.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,17 @@ error: matching over `()` is more explicit
4343
LL | let _ = foo().unwrap();
4444
| ^ help: use `()` instead of `_`: `()`
4545

46-
error: aborting due to 7 previous errors
46+
error: matching over `()` is more explicit
47+
--> $DIR/ignored_unit_patterns.rs:45:13
48+
|
49+
LL | (1, _) => unimplemented!(),
50+
| ^ help: use `()` instead of `_`: `()`
51+
52+
error: matching over `()` is more explicit
53+
--> $DIR/ignored_unit_patterns.rs:52:13
54+
|
55+
LL | for (x, _) in v {
56+
| ^ help: use `()` instead of `_`: `()`
57+
58+
error: aborting due to 9 previous errors
4759

0 commit comments

Comments
 (0)