rust-lang / rust-lang/rust

Result::<Infallible, ()>::unwrap() does not make the code after it unreachable

Open
#156,657 4 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.