rust-lang / rust-lang/rust-clippy
Option unwrap or outer loop continue can be pattern match
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
let a is Option<T>.
If both condition is met, the pattern can be written in pattern match:
a == Nonethencontinueouter loop- If not,
t = a.unwrap()then usingtlater
Lint Name
loop_option_unwrap_with_continue
Category
pedantic
Advantage
- Removing call to
Option<T>#unwrapwhich can be written in more idiomatic way
Drawbacks
No response
Example
for a in b {
let c: Option<T> = a;
if c.is_none() {
continue;
}
let e = c.unwrap();
// using e
}
Could be written as:
for a in b {
let c: Option<T> = a;
match c {
Some(e) => {
// using e
}
None => continue;
}
}
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 searching Clippy's existing lint implementations for loop and Option::unwrap patterns, along with their associated lint tests. Use the issue's examples to define the target pattern and verify that the new lint recognizes the Some/None control flow without flagging unrelated code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100