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

Activity

  1. zackmdavis commented on Apr 28, 2018

    @zackmdavis
    Contributor

    This bad suggestion was fixed in most cases by #47922, but this case would seem to have evaded it. (Notice that on Nightly you can omit the ampersands from the match guards (due to the stabilization of the match-default-bindings ergonomic) and receive the correct suggestion!)

  2. added a commit that references this issue on Apr 30, 2018
    cbbdf99
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