Skip to content

Commit

Permalink
Rollup merge of #117398 - Nadrieril:fix-117378, r=compiler-errors
Browse files Browse the repository at this point in the history
Correctly handle nested or-patterns in exhaustiveness

I had assumed nested or-patterns were flattened, and they mostly are but not always.

Fixes #117378
  • Loading branch information
matthiaskrgr committed Oct 30, 2023
2 parents e648f47 + d5e836c commit 342483c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
let specialized = pat.specialize(pcx, &ctor);
for (subpat, column) in specialized.iter().zip(&mut specialized_columns) {
if subpat.is_or_pat() {
column.patterns.extend(subpat.iter_fields())
column.patterns.extend(subpat.flatten_or_pat())
} else {
column.patterns.push(subpat)
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/or-patterns/exhaustiveness-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ fn main() {
((0, 0) | (1, 0),) => {}
_ => {}
}

// This one caused ICE https://github.com/rust-lang/rust/issues/117378
match (0u8, 0) {
(x @ 0 | x @ (1 | 2), _) => {}
(3.., _) => {}
}
}

0 comments on commit 342483c

Please sign in to comment.