Skip to content

Failure to correctly apply fixes for clippy::map_entry #15307

@hkBst

Description

@hkBst

Description

Failure to correctly apply fixes for this lint:

warning: usage of `contains_key` followed by `insert` on a `HashMap`
   --> src/tools/unicode-table-generator/src/raw_emitter.rs:343:13
    |
343 | /             if !unique_mapping.contains_key(&w) {
344 | |                 assert!(
345 | |                     unique_mapping
346 | |                         .insert(w, UniqueMapping::Canonical(canonical_words.len()))
...   |
349 | |                 canonical_words.push(w);
350 | |             }
    | |_____________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
    = note: `#[warn(clippy::map_entry)]` on by default
help: try
    |
343 ~             if let std::collections::hash_map::Entry::Vacant(e) = unique_mapping.entry(w) {
344 +                 assert!(
345 +                     { e.insert(UniqueMapping::Canonical(canonical_words.len())); None }
346 +                         .is_none()
347 +                 );
348 +                 canonical_words.push(w);
349 +             }

Original code:

        for &w in unique_words {
            if !unique_mapping.contains_key(&w) {
                assert!(
                    unique_mapping
                        .insert(w, UniqueMapping::Canonical(canonical_words.len()))
                        .is_none()
                );
                canonical_words.push(w);
            }
        }

Invocation and output after failure:

~/rust/src/tools/unicode-table-generator$ cargo clippy --fix --bin "unicode-table-generator"
    Checking unicode-table-generator v0.1.0 (/home/gh-hkBst/rust/src/tools/unicode-table-generator)
warning: failed to automatically apply fixes suggested by rustc to crate `unicode_table_generator`

after fixes were automatically applied the compiler reported errors within these files:

  * src/tools/unicode-table-generator/src/raw_emitter.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0282]: type annotations needed
   --> src/tools/unicode-table-generator/src/raw_emitter.rs:345:82
    |
345 |                     { e.insert(UniqueMapping::Canonical(canonical_words.len())); None }
    |                                                                                  ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
    |
help: consider specifying the generic argument
    |
345 |                     { e.insert(UniqueMapping::Canonical(canonical_words.len())); None::<T> }
    |                                                                                      +++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0282`.
Original diagnostics will follow.

Version

rustc 1.90.0-nightly (e46629662 2025-07-17)
binary: rustc
commit-hash: e4662966273ed58b51f9ff8d682accc202aa1210
commit-date: 2025-07-17
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions