rust-lang / rust-lang/rust-clippy
Suggest binding to a tuple if possible in the `useless_let_if_seq` lint
Open
Nobody has claimed this yet.
C-enhancement
L-suggestion
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I could be missing something here, but it seems like clippy (0.0.212 (e3cb40e 2019-06-25)) is giving a false positive for this code (useless_let_if_seq)?
fn main() {
let i = 1;
let mut arr0 = vec![0,0,0];
let mut more_arrs = vec![ vec![1,1,1], vec![2,2,2], vec![3,3,3] ];
let first;
let second;
if i == 0 {
first = &mut arr0;
second = &mut more_arrs[0];
} else {
let (start, end) = more_arrs.split_at_mut(i);
first = &mut start[start.len()-1];
second = &mut end[0];
}
println!("{:?}", first);
println!("{:?}", second);
}
Might be similar to #2176 and #2918?
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
Reproduce the example in the linked Rust Playground, then inspect the implementation and tests for the useless_let_if_seq lint. The change is done when this valid conditional borrowing pattern is no longer reported incorrectly and tuple binding is suggested where appropriate.
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
- 45/100