rust-lang / rust-lang/rust-clippy
Bad suggestion of `useless_let_if_seq` when having side effects.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
The version of clippy is 0.0.212.
Here's an example:
pub fn func() {
// This need to be called first always.
let mut ret = foo1();
if cond() {
// Overwrite with some complex expr.
ret = (foo2() * 2).to_string().len() as _;
}
baz(ret)
}
It suggest writing let <mut> ret = if cond() { .. foo2() .. } else { foo1() };, which cause 3 function calls (may have side-effects) being reordered, and foo1() not always being called.
Well, I'm not sure how to write make it more idiomatic in this case...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the useless_let_if_seq suggestion with the Rust example in the issue, using cargo clippy. Read the lint implementation and its existing tests to determine how side effects and evaluation order are handled; done means the example no longer receives an unsafe or misleading suggestion while valid cases still do.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100