mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
Fix match_ref_pats FP on match scrutinee of never type (#15474)
Closes rust-lang/rust-clippy#15378 changelog: [`match_ref_pats`] fix FP on match scrutinee of never type
This commit is contained in:
@@ -17,6 +17,11 @@ pub(crate) fn check<'a, 'b, I>(cx: &LateContext<'_>, scrutinee: &Expr<'_>, pats:
|
||||
return;
|
||||
}
|
||||
|
||||
// `!` cannot be deref-ed
|
||||
if cx.typeck_results().expr_ty(scrutinee).is_never() {
|
||||
return;
|
||||
}
|
||||
|
||||
let (first_sugg, msg, title);
|
||||
let ctxt = expr.span.ctxt();
|
||||
let mut app = Applicability::Unspecified;
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#![warn(clippy::match_ref_pats)]
|
||||
#![allow(dead_code, unused_variables)]
|
||||
#![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)]
|
||||
#![allow(
|
||||
clippy::enum_variant_names,
|
||||
clippy::equatable_if_let,
|
||||
clippy::uninlined_format_args,
|
||||
clippy::empty_loop,
|
||||
clippy::diverging_sub_expression
|
||||
)]
|
||||
|
||||
fn ref_pats() {
|
||||
{
|
||||
@@ -120,4 +126,32 @@ mod issue_7740 {
|
||||
}
|
||||
}
|
||||
|
||||
mod issue15378 {
|
||||
fn never_in_match() {
|
||||
match unimplemented!() {
|
||||
&_ => {},
|
||||
&&&42 => {
|
||||
todo!()
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
match panic!() {
|
||||
&_ => {},
|
||||
&&&42 => {
|
||||
todo!()
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
match loop {} {
|
||||
&_ => {},
|
||||
&&&42 => {
|
||||
todo!()
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#![warn(clippy::match_ref_pats)]
|
||||
#![allow(dead_code, unused_variables)]
|
||||
#![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)]
|
||||
#![allow(
|
||||
clippy::enum_variant_names,
|
||||
clippy::equatable_if_let,
|
||||
clippy::uninlined_format_args,
|
||||
clippy::empty_loop,
|
||||
clippy::diverging_sub_expression
|
||||
)]
|
||||
|
||||
fn ref_pats() {
|
||||
{
|
||||
@@ -120,4 +126,32 @@ fn issue_7740() {
|
||||
}
|
||||
}
|
||||
|
||||
mod issue15378 {
|
||||
fn never_in_match() {
|
||||
match unimplemented!() {
|
||||
&_ => {},
|
||||
&&&42 => {
|
||||
todo!()
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
match panic!() {
|
||||
&_ => {},
|
||||
&&&42 => {
|
||||
todo!()
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
match loop {} {
|
||||
&_ => {},
|
||||
&&&42 => {
|
||||
todo!()
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: you don't need to add `&` to all patterns
|
||||
--> tests/ui/match_ref_pats.rs:8:9
|
||||
--> tests/ui/match_ref_pats.rs:14:9
|
||||
|
|
||||
LL | / match v {
|
||||
LL | |
|
||||
@@ -19,7 +19,7 @@ LL ~ None => println!("none"),
|
||||
|
|
||||
|
||||
error: you don't need to add `&` to both the expression and the patterns
|
||||
--> tests/ui/match_ref_pats.rs:26:5
|
||||
--> tests/ui/match_ref_pats.rs:32:5
|
||||
|
|
||||
LL | / match &w {
|
||||
LL | |
|
||||
@@ -37,7 +37,7 @@ LL ~ None => println!("none"),
|
||||
|
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> tests/ui/match_ref_pats.rs:39:12
|
||||
--> tests/ui/match_ref_pats.rs:45:12
|
||||
|
|
||||
LL | if let &None = a {
|
||||
| -------^^^^^---- help: try: `if a.is_none()`
|
||||
@@ -46,13 +46,13 @@ LL | if let &None = a {
|
||||
= help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> tests/ui/match_ref_pats.rs:45:12
|
||||
--> tests/ui/match_ref_pats.rs:51:12
|
||||
|
|
||||
LL | if let &None = &b {
|
||||
| -------^^^^^----- help: try: `if b.is_none()`
|
||||
|
||||
error: you don't need to add `&` to all patterns
|
||||
--> tests/ui/match_ref_pats.rs:106:9
|
||||
--> tests/ui/match_ref_pats.rs:112:9
|
||||
|
|
||||
LL | / match foobar_variant!(0) {
|
||||
LL | |
|
||||
|
||||
Reference in New Issue
Block a user