Skip to content

New lint: suggest using the only remaining variant instead of a wildcard #5556

Closed
@ebroto

Description

@ebroto

When matching an enum, if there is only one variant left, suggest using that instead of the wildcard pattern.

For example, for this enum:

enum E {
    First,
    Second,
    Third,
}

When matching it like this:

match e {
    E::First => {}
    E::Second => {}
    _ => {}
}

Suggest the following replacement:

match e {
    E::First => {}
    E::Second => {}
    E::Third => {}
}

The lint should be under the pedantic category.

Note that for #[non_exhaustive] enums the wildcard arm should be kept.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesT-ASTType: Requires working with the ASTgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions