rust-lang / rust-lang/rust-clippy

map_entry does not consider `get()`

Open
#6,440 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.