Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unreachable_patterns emitted on _ that matches a local of uninhabited type (that is uninitialized) #134733

Open
WaffleLapkin opened this issue Dec 24, 2024 · 1 comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unreachable_patterns Lint: unreachable_patterns T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

I tried this code:

enum Void {}

fn main() {
    let void: Void;
    match void {
        _ => (),
    }
}

(playground)

I expected to see this happen: the code compiler without warnings and successfully runs doing nothing.

Instead, this happened: a warning is emitted (the code compiles and runs as expected):

warning: unreachable pattern
 --> src/main.rs:6:9
  |
6 |         _ => (),
  |         ^-------
  |         |
  |         matches no values because `Void` is uninhabited
  |         help: remove the match arm
  |
  = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types
  = note: `#[warn(unreachable_patterns)]` on by default

Meta

rustc version: 1.85.0-nightly (2024-12-23 bdc6b3de48646345549f)

@WaffleLapkin WaffleLapkin added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unreachable_patterns Lint: unreachable_patterns labels Dec 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 24, 2024
@compiler-errors
Copy link
Member

This is annoying to fix, b/c while the unreachable patterns lint is in mir-build, we don't actually do the analysis to determine that the variable is uninitialized until borrowck. I'm not totally certain if it's easy or possible to probe whether a variable is initialized in THIR or HIR so that this lint can be suppressed for uninitialized uninhabited variables.

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unreachable_patterns Lint: unreachable_patterns T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants