rust-lang / rust-lang/rust-clippy
False positive?: get_unwrap
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Link to example: http://play.integer32.com/?gist=2d02b966174279055a9519a5f3182a7d&version=undefined
warning: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise
--> src/main.rs:24:9
|
24 | data.data.get(&key).unwrap().clone()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `&data.data[&key]`
|
= note: #[warn(get_unwrap)] on by default
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#get_unwrap
Honestly seems like the suggested change should work but lifetimes seem to prevent it. Might be because Index and get take slightly different parameter types?
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 linked example and the get_unwrap lint warning at src/main.rs:24:9; compare the suggested indexing expression with the original get().unwrap() call under Rust's lifetime behavior. Done means establishing whether this is a false positive and documenting or correcting the lint's suggestion accordingly.
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
- 35/100