-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix map_entry
false positive
#4495
Conversation
n.insert(k, v); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add the following test as described in the issue (where one is mut and the other is not):
fn insert_other<K: Eq + Hash, V>(m: HashMap<K, V>, n: &mut HashMap<K, V>, k: K, v: V) {
if !m.contains_key(&k) {
n.insert(k, v);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the test (and renamed)
@@ -140,6 +140,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { | |||
if path.ident.name == sym!(insert); | |||
if get_item_name(self.cx, self.map) == get_item_name(self.cx, ¶ms[0]); | |||
if SpanlessEq::new(self.cx).eq_expr(self.key, ¶ms[1]); | |||
if snippet_opt(self.cx, self.map.span) == snippet_opt(self.cx, params[0].span); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, in general I don't think comparing the span's text is very robust, but I think in this case it should be fine 👍
r=me with the test added :) |
@bors r+ thanks! |
📌 Commit 5c760f0 has been approved by |
Fix `map_entry` false positive Fixes #4219 changelog: Fix `map_entry` false positive
☀️ Test successful - checks-travis, status-appveyor |
Fixes #4219
changelog: Fix
map_entry
false positive