Skip to content

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

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: _

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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