I tried this code:
use std::process::ExitCode;
enum Never {}
fn never_returns() -> Never {
todo!()
}
pub fn run() -> ExitCode {
never_returns();
ExitCode::FAILURE
}
And rustc raises an "unreachable expression" warning. This seems reasonable. So I remove that line:
use std::process::ExitCode;
enum Never {}
fn never_returns() -> Never {
todo!()
}
pub fn run() -> ExitCode {
never_returns();
}
I expected to see this happen:
- either rustc can tell that that path is unreachable, and it should not have type errors,
- or rustc can't tell it's unreachable, and the "unreachable expression" warning should not appear.
Instead, this happened: rustc seems to simultaneously indicate that path is unreachable, AND some expression is needed there to satisfy the type-checker.
Is there really no way to write the run function without invoking #[allow(unreachable_code)]? That seems odd. (Sorry, I shouldn't have asked. Didn't mean to nerd-snipe.)
Meta
rustc --version --verbose:
rustc 1.93.1 (01f6ddf75 2026-02-11)
binary: rustc
commit-hash: 01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf
commit-date: 2026-02-11
host: x86_64-unknown-linux-gnu
release: 1.93.1
LLVM version: 21.1.8
(Happens on any stable version >= 1.92.0; and also on nightly 2026-02-11)
I tried this code:
And rustc raises an "unreachable expression" warning. This seems reasonable. So I remove that line:
I expected to see this happen:
Instead, this happened: rustc seems to simultaneously indicate that path is unreachable, AND some expression is needed there to satisfy the type-checker.
Is there really no way to write the(Sorry, I shouldn't have asked. Didn't mean to nerd-snipe.)runfunction without invoking#[allow(unreachable_code)]? That seems odd.Meta
rustc --version --verbose:(Happens on any stable version >= 1.92.0; and also on nightly 2026-02-11)