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

new lint for clone() on an Arc or Rc #13921

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lapla-cogito
Copy link
Contributor

close #13917

Starting with Rust 1.76.0, std::sync::Arc and std::rc::Rc support unwrap_or_clone. This allows for eliminating unnecessary clones more effectively than using clone directly, and linting for this can help improve efficiency.

changelog: [clone_on_arc_or_rc]: new lint

@rustbot
Copy link
Collaborator

rustbot commented Jan 1, 2025

r? @Manishearth

rustbot has assigned @Manishearth.
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 Jan 1, 2025
@lapla-cogito lapla-cogito force-pushed the arc_rc_unwrap_or_clone branch 2 times, most recently from 311d3ee to 1725601 Compare January 1, 2025 14:07
@lapla-cogito lapla-cogito force-pushed the arc_rc_unwrap_or_clone branch 2 times, most recently from 0986e73 to d8ded3f Compare January 1, 2025 15:15
@lapla-cogito lapla-cogito force-pushed the arc_rc_unwrap_or_clone branch 2 times, most recently from b8a5088 to 174e027 Compare January 1, 2025 15:56
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/clone_on_arc_or_rc.rs Outdated Show resolved Hide resolved
@lapla-cogito lapla-cogito force-pushed the arc_rc_unwrap_or_clone branch from 174e027 to fbd4e37 Compare January 1, 2025 16:04
@lapla-cogito lapla-cogito force-pushed the arc_rc_unwrap_or_clone branch from fbd4e37 to 8141c38 Compare January 1, 2025 16:09
@lapla-cogito lapla-cogito force-pushed the arc_rc_unwrap_or_clone branch from 9b80851 to 0aeca65 Compare January 1, 2025 16:45
@Manishearth
Copy link
Member

This lint should only fire if it is okay to move the arc.

(In which case it probably could be rolled into the existing unnecessary_clones lint)

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

(see previous comment)

don't want a perf lint that will have such a high false positive rate

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.

Suggest Arc::unwrap_or_clone() when appropriate
5 participants