Skip to content

Poor help error message for unused variable on struct enum match #50303

Closed
@dandc87

Description

@dandc87

Suppose I've written code like:

enum Foo {
    Bar { bar: u32 },
    Baz,
}

fn is_bar(foo: &Foo) -> bool {
    match foo {
        &Foo::Bar { bar } => true,
        &Foo::Baz => false,
    }
}

The bar variable is unused, and the error message I get looks like:

warning: unused variable: `bar`
  --> src/main.rs:37:21
   |
37 |         &Foo::Bar { bar } => true,
   |                     ^^^ help: consider using `_bar` instead
   |
   = note: #[warn(unused_variables)] on by default

The help is incorrect; _bar is invalid. It should suggest replacing bar with bar: _

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions