Skip to content
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

new lint: using let mut a = a at start of function #5102

Closed
jyn514 opened this issue Jan 27, 2020 · 9 comments
Closed

new lint: using let mut a = a at start of function #5102

jyn514 opened this issue Jan 27, 2020 · 9 comments
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@jyn514
Copy link
Member

jyn514 commented Jan 27, 2020

I inherited a codebase from someone new to Rust and there were lots of function definitions that looked like this:

fn f(a: Vec<u8>) {
    let mut a = a;
    // rest of code
}

It would be nice if there were a lint saying this would be better as fn f(mut a: Vec<u8>) instead.

@flip1995 flip1995 added L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints labels Jan 27, 2020
@sonng
Copy link

sonng commented Jan 30, 2020

Looks like a good first issue. Could this be assigned to me please?

Thanks

@sonng
Copy link

sonng commented Feb 5, 2020

Hey guys,

I'm on the last leg of the work (cargo test) and making sure everything is fine. I noticed that while running that, our new lint gets triggered and causes an error, causing the whole thing to fail.

My question is, how do I turn this from an error to a warning?
or alternatively, I could update the problematic code and make them fn parameters mutable.

Cheers

@flip1995
Copy link
Member

flip1995 commented Feb 5, 2020

Can you open a WIP PR, so I can have a look at the code and the dogfood error?

@sonng
Copy link

sonng commented Feb 6, 2020

I'm happy for any feedback on the overall change too.

@brightly-salty
Copy link
Contributor

I'm willing to attempt to implement this and submit a PR if it would be accepted if @sonng isn't working on it. I expect to restart (to avoid merge conflicts) using their PR as a guide/inspiration?

@flip1995
Copy link
Member

flip1995 commented Jan 4, 2021

@brightly-salty Thanks! Yes you can use they're PR as inspiration. I think my comments on the PR should also help you with dos and don'ts.

@max-niederman
Copy link
Contributor

@rustbot claim

@rustbot rustbot assigned max-niederman and unassigned sonng Jun 3, 2023
@max-niederman
Copy link
Contributor

I think this should probably be generalized to redefined locals as well.

bors added a commit that referenced this issue Jul 22, 2023
new lint: `redundant_locals`

This lint checks for code like the following:

```rs
let x = 1;
let x = x;
```

It checks (afaik) all cases where a binding is shadowed by its own value in the same block, including function parameters. This has no effect and is almost certainly accidental, so it's in the `correctness` category like `self_assignment`.

This also lays the groundwork for a more generalized version of #5102.

changelog: new lint: [`redundant_local`]
@maxcnunes
Copy link

Is this issue still relevant? It seems #10885 covered what have been requested here and we could close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants