Skip to content

Incorrect "unreachable pattern" warning #79498

Closed
@psychon

Description

@psychon

Hi,

the following program builds without warnings on stable and nightly, but prints an (IMHO incorrect) warning on beta:

fn foo() -> (Result<u8, ()>, &'static [u8]) {
    (Err(()), b"1")
}

fn main() {
    match foo() {
        (Ok(_), _) => panic!("1"),
        (Err(_), b"") => panic!("2"),
        (Err(_), _) => panic!("3"),
    }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
warning: unreachable pattern
 --> src/main.rs:9:9
  |
9 |         (Err(_), _) => panic!("3"),
  |         ^^^^^^^^^^^
  |
  = note: `#[warn(unreachable_patterns)]` on by default

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 1.46s
     Running `target/debug/playground`
thread 'main' panicked at '3', src/main.rs:9:24
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The panic shows that the supposedly unreachable pattern was, well, reached.

Originally discovered in psychon/x11rb#561 and surprisingly my attempt at reducing the example succeeded on the first try.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-releaseRelevant to the release subteam, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions