Skip to content

[map_entry]: Check insert expression for map use #12362

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

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

Ethiraric
Copy link
Contributor

@Ethiraric Ethiraric commented Feb 27, 2024

The lint makes sure that the map is not used (borrowed) before the call to insert. Since the lint creates a mutable borrow on the map with the Entry, it wouldn't be possible to replace such code with Entry. However, expressions up to the insert call are checked, but not expressions for the arguments of the insert call itself. This commit fixes that.

Fixes #11935


changelog: [map_entry]: Fix false positive when borrowing the map in the insert call

@rustbot
Copy link
Collaborator

rustbot commented Feb 27, 2024

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 27, 2024
Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Adding new docs is very appreciated! :)

/// Details on an expression checking whether a map contains a key.
///
/// For instance, with the following:
/// ```no_run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to mark it as ignore, otherwise the doctest will fail.

///
/// For instance, on the following:
/// ```no_run
/// self.the_map.insert("the_key", 3 + 4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@llogiq
Copy link
Contributor

llogiq commented Feb 27, 2024

Thank you!

@bors r+

@bors
Copy link
Contributor

bors commented Feb 27, 2024

📌 Commit 6f25290 has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 27, 2024

⌛ Testing commit 6f25290 with merge 9ec7b06...

bors added a commit that referenced this pull request Feb 27, 2024
[`map_entry`]: Check insert expression for map use

The lint makes sure that the map is not used (borrowed) before the call to `insert`. Since the lint creates a mutable borrow on the map with the `Entry`, it wouldn't be possible to replace such code with `Entry`. However, expressions up to the `insert` call are checked, but not expressions for the arguments of the `insert` call itself. This commit fixes that.

Fixes #11935

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`map_entry`]: Fix false positive when borrowing the map in the `insert` call
@bors
Copy link
Contributor

bors commented Feb 27, 2024

💔 Test failed - checks-action_test

@Ethiraric
Copy link
Contributor Author

@bors retry
Please 🥺

@bors
Copy link
Contributor

bors commented Feb 27, 2024

@Ethiraric: 🔑 Insufficient privileges: not in try users

@llogiq
Copy link
Contributor

llogiq commented Feb 27, 2024

@bors retry

@bors
Copy link
Contributor

bors commented Feb 27, 2024

⌛ Testing commit 6f25290 with merge 7115162...

bors added a commit that referenced this pull request Feb 27, 2024
[`map_entry`]: Check insert expression for map use

The lint makes sure that the map is not used (borrowed) before the call to `insert`. Since the lint creates a mutable borrow on the map with the `Entry`, it wouldn't be possible to replace such code with `Entry`. However, expressions up to the `insert` call are checked, but not expressions for the arguments of the `insert` call itself. This commit fixes that.

Fixes #11935

----

changelog: [`map_entry`]: Fix false positive when borrowing the map in the `insert` call
@bors
Copy link
Contributor

bors commented Feb 27, 2024

💔 Test failed - checks-action_test

@Ethiraric
Copy link
Contributor Author

The errors do not happen near the code I have changed. I have no MacOS computer to test that locally.

If this is linked to the code I wrote, do you have any hint for me regarding a way of debugging this?

@y21
Copy link
Member

y21 commented Feb 27, 2024

Random SIGABRT in an unrelated test on a macOS runner, definitely looks spurious
@bors retry

@bors
Copy link
Contributor

bors commented Feb 27, 2024

⌛ Testing commit 6f25290 with merge 2c379d2...

bors added a commit that referenced this pull request Feb 27, 2024
[`map_entry`]: Check insert expression for map use

The lint makes sure that the map is not used (borrowed) before the call to `insert`. Since the lint creates a mutable borrow on the map with the `Entry`, it wouldn't be possible to replace such code with `Entry`. However, expressions up to the `insert` call are checked, but not expressions for the arguments of the `insert` call itself. This commit fixes that.

Fixes #11935

----

changelog: [`map_entry`]: Fix false positive when borrowing the map in the `insert` call
@bors
Copy link
Contributor

bors commented Feb 27, 2024

💔 Test failed - checks-action_test

@y21
Copy link
Member

y21 commented Feb 27, 2024

This failure looks less 'spurious' (as in, I can at least repro it locally after cargo update -p ui_test to match CI's version) but also really shouldn't have anything to do with this PR. 🤔

I wonder if this has something to do with the new version of uitest published 40 minutes ago that might've broken clippy? cc @oli-obk ?

@y21
Copy link
Member

y21 commented Feb 27, 2024

Ah, I just saw #12363, which looks like it fixed these failing tests. Probably just needs a rebase then

The lint makes sure that the map is not used (borrowed) before the call
to `insert`. Since the lint creates a mutable borrow on the map with the
`Entry`, it wouldn't be possible to replace such code with `Entry`.
However, expressions up to the `insert` call are checked, but not
expressions for the arguments of the `insert` call itself. This commit
fixes that.

Fixes rust-lang#11935
@Ethiraric
Copy link
Contributor Author

Hurray! 🎉 Thanks for digging into this @y21!

@matthiaskrgr
Copy link
Member

@bors retry

@matthiaskrgr
Copy link
Member

ah oops
@bors r=llogiq

@bors
Copy link
Contributor

bors commented Feb 27, 2024

📌 Commit 03bb790 has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 27, 2024

⌛ Testing commit 03bb790 with merge 4c1d05c...

@bors
Copy link
Contributor

bors commented Feb 27, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 4c1d05c to master...

@bors bors merged commit 4c1d05c into rust-lang:master Feb 27, 2024
@Ethiraric Ethiraric deleted the fix-11935 branch February 28, 2024 14:27
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.

clippy's automatic fix for map_entry fails to compile, with a borrow error
7 participants