Auto merge of #11670 - lengyijun:ignored_unit_pattern_ref, r=dswij
[`ignored_unit_patterns`]: check &(), &&(), ... changelog: [`ignored_unit_patterns`]: check &(), &&(), ...
This commit is contained in:
commit
7ce6e0d853
@ -52,7 +52,7 @@ fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
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,
|
||||
|
@ -38,3 +38,19 @@ pub fn moo(_: ()) {
|
||||
let _: () = foo().unwrap();
|
||||
let _: () = ();
|
||||
}
|
||||
|
||||
fn test_unit_ref_1() {
|
||||
let x: (usize, &&&&&()) = (1, &&&&&&());
|
||||
match x {
|
||||
(1, ()) => unimplemented!(),
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
}
|
||||
|
||||
fn test_unit_ref_2(v: &[(usize, ())]) {
|
||||
for (x, ()) in v {
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
let _ = x;
|
||||
}
|
||||
}
|
||||
|
@ -38,3 +38,19 @@ pub fn moo(_: ()) {
|
||||
let _: () = foo().unwrap();
|
||||
let _: () = ();
|
||||
}
|
||||
|
||||
fn test_unit_ref_1() {
|
||||
let x: (usize, &&&&&()) = (1, &&&&&&());
|
||||
match x {
|
||||
(1, _) => unimplemented!(),
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
}
|
||||
|
||||
fn test_unit_ref_2(v: &[(usize, ())]) {
|
||||
for (x, _) in v {
|
||||
//~^ ERROR: matching over `()` is more explicit
|
||||
let _ = x;
|
||||
}
|
||||
}
|
||||
|
@ -43,5 +43,17 @@ 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: matching over `()` is more explicit
|
||||
--> $DIR/ignored_unit_patterns.rs:52:13
|
||||
|
|
||||
LL | for (x, _) in v {
|
||||
| ^ help: use `()` instead of `_`: `()`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user