Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clippy_lints/src/matches/match_ref_pats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ where
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;
Expand Down
36 changes: 35 additions & 1 deletion tests/ui/match_ref_pats.fixed
Original file line number Diff line number Diff line change
@@ -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() {
{
Expand Down Expand Up @@ -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() {}
36 changes: 35 additions & 1 deletion tests/ui/match_ref_pats.rs
Original file line number Diff line number Diff line change
@@ -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() {
{
Expand Down Expand Up @@ -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() {}
10 changes: 5 additions & 5 deletions tests/ui/match_ref_pats.stderr
Original file line number Diff line number Diff line change
@@ -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 | |
Expand All @@ -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 | |
Expand All @@ -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()`
Expand All @@ -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 | |
Expand Down
Loading