Skip to content

Commit 342483c

Browse files
authored
Rollup merge of #117398 - Nadrieril:fix-117378, r=compiler-errors
Correctly handle nested or-patterns in exhaustiveness I had assumed nested or-patterns were flattened, and they mostly are but not always. Fixes #117378
2 parents e648f47 + d5e836c commit 342483c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
931931
let specialized = pat.specialize(pcx, &ctor);
932932
for (subpat, column) in specialized.iter().zip(&mut specialized_columns) {
933933
if subpat.is_or_pat() {
934-
column.patterns.extend(subpat.iter_fields())
934+
column.patterns.extend(subpat.flatten_or_pat())
935935
} else {
936936
column.patterns.push(subpat)
937937
}

tests/ui/or-patterns/exhaustiveness-pass.rs

+6
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ fn main() {
3535
((0, 0) | (1, 0),) => {}
3636
_ => {}
3737
}
38+
39+
// This one caused ICE https://github.com/rust-lang/rust/issues/117378
40+
match (0u8, 0) {
41+
(x @ 0 | x @ (1 | 2), _) => {}
42+
(3.., _) => {}
43+
}
3844
}

0 commit comments

Comments
 (0)