Skip to content

Unnecessary &mut should be warned #53759

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

Closed
upsuper opened this issue Aug 28, 2018 · 3 comments
Closed

Unnecessary &mut should be warned #53759

upsuper opened this issue Aug 28, 2018 · 3 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@upsuper
Copy link
Contributor

upsuper commented Aug 28, 2018

Given the following code:

fn foo(_: &mut usize) {}
let mut a = 0;
let mut b = &mut a;
foo(&mut b);

there is no warning saying that the &mut in the last line is unnecessary.

Some novice don't always have clear idea about where should have &mut so they may add lots of unnecessary ones which leads to more unnecessary mut variables.

It might be helpful if we can warn on this case so that they know this isn't necessary.

@ExpHP
Copy link
Contributor

ExpHP commented Aug 28, 2018

I'm pretty sure this would generate hundreds of warnings all over my codebase. I've always regarded this as a feature of deref coercions that makes refactoring functions less painful.

Linting against this feels much like linting against match ergonomics... which I acknowledge is something that some people want, but I don't think the standard compiler ought to do it.

@ivanbakel
Copy link
Contributor

ivanbakel commented Aug 28, 2018

This behaviour also happens in the simpler case

fn foo (_: &i32) {}
let mut a = 0;
foo (&mut a);

Which looks a lot worthier of a lint.

@frewsxcv frewsxcv added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Aug 29, 2018
@sanxiyn
Copy link
Member

sanxiyn commented Mar 17, 2019

This is rust-lang/rust-clippy#1230. I agree with @ExpHP that this belongs in clippy and not rustc.

@sanxiyn sanxiyn closed this as completed Mar 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

5 participants