Skip to content
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

Merged
merged 2 commits into from
Sep 4, 2019

Conversation

JohnTitor
Copy link
Member

Fixes #4219

changelog: Fix map_entry false positive

@JohnTitor JohnTitor added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 4, 2019
@phansch phansch self-requested a review September 4, 2019 15:01
n.insert(k, v);
}
}

Copy link
Member

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);
    }
}

Copy link
Member Author

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, &params[0]);
if SpanlessEq::new(self.cx).eq_expr(self.key, &params[1]);
if snippet_opt(self.cx, self.map.span) == snippet_opt(self.cx, params[0].span);
Copy link
Member

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 👍

@phansch
Copy link
Member

phansch commented Sep 4, 2019

r=me with the test added :)

@phansch
Copy link
Member

phansch commented Sep 4, 2019

@bors r+ thanks!

@bors
Copy link
Collaborator

bors commented Sep 4, 2019

📌 Commit 5c760f0 has been approved by phansch

@bors
Copy link
Collaborator

bors commented Sep 4, 2019

⌛ Testing commit 5c760f0 with merge e3ae76a...

bors added a commit that referenced this pull request Sep 4, 2019
Fix `map_entry` false positive

Fixes #4219

changelog: Fix `map_entry` false positive
@bors
Copy link
Collaborator

bors commented Sep 4, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: phansch
Pushing e3ae76a to master...

@bors bors merged commit 5c760f0 into rust-lang:master Sep 4, 2019
@JohnTitor JohnTitor deleted the fix-map-entry-false-positive branch September 4, 2019 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

false positive for map_entry when two different maps used
3 participants