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 4 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
14 changes: 8 additions & 6 deletions compiler/rustc_mir_build/src/builder/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// in match tree lowering.
fn merge_trivial_subcandidates(&mut self, candidate: &mut Candidate<'_, 'tcx>) {
assert!(!candidate.subcandidates.is_empty());
if candidate.false_edge_start_block.is_none() {
candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
}

Nadrieril marked this conversation as resolved.
Show resolved Hide resolved
if candidate.has_guard {
// FIXME(or_patterns; matthewjasper) Don't give up if we have a guard.
return;
Expand All @@ -1959,10 +1963,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let or_span = candidate.or_span.take().unwrap();
let source_info = self.source_info(or_span);

if candidate.false_edge_start_block.is_none() {
candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
}

// Remove the (known-trivial) subcandidates from the candidate tree,
// so that they aren't visible after match tree lowering, and wire them
// all to join up at a single shared pre-binding block.
Expand Down Expand Up @@ -2000,8 +2000,10 @@ 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);
}
}

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,21 @@
#![feature(never_patterns)]
#![feature(if_let_guard)]
#![allow(incomplete_features)]

fn split_last(_: &()) -> Option<(&i32, &i32)> {
None
}

fn assign_twice() {
loop {
match () {
(!| //~ ERROR: mismatched types
!) if let _ = split_last(&()) => {} //~ ERROR a never pattern is always unreachable
//~^ ERROR: mismatched types
//~^^ WARNING: irrefutable `if let` guard pattern [irrefutable_let_patterns]
_ => {}
}
}
}
Nadrieril marked this conversation as resolved.
Show resolved Hide resolved

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

error: mismatched types
--> $DIR/ICE-133063-never-arm-no-otherwise-block.rs:12:14
|
LL | (!|
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `()`

error: mismatched types
--> $DIR/ICE-133063-never-arm-no-otherwise-block.rs:13:13
|
LL | !) if let _ = split_last(&()) => {}
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `()`

warning: irrefutable `if let` guard pattern
--> $DIR/ICE-133063-never-arm-no-otherwise-block.rs:13:19
|
LL | !) if let _ = split_last(&()) => {}
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this pattern will always match, so the guard is useless
= help: consider removing the guard and adding a `let` inside the match arm
= note: `#[warn(irrefutable_let_patterns)]` on by default

error: aborting due to 3 previous errors; 1 warning emitted

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

fn main() {
match () {
(!|
//~^ ERROR: mismatched types
!) if true => {} //~ ERROR a never pattern is always unreachable
//~^ ERROR: mismatched types
(!|!) if true => {} //~ ERROR a never pattern is always unreachable
}
}
Nadrieril marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
error: a never pattern is always unreachable
--> $DIR/ICE-133117-duplicate-never-arm.rs:8:23
|
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: mismatched types
--> $DIR/ICE-133117-duplicate-never-arm.rs:6:10
|
LL | (!|
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `()`

error: mismatched types
--> $DIR/ICE-133117-duplicate-never-arm.rs:8:9
|
LL | !) if true => {}
| ^ a never pattern must be used on an uninhabited type
|
= note: the matched value is of type `()`

error: aborting due to 4 previous errors

Loading