Skip to content

New Lint: detect unused &mut references in function parameters #5546

Description

@leonardo-m

Hi! Clippy in the Rust Playground spots this problem:

fn foo(x: &u32) {
    let _y = x;
}
fn main() {
    foo(&mut 10);
}


warning: The function/method `foo` doesn't need a mutable reference
note: `#[warn(clippy::unnecessary_mut_passed)]` on by default

But it doesn't find the inverted problem here:

fn foo(x: &mut u32) { // This doesn't need to take a mut
    let _y = x;
}
fn main() {
    foo(&mut 10);
}

While this is caught by Rustc too:

fn foo(mut x: u32) {
    let _y = x;
}
fn main() {
    foo(10);
}

warning: variable does not need to be mutable

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-lintArea: New lintsE-hardCall for participation: This a hard problem and requires more experience or effort to work onL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions