rust-lang / rust-lang/rust-clippy

Redundant if test lint

Open
#8,923 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What it does

Here the first if test contains a return so the second if can't be true. This is usually a coding mistake that could hide a bug, so I think a lint that spots such situations is good. This lint could be complex (like firing even if the first test contains "< 3") but even basic cases like this with repeated conditions should be useful.

Lint Name

impossibile_if_branch

Category

suspicious

Advantage

No response

Drawbacks

No response

Example
fn test2(s: &[u32]) -> bool {
    if s.len() < 2 {
        return true;
    }
    
    if s.len() < 2 {
        println!("*");
    }
    false
}

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

No implementation files or tests are named in the issue. Start by locating Clippy's existing suspicious lints and their test conventions, then use the Rust example as the initial acceptance case: repeated conditions after a returning branch should be reported without incorrectly flagging valid control flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.