Result::<Infallible, ()>::unwrap() does not make the code after it unreachable
Open
Nobody has claimed this yet.
C-enhancement
F-never_type
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
use std::convert::Infallible;
fn main() {
foo();
}
fn foo() -> bool {
bar().unwrap();
}
fn bar() -> Result<Infallible, ()> {
Err(())
}
I expected to see this happen: The code compile.
Instead, this happened:
error[E0308]: mismatched types
--> src/main.rs:7:13
|
7 | fn foo() -> bool {
| --- ^^^^ expected `bool`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
Meta
rustc --version --verbose:
rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: x86_64-unknown-linux-gnu
release: 1.95.0
LLVM version: 22.1.2
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.
Research direction
Start with the minimal reproduction in src/main.rs and compile it with the reported rustc version, then compare how Result<Infallible, ()>::unwrap() is typed with the compiler's unreachable-code and never-type behavior. Done means the intended return type is accepted, or the issue is clarified with a confirmed language or compiler rationale and a regression test location identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100