-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.L-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).L-unreachable_codeLint: unreachable_codeLint: unreachable_codeP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
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 (Sorry, I shouldn't have asked. Didn't mean to nerd-snipe.)run function without invoking #[allow(unreachable_code)]? That seems odd.
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.L-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).L-unreachable_codeLint: unreachable_codeLint: unreachable_codeP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Fields
Give feedbackNo fields configured for issues without a type.