Skip to content

Commit a15d987

Browse files
committed
Auto merge of rust-lang#7021 - camsteffen:7012, r=giraffate
Fix ICE rust-lang#7012 changelog: none Fixes rust-lang#7012
2 parents 6bb608c + 7014340 commit a15d987

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

clippy_lints/src/matches.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1046,16 +1046,18 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
10461046
path
10471047
},
10481048
PatKind::TupleStruct(path, patterns, ..) => {
1049-
if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p)) {
1050-
let id = cx.qpath_res(path, pat.hir_id).def_id();
1051-
missing_variants.retain(|e| e.ctor_def_id != Some(id));
1049+
if let Some(id) = cx.qpath_res(path, pat.hir_id).opt_def_id() {
1050+
if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p)) {
1051+
missing_variants.retain(|e| e.ctor_def_id != Some(id));
1052+
}
10521053
}
10531054
path
10541055
},
10551056
PatKind::Struct(path, patterns, ..) => {
1056-
if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p.pat)) {
1057-
let id = cx.qpath_res(path, pat.hir_id).def_id();
1058-
missing_variants.retain(|e| e.def_id != id);
1057+
if let Some(id) = cx.qpath_res(path, pat.hir_id).opt_def_id() {
1058+
if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p.pat)) {
1059+
missing_variants.retain(|e| e.def_id != id);
1060+
}
10591061
}
10601062
path
10611063
},

tests/ui/crashes/ice-7012.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![allow(clippy::all)]
2+
3+
enum _MyOption {
4+
None,
5+
Some(()),
6+
}
7+
8+
impl _MyOption {
9+
fn _foo(&self) {
10+
match self {
11+
&Self::Some(_) => {},
12+
_ => {},
13+
}
14+
}
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)