Skip to content

Commit

Permalink
[ignored_unit_patterns]: check &(), &&(), ...
Browse files Browse the repository at this point in the history
  • Loading branch information
lengyijun committed Oct 15, 2023
1 parent c40359d commit 2262b64
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/ignored_unit_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
},
_ => {},
}
if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).is_unit() {
if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).peel_refs().is_unit() {
span_lint_and_sugg(
cx,
IGNORED_UNIT_PATTERNS,
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/ignored_unit_patterns.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ pub fn moo(_: ()) {
let _: () = foo().unwrap();
let _: () = ();
}

fn test_unit_ref() {
let x: (usize, &&&&&()) = (1, &&&&&&());
match x {
(1, ()) => unimplemented!(),
_ => unimplemented!(),
};
}
8 changes: 8 additions & 0 deletions tests/ui/ignored_unit_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ pub fn moo(_: ()) {
let _: () = foo().unwrap();
let _: () = ();
}

fn test_unit_ref() {
let x: (usize, &&&&&()) = (1, &&&&&&());
match x {
(1, _) => unimplemented!(),
_ => unimplemented!(),
};
}
8 changes: 7 additions & 1 deletion tests/ui/ignored_unit_patterns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@ error: matching over `()` is more explicit
LL | let _ = foo().unwrap();
| ^ help: use `()` instead of `_`: `()`

error: aborting due to 7 previous errors
error: matching over `()` is more explicit
--> $DIR/ignored_unit_patterns.rs:45:13
|
LL | (1, _) => unimplemented!(),
| ^ help: use `()` instead of `_`: `()`

error: aborting due to 8 previous errors

0 comments on commit 2262b64

Please sign in to comment.