rust-lang / rust-lang/rust-clippy

if_same_then_else does not detect same `if let` expression

Open
#6,702 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement E-hard I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Lint name: if_same_then_else

I tried this code: https://github.com/deltachat/deltachat-core-rust/blob/master/src/message.rs#L1081-L1091

                        if chat.id.is_deaddrop() {
                            if let Some(contact) = contact {
                                self.text1 = Some(msg.get_sender_name(contact));
                            } else {
                                self.text1 = None;
                            }
                        } else if let Some(contact) = contact {
                            self.text1 = Some(msg.get_sender_name(contact));
                        } else {
                            self.text1 = None;
                        }

I expected to see this happen: detect that chat.id.is_deaddrop() condition could be removed.

Instead, this happened: clippy did not detect anything.

Meta
  • cargo clippy -V: clippy 0.0.212 (e1884a8 2020-12-29)
  • rustc -Vv:
    rustc 1.49.0 (e1884a8e3 2020-12-29)
    binary: rustc
    commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
    commit-date: 2020-12-29
    host: x86_64-unknown-linux-gnu
    release: 1.49.0
    

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 with the linked src/message.rs example around lines 1081-1091 and reproduce the behavior using cargo clippy. Trace the if_same_then_else lint entry point and its existing coverage, then add detection for this repeated if let expression and verify that Clippy reports the removable condition.

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
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.