about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCameron Steffen <cam.steffen94@gmail.com>2021-04-02 11:56:32 -0500
committerCameron Steffen <cam.steffen94@gmail.com>2021-04-03 14:17:58 -0500
commit7014340d5713b9401d95a5ca3287163fd407da46 (patch)
tree0dd71e0557f100e808fbf5ba9528fdd9d3af98ba
parent86fb0e82660aafb033414fde46a768fd92f29556 (diff)
downloadrust-7014340d5713b9401d95a5ca3287163fd407da46.tar.gz
rust-7014340d5713b9401d95a5ca3287163fd407da46.zip
Fix ICE
-rw-r--r--clippy_lints/src/matches.rs14
-rw-r--r--tests/ui/crashes/ice-7012.rs17
2 files changed, 25 insertions, 6 deletions
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs
index b13db4cd45c..ba49097fd3b 100644
--- a/clippy_lints/src/matches.rs
+++ b/clippy_lints/src/matches.rs
@@ -1046,16 +1046,18 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
                     path
                 },
                 PatKind::TupleStruct(path, patterns, ..) => {
-                    if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p)) {
-                        let id = cx.qpath_res(path, pat.hir_id).def_id();
-                        missing_variants.retain(|e| e.ctor_def_id != Some(id));
+                    if let Some(id) = cx.qpath_res(path, pat.hir_id).opt_def_id() {
+                        if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p)) {
+                            missing_variants.retain(|e| e.ctor_def_id != Some(id));
+                        }
                     }
                     path
                 },
                 PatKind::Struct(path, patterns, ..) => {
-                    if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p.pat)) {
-                        let id = cx.qpath_res(path, pat.hir_id).def_id();
-                        missing_variants.retain(|e| e.def_id != id);
+                    if let Some(id) = cx.qpath_res(path, pat.hir_id).opt_def_id() {
+                        if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p.pat)) {
+                            missing_variants.retain(|e| e.def_id != id);
+                        }
                     }
                     path
                 },
diff --git a/tests/ui/crashes/ice-7012.rs b/tests/ui/crashes/ice-7012.rs
new file mode 100644
index 00000000000..60bdbc4f124
--- /dev/null
+++ b/tests/ui/crashes/ice-7012.rs
@@ -0,0 +1,17 @@
+#![allow(clippy::all)]
+
+enum _MyOption {
+    None,
+    Some(()),
+}
+
+impl _MyOption {
+    fn _foo(&self) {
+        match self {
+            &Self::Some(_) => {},
+            _ => {},
+        }
+    }
+}
+
+fn main() {}