rust-lang / rust-lang/rust-clippy

useless_let_if_seq should not emit a warning if multiple assignments happen

Open
#2,749 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

I have code that looks like this:

let img_x: u32;
let img_y: u32;
let pattern_x: u32;
let pattern_y: u32;

if forward {
    img_x = start_x + scan_x;
    img_y = start_y + scan_y;
    pattern_x = scan_x;
    pattern_y = scan_y;
} else {
    img_x = start_x - scan_x;
    img_y = start_y - scan_y;
    pattern_x = scan_width - scan_x - 1;
    pattern_y = scan_height - scan_y - 1;
}

Am I right in thinking that this should be ok with clippy or is there actually a more idiomatic way of doing something like this?

If people agree with me, I'll fix the bug.

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

Start by locating the useless_let_if_seq lint and reproduce the issue with the Rust snippet in this report. Confirm the expected behavior for multiple assignments in both branches, then add or update coverage so the lint no longer warns for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
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.