Skip to content

missing-match-arm's fix duplicates existing variant when matching on a reference #22223

@ada4a

Description

@ada4a

rust-analyzer version: rust-analyzer 1.95.0 (5980761 2026-04-14)

rustc version: rustc 1.95.0 (59807616e 2026-04-14)

editor or extension: VSCode, extension version 0.3.2878

relevant settings: none

repository link (if public, optional): none

code snippet to reproduce:

enum Enum {
    Old {},
    New,
}

fn foo(e: &Enum) {
    match e {
        &Enum::Old {} => {}
    };
}

This should be suggesting:

match e {
    &Enum::Old {} => {}
    Enum::New => todo!(),
};

but it suggests:

match e {
    &Enum::Old {} => {}
    Enum::Old { } => todo!(),
    Enum::New => todo!(),
};

whose second arm (Enum::Old { }) is unreachable.

The same happens if Enum::Old is a tuple variant, and if it has fields -- this is just a minimization.

@rustbot claim

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions