Skip to content

Matching field-less enum variants that aren't imported should deny-lint, not just give lots of warnings #103442

Closed
@igor37

Description

@igor37

When the enum variants listed in a match block omit the preceding EnumName:: the compiler may still accept the code, even if some cases were not handled or nonexistent variants are listed.

I tried this code:

enum Enum {
    A,
    B,
    C,
}

fn main() {
    let b = Enum::B;

    match b {
        A => println!("A"),
        B => println!("B"),
        Foo => {},
    }
}

I expected to see this happen: Compiler errors regarding missing Enum::, missing variant Enum::C, and invalid variant.

Instead, this happened: the code compiled and printed "A"

Meta

rustc --version --verbose:

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: aarch64-apple-darwin
release: 1.64.0
LLVM version: 14.0.6

Also tested with rustc 1.66.0-nightly (f83e0266c 2022-10-03)

Metadata

Metadata

Assignees

Labels

D-confusingDiagnostics: Confusing error or lint that should be reworked.E-help-wantedCall for participation: Help is requested to fix this issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions