rust-lang / rust-lang/rust

Guaranteed early breaks out of try blocks can't infer never type

Open
#160,931 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-inference C-bug F-never_type F-try_blocks S-has-mcve T-compiler T-lang T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(try_blocks)]

fn bug_repro() {
    None = try {
        return; // The semicolon is important!
    };
}
#![feature(try_blocks)]

fn bug_repro() {
    None = try {
        None?;
        return;
    };
}

I expected to see this happen: The code compiles. This pattern is irrefutable

Instead, this happened: The pattern is marked as refutable and this code doesn't compile

Meta

rustc --version --verbose:

rustc 1.99.0-nightly (12c36e253 2026-08-10)
binary: rustc
commit-hash: 12c36e2539c54397c51d6ea4401defd8768a4f5b
commit-date: 2026-08-10
host: aarch64-apple-darwin
release: 1.99.0-nightly
LLVM version: 23.1.0

Zulip thread: #t-lang > Changing desugaring of try blocks

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 by compiling the two minimal try-block examples from the issue on the reported nightly and compare their pattern-refutability diagnostics. Then trace the compiler's try-block handling and never-type inference for guaranteed early exits; done means both examples compile with the pattern treated as irrefutable.

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
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.