-
Notifications
You must be signed in to change notification settings - Fork 1.6k
clippy:: map_entry
incorrectly warned on code with a contains_key
and no insert
#14449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We're rolling out `clippy::map_entry` across the tree and adding `#[allow(clippy::map_entry)]` attributes on all current code that triggers the lint, due to a known bug in the latest Rust compiler (see [here](rust-lang/rust-clippy#14449) for more info). Bug: 407087100 Bug: 407086469 Bug: 407087136 Change-Id: I4962a540e80b1916b2e4e8f4c67bd928165988cb Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1239684 Reviewed-by: Peter Johnston <peterjohnston@google.com> Reviewed-by: Sarah Chan <spqchan@google.com> Commit-Queue: Steven Grady <slgrady@google.com>
We're rolling out `clippy::map_entry` across the tree and adding `#[allow(clippy::map_entry)]` attributes on all current code that triggers the lint, due to a known bug in the latest Rust compiler (see [here](rust-lang/rust-clippy#14449) for more info). Original-Bug: 407087100 Original-Bug: 407086469 Original-Bug: 407087136 Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1239684 Original-Revision: 2652deb44c3069064381427157357dd37419d03e GitOrigin-RevId: 31f9512e215661d3989b6de9d66a7f22252e9753 Change-Id: I081ddf17aab4a046c8fc8cd4e24c80566f82034a
We are running into the same issue:
Versionclippy 0.1.87 (45165c82a4 2025-04-01) (current beta) |
Minimal example (playground): use std::collections::BTreeMap;
pub struct Meow {
map: BTreeMap<String, String>,
}
impl Meow {
fn pet(&self, _key: &str, _v: u32) -> u32 {
42
}
}
pub fn f(meow: &Meow, x: String) {
if meow.map.contains_key(&x) {
let _ = meow.pet(&x, 1);
} else {
let _ = meow.pet(&x, 0);
}
} |
searched nightlies: from nightly-2025-03-17 to nightly-2025-04-08 bisected with cargo-bisect-rustc v0.6.9Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --component clippy -- clippy |
This is a regression in the lint [0] and it should be fixed again in the next version. See [1] for more details. [0]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry [1]: rust-lang/rust-clippy#14449 Signed-off-by: Michael Weiss <michael.weiss@eviden.com>
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 usecontains_key
, but do not have a correspondinginsert
: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
Additional Labels
No response
The text was updated successfully, but these errors were encountered: