rust-lang / rust-lang/rust

Missing unreachable code/arm warning, when a match guard is diverging

Open
#134,734 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints C-bug L-unreachable_code T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

fn main() {
    match () {
        _ if loop {} => (),
        _ => (),
    }
    println!("nya :3");
}

(playground)

I expected to see this happen: compiler to emit a warning that the first arm and later code is unreachable (since loop{} never terminates and has type !).

Instead, this happened: the code compiles without warnings.

Meta

rustc version: 1.84.0-beta.4 (2024-12-07 202008a1b8de96d2e5b6)

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

Reproduce the issue with the provided Rust match-guard example on the cited beta toolchain, then investigate unreachable-code analysis for diverging guards. Done means the compiler warns that the first match arm and the later println! are unreachable, with coverage for this example.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.