-
Notifications
You must be signed in to change notification settings - Fork 1.7k
map_entry, suggestion produces invalid borrow inside closure #11976
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
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Comments
I faced the same Issue. Here is the relevant PR: https://github.com/8xFF/atm0s-media-server/pull/349/files#diff-33ab08f3a3309009785786b7440abbb7e1f2a4ae26dc63c54f2d10acf16a2f56R68 |
More context from the above PR:
|
@rustbot claim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
The
map_entry
lint is suppressed if the hash map is accessed between the call toHashMap::contains_key
and the later call toHashMap::insert
. However, it does not check for access of the hash map occurring within a closure. As a result, the suggestion's use ofHashMap::entry
starts a mutable borrow of the entire hashmap, conflicting with call toHashMap::get
that occurred between thecontains_key
andinsert
.In the example below, if the line
let _ = || hashmap.get(&0);
is replaced withhashmap.get(&0);
, the lint is no longer suggested.Lint Name
map_entry
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen: No clippy suggestions produced.
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: