Skip to content
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
6 changes: 6 additions & 0 deletions compiler/rustc_mir_build/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
{
continue;
}
// Ignore return value plumbing. After a call returning a non-`!`
// uninhabited type, a tail expression can be unreachable while
// still being needed to satisfy the surrounding return type.
StatementKind::Assign((place, _)) if place.as_local() == Some(RETURN_PLACE) => {
continue;
}
StatementKind::StorageLive(_) | StatementKind::StorageDead(_) => {
continue;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/uninhabited/unreachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//@ check-pass
#![deny(unreachable_code)]

use std::process::ExitCode;

enum Never {}

fn make_never() -> Never {
Expand All @@ -28,6 +30,14 @@ fn branchy() {
}
}

// Regression test for https://github.com/rust-lang/rust/issues/152559.
// The final expression is unreachable at runtime, but it cannot be removed
// because it supplies the function's required return type.
fn required_return_value() -> ExitCode {
make_never();
ExitCode::FAILURE
}

fn main() {
func();
block();
Expand Down
Loading