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 1 commit
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
8 changes: 5 additions & 3 deletions compiler/rustc_mir_build/src/builder/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// This candidate is about to become a leaf, so unset `or_span`.
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;
}
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
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