Skip to content

Commit 8a57fa6

Browse files
committed
Fix ICE-133117
If all subcandidates have never-pattern, we should assign false_edge_start_block to the parent candidate if it doesn't have. merge_trivial_subcandidates does so, but if the candidate has guard it returns before the assignment. Signed-off-by: Shunpoco <[email protected]>
1 parent 3a83422 commit 8a57fa6

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19401940
/// in match tree lowering.
19411941
fn merge_trivial_subcandidates(&mut self, candidate: &mut Candidate<'_, 'tcx>) {
19421942
assert!(!candidate.subcandidates.is_empty());
1943+
if candidate.false_edge_start_block.is_none() {
1944+
candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
1945+
}
1946+
19431947
if candidate.has_guard {
19441948
// FIXME(or_patterns; matthewjasper) Don't give up if we have a guard.
19451949
return;
@@ -1958,10 +1962,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19581962
// This candidate is about to become a leaf, so unset `or_span`.
19591963
let or_span = candidate.or_span.take().unwrap();
19601964
let source_info = self.source_info(or_span);
1961-
1962-
if candidate.false_edge_start_block.is_none() {
1963-
candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
1964-
}
19651965

19661966
// Remove the (known-trivial) subcandidates from the candidate tree,
19671967
// so that they aren't visible after match tree lowering, and wire them
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(never_patterns)]
2+
#![allow(incomplete_features)]
3+
4+
fn main() {
5+
match () {
6+
(!|
7+
//~^ ERROR: mismatched types
8+
!) if true => {} //~ ERROR a never pattern is always unreachable
9+
//~^ ERROR: mismatched types
10+
(!|!) if true => {} //~ ERROR a never pattern is always unreachable
11+
}
12+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error: a never pattern is always unreachable
2+
--> $DIR/ICE-133117-duplicate-never-arm.rs:8:23
3+
|
4+
LL | !) if true => {}
5+
| ^^
6+
| |
7+
| this will never be executed
8+
| help: remove this expression
9+
10+
error: a never pattern is always unreachable
11+
--> $DIR/ICE-133117-duplicate-never-arm.rs:10:26
12+
|
13+
LL | (!|!) if true => {}
14+
| ^^
15+
| |
16+
| this will never be executed
17+
| help: remove this expression
18+
19+
error: mismatched types
20+
--> $DIR/ICE-133117-duplicate-never-arm.rs:6:10
21+
|
22+
LL | (!|
23+
| ^ a never pattern must be used on an uninhabited type
24+
|
25+
= note: the matched value is of type `()`
26+
27+
error: mismatched types
28+
--> $DIR/ICE-133117-duplicate-never-arm.rs:8:9
29+
|
30+
LL | !) if true => {}
31+
| ^ a never pattern must be used on an uninhabited type
32+
|
33+
= note: the matched value is of type `()`
34+
35+
error: aborting due to 4 previous errors
36+

0 commit comments

Comments
 (0)