rust-lang / rust-lang/rust-clippy
FN unnecessary_unwrap does not traverse struct fields
Open
Nobody has claimed this yet.
C-bug
I-false-negative
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Lint name : unnecessary_unwrap
I tried this code:
pub struct S {
inner: Option<i32>,
}
impl S {
pub fn fun(&self) -> i32 {
if self.inner.is_some() {
return self.inner.unwrap();
}
4
}
}
I expect this to trigger clippy::unnecessary_unwrap and suggest something like
if let Some(val) = self.inner {
return val;
}
4
but the lint did not trigger 😦
Meta
clippy 0.0.212 (fde6927 2021-01-02)
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 with the unnecessary_unwrap lint and reproduce the Rust example from the issue, checking why access through the struct field is not traversed. Done means the lint recognizes this pattern and suggests the shown if let Some form without regressing existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100