Skip to content

Commit 804d5f2

Browse files
committed
fix: match_ref_pats FP on unimplement!() in match scrutinee
1 parent 306d4e3 commit 804d5f2

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

clippy_lints/src/matches/match_ref_pats.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::{snippet, walk_span_to_context};
33
use clippy_utils::sugg::Sugg;
4+
use clippy_utils::usage::is_todo_unimplemented_stub;
45
use core::iter::once;
56
use rustc_errors::Applicability;
67
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind};
@@ -17,6 +18,11 @@ where
1718
return;
1819
}
1920

21+
// `todo!()` and `unimplemented!()` stub cannot deref
22+
if is_todo_unimplemented_stub(cx, scrutinee) {
23+
return;
24+
}
25+
2026
let (first_sugg, msg, title);
2127
let ctxt = expr.span.ctxt();
2228
let mut app = Applicability::Unspecified;

tests/ui/match_ref_pats.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,16 @@ mod issue_7740 {
120120
}
121121
}
122122

123+
mod issue15378 {
124+
fn unimplemented_in_match() {
125+
match unimplemented!() {
126+
&_ => {},
127+
&&&42 => {
128+
todo!()
129+
},
130+
_ => {},
131+
}
132+
}
133+
}
134+
123135
fn main() {}

tests/ui/match_ref_pats.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,16 @@ mod issue_7740 {
120120
}
121121
}
122122

123+
mod issue15378 {
124+
fn unimplemented_in_match() {
125+
match unimplemented!() {
126+
&_ => {},
127+
&&&42 => {
128+
todo!()
129+
},
130+
_ => {},
131+
}
132+
}
133+
}
134+
123135
fn main() {}

0 commit comments

Comments
 (0)