rust-lang / rust-lang/rust-clippy
map_entry does not consider `get()`
Open
Nobody has claimed this yet.
C-enhancement
E-medium
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I tried this code:
if let Some(&idx) = self.backtraces.get(&bt) {
idx
} else {
let pp_info_idx = self.pp_infos.len();
self.pp_infos.push(new());
let old = self.backtraces.insert(bt, pp_info_idx);
assert_eq!(old, None);
}
I expected to see this happen: Clippy suggests using backtraces.entry(bt).or_insert_with(|| { ... }) instead.
Instead, this happened: Clippy gave no warning.
Meta
cargo clippy -V: clippy 0.0.212 (0f6f2d6 2020-12-06)rustc -V: rustc 1.50.0-nightly (0f6f2d681 2020-12-06)
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 tracing the existing map_entry lint and its handling of get() and insert() in the Clippy source, then locate related regression tests. Done means the reported Rust pattern is recognized and the test suite covers the expected suggestion without breaking existing cases.
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