rust-lang / rust-lang/rust-clippy
Factor `return`, `break` and `continue` from multiple branches
Open
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
When all branches in a if/else[/if/…] or match are divergent, and several of them end with the same construct (return, break or continue), some things may be factored out, for example the most commonly used:
returnorbreakmay be moved before theiformatchif they have a payload- in other cases, they may be moved after the
iformatch
Advantage
- Remove redundant keywords
Drawbacks
- May make the code harder to follow
Example
fn f(a: i32) -> i32 {
if a > 3 {
if a > 10 {
return a;
} else {
return a+1;
}
}
0
}
could be written as
fn f(a: i32) -> i32 {
if a > 3 {
return if a > 10 { a } else { a+1 };
}
0
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by examining the proposed Rust examples and existing Clippy handling for divergent if/match branches; done means eligible return, break, or continue constructs can be factored while preserving behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100