-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-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.F-never_type`#![feature(never_type)]``#![feature(never_type)]`L-false-negativeLint: False negative (should have fired but didn't).Lint: False negative (should have fired but didn't).L-unreachable_codeLint: unreachable_codeLint: unreachable_codeT-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.
Description
I tried this code:
fn main() {
(|| panic!())();
();
}
I expected to see this happen: ();
is marked as unreachable code
Instead, this happened: there is no warning.
This happens because we emit unreachable code lint in rustc_hir_typeck
, while checking expressions (we track it via FnCtxt::diverges
), which means that we can have unresolved inference variables.
In this case, when checking code reachibility we see that the type of (|| panic!())()
is a (diverging) inference variable and not !
so we don't set FnCtxt::diverges
to "always". Later this inference variable is set to !
(NB: currently only on edition = 2024), but at this point we don't check for unreachable code.
Meta
rustc --version --verbose
:
1.91.0-nightly (2025-08-31 07d246fc6dc227903da2)
Metadata
Metadata
Assignees
Labels
A-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.F-never_type`#![feature(never_type)]``#![feature(never_type)]`L-false-negativeLint: False negative (should have fired but didn't).Lint: False negative (should have fired but didn't).L-unreachable_codeLint: unreachable_codeLint: unreachable_codeT-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.