about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-10-22 09:15:42 +0200
committerGitHub <noreply@github.com>2023-10-22 09:15:42 +0200
commit4681eb6c94188dc15ec02ea3bcb1aede89754763 (patch)
tree67b3b3e42e8224659edec4400ba479a990786495
parent4d80740c1dcc079e9a95f9b4aedf05dee3dfb605 (diff)
parenta134f1624cd011703378f5f7597854375d74e135 (diff)
downloadrust-4681eb6c94188dc15ec02ea3bcb1aede89754763.tar.gz
rust-4681eb6c94188dc15ec02ea3bcb1aede89754763.zip
Rollup merge of #117034 - Nadrieril:fix-117033, r=cjgillot
Don't crash on empty match in the `nonexhaustive_omitted_patterns` lint

Oops

Fixes https://github.com/rust-lang/rust/issues/117033
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/usefulness.rs3
-rw-r--r--tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns.rs7
2 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
index a8cee5a61ed..5218f772484 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
@@ -884,6 +884,9 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
     cx: &MatchCheckCtxt<'p, 'tcx>,
     column: &[&DeconstructedPat<'p, 'tcx>],
 ) -> Vec<WitnessPat<'tcx>> {
+    if column.is_empty() {
+        return Vec::new();
+    }
     let ty = column[0].ty();
     let pcx = &PatCtxt { cx, ty, span: DUMMY_SP, is_top_level: false };
 
diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns.rs b/tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns.rs
index ecfeb3f9b98..e0a6051a81f 100644
--- a/tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns.rs
+++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns.rs
@@ -251,3 +251,10 @@ fn main() {
 pub fn takes_non_exhaustive(_: NonExhaustiveEnum) {
     let _closure = |_: NonExhaustiveEnum| {};
 }
+
+// ICE #117033
+enum Void {}
+#[deny(non_exhaustive_omitted_patterns)]
+pub fn void(v: Void) -> ! {
+    match v {}
+}