rust-lang / rust-lang/rust-clippy

Suggest binding to a tuple if possible in the `useless_let_if_seq` lint

Open
#4,448 4 comments 0 reactions 0 assignees View on GitHub

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);
    
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=0cbbd72da8e9a800131ca458f1e76016

Might be similar to #2176 and #2918?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.