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

Extend map_clone lint to also work on non-explicit closures #12104

Merged
merged 3 commits into from Jan 6, 2024

Conversation

GuillaumeGomez
Copy link
Member

I found it weird that this case was not handled by the current line so I added it. The only thing is that I don't see an obvious way to infer the current type to determine if it's copyable or not, so for now I always suggest cloned and I added a FIXME.

r? @llogiq

changelog: Extend map_clone lint to also work on non-explicit closures

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 6, 2024
@llogiq
Copy link
Contributor

llogiq commented Jan 6, 2024

Would it then make sense to also change the message because Clone::clone is not a closure.

Perhaps something like "manually implementing .cloned()".

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Jan 6, 2024

Sounds good to me! Just realized that I also left some code I was working on for another update... I also need to fix dogfood which found issues thanks to this update.

@GuillaumeGomez
Copy link
Member Author

Fixed the CI failures. :)

Comment on lines +74 to +75
// FIXME: It would be better to infer the type to check if it's copyable or not
// to suggest to use `.copied()` instead of `.cloned()` where applicable.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would getting the iterator type from the map(_) and then extracting the Item type work here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Worth a try.

@llogiq
Copy link
Contributor

llogiq commented Jan 6, 2024

Looks good to me. Any further extensions can be a follow up PR.

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 6, 2024

📌 Commit af35d37 has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jan 6, 2024

⌛ Testing commit af35d37 with merge 17b2418...

@bors
Copy link
Collaborator

bors commented Jan 6, 2024

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

@bors bors merged commit 17b2418 into rust-lang:master Jan 6, 2024
5 checks passed
@GuillaumeGomez GuillaumeGomez deleted the map-clone branch January 6, 2024 17:01
bors added a commit that referenced this pull request Jan 7, 2024
Handle "calls" inside the closure as well in `map_clone` lint

Follow-up of #12104.

I just realized that I didn't handle the case where the `clone` method was made as a call and not a method call.

r? `@llogiq`

changelog: Handle "calls" inside the closure as well in `map_clone` lint
bors added a commit that referenced this pull request Jan 11, 2024
Fix suggestion for `map_clone` lint on types implementing `Copy`

Follow-up of #12104.

It was missing this check to suggest the correct method.

r? `@llogiq`

changelog: Fix suggestion for `map_clone` lint on types implementing `Copy`
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.

None yet

4 participants