unreachable code is not detected if it depends on never type fallback
@jdonszelmann is already working on this.
Since May 6, 2026.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.