Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE-133117: multiple never-pattern arm doesn't have false_edge_start_block #135409

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions compiler/rustc_mir_build/src/builder/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
return;
}

let false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
candidate.subcandidates.retain_mut(|candidate| {
if candidate.extra_data.is_never {
candidate.visit_leaves(|subcandidate| {
Expand All @@ -2000,8 +2001,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
});
if candidate.subcandidates.is_empty() {
// If `candidate` has become a leaf candidate, ensure it has a `pre_binding_block`.
candidate.pre_binding_block = Some(self.cfg.start_new_block());
// If `candidate` has become a leaf candidate, ensure it has a `pre_binding_block` and `otherwise_block`.
let next_block = self.cfg.start_new_block();
candidate.pre_binding_block = Some(next_block);
candidate.otherwise_block = Some(next_block);
// In addition, if `candidate` doesn't have `false_edge_start_block`, it should be assigned here.
if candidate.false_edge_start_block.is_none() {
candidate.false_edge_start_block = false_edge_start_block;
}
}
}

Expand Down
11 changes: 0 additions & 11 deletions tests/crashes/130779.rs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/crashes/133063.rs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/crashes/133117.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(never_patterns)]
#![allow(incomplete_features)]

enum E { A }

fn main() {
match E::A {
! | //~ ERROR: a trailing `|` is not allowed in an or-pattern
//~^ ERROR: mismatched types
if true => {} //~ ERROR: a never pattern is always unreachable
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
error: a trailing `|` is not allowed in an or-pattern
--> $DIR/ICE-130779-never-arm-no-oatherwise-block.rs:8:11
|
LL | ! |
| - ^
| |
| while parsing this or-pattern starting here
|
help: remove the `|`
|
LL - ! |
LL + !
|

error: a never pattern is always unreachable
--> $DIR/ICE-130779-never-arm-no-oatherwise-block.rs:10:20
|
LL | if true => {}
| ^^
| |
| this will never be executed
| help: remove this expression

error: mismatched types
--> $DIR/ICE-130779-never-arm-no-oatherwise-block.rs:8:9
|
LL | ! |
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `E`

error: aborting due to 3 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(never_type)]
#![feature(never_patterns)]
#![allow(incomplete_features)]

enum Void {}

fn foo(x: Void) {
loop {
match x {
(!|!) if false => {} //~ ERROR a never pattern is always unreachable
_ => {}
}
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: a never pattern is always unreachable
--> $DIR/ICE-133063-never-arm-no-otherwise-block.rs:10:31
|
LL | (!|!) if false => {}
| ^^
| |
| this will never be executed
| help: remove this expression

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![feature(never_type)]
#![feature(never_patterns)]
#![allow(incomplete_features)]

enum Void {}

fn foo(x: Void) {
match x {
(!|!) if true => {} //~ ERROR a never pattern is always unreachable
(!|!) if true => {} //~ ERROR a never pattern is always unreachable
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: a never pattern is always unreachable
--> $DIR/ICE-133117-duplicate-never-arm.rs:9:26
|
LL | (!|!) if true => {}
| ^^
| |
| this will never be executed
| help: remove this expression

error: a never pattern is always unreachable
--> $DIR/ICE-133117-duplicate-never-arm.rs:10:26
|
LL | (!|!) if true => {}
| ^^
| |
| this will never be executed
| help: remove this expression

error: aborting due to 2 previous errors

Loading