rust-lang / rust-lang/rust-clippy

if_same_then_else should ignore empty bodies

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

Nobody has claimed this yet.

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

Description

Summary

Example:

            if x.ident == y {
            } else if first && (*y == "core" || *y == "alloc") && x.ident == "std" {
            } else {
                return false;
            }

Yes, this is just a chained if expression. There are different ways to write it; as a single expression with/without brackets, via let bindings (though it's less clear if these take advantage of lazy evaluation), even via a match expression.

This is all about style (which, in my opinion, Clippy does not deserve a say in) and nothing about efficiency or redundancy.

Lint Name

if_same_then_else

Reproducer

No response

Version

No response

Additional Labels

No response

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 at the if_same_then_else lint implementation and its existing tests in rust-clippy. Trace how chained if branches are classified, then add coverage for branches with empty bodies. Done means the lint ignores empty branches in the reported pattern while preserving its existing behavior for non-empty branches.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.