Skip to content

Lint needless &mut when & suffices #1230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
phil-opp opened this issue Sep 16, 2016 · 3 comments
Open

Lint needless &mut when & suffices #1230

phil-opp opened this issue Sep 16, 2016 · 3 comments
Labels
A-lint Area: New lints T-middle Type: Probably requires verifiying types

Comments

@phil-opp
Copy link

Idea: Add a lint for unneeded mutable borrows when an immutable borrow suffices:

fn main() {
    let m = &mut 21; // `&21` would suffice
    println!("{}", m);
}

This lint could also catch an unneeded ref mut when a plain ref suffices:

fn main() {
    let test = &mut Test{a: 1};
    let &mut Test{ ref mut a } = test;

    println!("{}", a);
}

struct Test {
    a: i32,
}

cc @oli-obk

@mcarton mcarton added T-middle Type: Probably requires verifiying types A-lint Area: New lints labels Sep 16, 2016
@pickfire
Copy link
Contributor

Is this E-hard?

@oli-obk
Copy link
Contributor

oli-obk commented Oct 21, 2020

probably not, but it requires some gray matter wrangling. For this to be doable in a reasonable matter, we likely need to implement it on MIR and use dataflow to track mutable references.

@GnomedDev
Copy link
Contributor

Isn't this a duplicate of #353?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

5 participants