Skip to content

Lint for missing pair in match on pairs of enum #971

Open
@mcarton

Description

@mcarton

This match:

match (&left.node, &right.node) {
    (&PatKind::Box(..), &PatKind::Box(..)) => …,
    (&PatKind::TupleStruct(..), &PatKind::TupleStruct(..)) => …,
    (&PatKind::Ident(..), &PatKind::Ident(..)) => …,
    (&PatKind::Lit(..), &PatKind::Lit(ref r)) => …,
    (&PatKind::QPath(..), &PatKind::QPath(..)) => …
    (&PatKind::Tuple(..), &PatKind::Tuple(..)) => …
    (&PatKind::Range(..), &PatKind::Range(..)) => …,
    (&PatKind::Ref(..), &PatKind::Ref(..)) => …,
    (&PatKind::Vec(..), &PatKind::Vec(..)) => …,
    (&PatKind::Wild, &PatKind::Wild) => …,
    _ => …,
}

looks like is missing some pair (&Path(..), &Path(..)) that was not added in a previous rustup. Of course in such case it would not be reasonable to list the n×(n-1) missing cases and we used _, but that means Rust won’t tell us about that missing pair 😢.

What do you think of a lint that would warn on such matches that users would explicitly mark?

#[deny(missing_tuple)] // ¹
match (&left.node, &right.node) {
    (&PatKind::Box(..), &PatKind::Box(..)) => …,
    [… same as above],
    (&PatKind::Wild, &PatKind::Wild) => …,
    _ => …, // error: the tuple `(Path, Path)` is missing
}

1: alternatively we could use a #[clippy_missing_tuple] attribute on the match if #[allow/deny/warn] do not work on expressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsC-questionCategory: QuestionsE-hardCall for participation: This a hard problem and requires more experience or effort to work onL-correctnessLint: Belongs in the correctness lint groupT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions