Skip to content

Incorrect "unreachable pattern" warning on nightly #79048

Closed
@alex

Description

@alex

I tried this code:

pub fn parse_data(data: &[u8]) -> u32 {
    match data {
        b"" => 1,
        _ => 2,
    }
}

fn main() {
    println!("{}", parse_data(b"asd"))
}

It produces the following, incorrect, warning:

warning: unreachable pattern
 --> src/main.rs:4:9
  |
4 |         _ => 2,
  |         ^
  |
  = note: `#[warn(unreachable_patterns)]` on by default

however, the output is 2 so it's clearly incorrect

Meta

rustc --version:

1.50.0-nightly (2020-11-13 74f7e32f43b5fb0f8389)

Metadata

Metadata

Assignees

Labels

A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions