Skip to content

Commit 3a83422

Browse files
committed
Fix ICE-133063
If all subcandidates have never-pattern, the parent candidate should have otherwise_block because some methods expect the candidate has the block. Signed-off-by: Shunpoco <[email protected]>
1 parent 13f3924 commit 3a83422

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19581958
// This candidate is about to become a leaf, so unset `or_span`.
19591959
let or_span = candidate.or_span.take().unwrap();
19601960
let source_info = self.source_info(or_span);
1961-
1961+
19621962
if candidate.false_edge_start_block.is_none() {
19631963
candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
19641964
}
@@ -2000,8 +2000,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20002000
}
20012001
});
20022002
if candidate.subcandidates.is_empty() {
2003-
// If `candidate` has become a leaf candidate, ensure it has a `pre_binding_block`.
2004-
candidate.pre_binding_block = Some(self.cfg.start_new_block());
2003+
// If `candidate` has become a leaf candidate, ensure it has a `pre_binding_block` and `otherwise_block`.
2004+
let next_block = self.cfg.start_new_block();
2005+
candidate.pre_binding_block = Some(next_block);
2006+
candidate.otherwise_block = Some(next_block);
20052007
}
20062008
}
20072009

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(never_patterns)]
2+
#![feature(if_let_guard)]
3+
#![allow(incomplete_features)]
4+
5+
fn split_last(_: &()) -> Option<(&i32, &i32)> {
6+
None
7+
}
8+
9+
fn assign_twice() {
10+
loop {
11+
match () {
12+
(!| //~ ERROR: mismatched types
13+
!) if let _ = split_last(&()) => {} //~ ERROR a never pattern is always unreachable
14+
//~^ ERROR: mismatched types
15+
//~^^ WARNING: irrefutable `if let` guard pattern [irrefutable_let_patterns]
16+
_ => {}
17+
}
18+
}
19+
}
20+
21+
fn main() {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error: a never pattern is always unreachable
2+
--> $DIR/ICE-133063-never-arm-no-otherwise-block.rs:13:46
3+
|
4+
LL | !) if let _ = split_last(&()) => {}
5+
| ^^
6+
| |
7+
| this will never be executed
8+
| help: remove this expression
9+
10+
error: mismatched types
11+
--> $DIR/ICE-133063-never-arm-no-otherwise-block.rs:12:14
12+
|
13+
LL | (!|
14+
| ^ a never pattern must be used on an uninhabited type
15+
|
16+
= note: the matched value is of type `()`
17+
18+
error: mismatched types
19+
--> $DIR/ICE-133063-never-arm-no-otherwise-block.rs:13:13
20+
|
21+
LL | !) if let _ = split_last(&()) => {}
22+
| ^ a never pattern must be used on an uninhabited type
23+
|
24+
= note: the matched value is of type `()`
25+
26+
warning: irrefutable `if let` guard pattern
27+
--> $DIR/ICE-133063-never-arm-no-otherwise-block.rs:13:19
28+
|
29+
LL | !) if let _ = split_last(&()) => {}
30+
| ^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= note: this pattern will always match, so the guard is useless
33+
= help: consider removing the guard and adding a `let` inside the match arm
34+
= note: `#[warn(irrefutable_let_patterns)]` on by default
35+
36+
error: aborting due to 3 previous errors; 1 warning emitted
37+

0 commit comments

Comments
 (0)