rust-lang / rust-lang/rust-clippy
`while_let_loop` should not be reported for empty match statements
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Description
In case the loop only contains a single match statement, with either an empty block or a break, while_let_loop should IMO not be reported, since the code communicates a slightly different intention.
A loop with a single, empty match communicates, that driving the iterator/stream/generator/... to completion is the main focus, while a while loop communicates, that the iterator/stream/generator/... is just a source of data and not the main focus.
loop {
match state.process_next() {
ControlFlow::Continue(_) => {},
ControlFlow::Break(_) => break,
}
}
while let ControlFlow::Continue(_) = state.process_next() {}
Small example: playground
Version
rustc 1.67.0-nightly (a00f8ba7f 2022-11-15)
binary: rustc
commit-hash: a00f8ba7fcac1b27341679c51bf5a3271fa82df3
commit-date: 2022-11-15
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
(also on stable)
Additional Labels
No response
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
Start by locating the while_let_loop lint and reproducing the provided Rust playground example. The work is done when loops containing a single empty match or a match ending in break are not reported, while the existing lint behavior remains covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100