Skip to content

unused_mut warning gives bad suggestion in a macro #60643

Description

@ehuss

The following gives a suggestion to remove the mut which will cause the code to fail to compile.

macro_rules! array {
    ($($element:expr),*) => {{
        let mut array = Vec::new();
        $(
            array.push($element);
        )*
        array
    }};
}

fn main() {
    let _x: Vec<i32> = array![];
    let _y: Vec<i32> = array![1,2,3];
}
warning: variable does not need to be mutable
  --> src/main.rs:3:13
   |
3  |         let mut array = Vec::new();
   |             ----^^^^^
   |             |
   |             help: remove this `mut`
...
12 |     let _x: Vec<i32> = array!{};
   |                        -------- in this macro invocation
   |
   = note: #[warn(unused_mut)] on by default

This causes cargo fix to fail.

(Sorry if this is a dupe, I went hunting but couldn't find any issues that were the same.)

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-NLLArea: Non-lexical lifetimes (NLL)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions