Skip to content

clippy:: map_entry incorrectly warned on code with a contains_key and no insert #14449

Closed
@erickt

Description

@erickt

Summary

Fuchsia just did a dry run roll of Rust rust-lang/rust@5d85a71, and it's incorrectly flagging the clippy::map_entry lint in at least two bits of our code that use contains_key, but do not have a corresponding insert:

error: usage of `contains_key` followed by `insert` on a `HashMap`
   --> ../../src/connectivity/network/netstack3/src/bindings/filter/conversion.rs:392:17
    |
392 | /                 if self.routine_types.contains_key(&name) {
393 | |                     self.expect_routine_resolved(&name, routine_type, rule_id)
394 | |                 } else {
395 | |                     self.convert_routine(
...   |
401 | |                 }
    | |_________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
    = note: `-D clippy::map-entry` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::map_entry)]`
error: usage of `contains_key` followed by `insert` on a `HashMap`
   --> ../../src/devices/lib/driver-static-checks/src/checks.rs:150:9
    |
150 | /         if json_category.contains_key(&device_category.subcategory) {
151 | |             Ok(StaticCheckPass {})
152 | |         } else {
153 | |             Err(StaticCheckFail  {
...   |
158 | |             })
159 | |         }
    | |_________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
    = note: `-D clippy::map-entry` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::map_entry)]`

Lint Name

clippy:: map_entry

Reproducer

So far I haven't been able to reproduce it outside our code, I'll update if I figure out one.

Version

This was built in our CI/CQ, so it's a little hard to get `rustc -Vv`, but it's with the nightly rustc version https://github.com/rust-lang/rust/commit/5d85a714b10a9121d2ec5115f39e904174f804e1.

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions