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

less aggressive needless_borrows_for_generic_args #12706

Merged
merged 1 commit into from May 15, 2024

Conversation

pacak
Copy link
Contributor

@pacak pacak commented Apr 23, 2024

Current implementation looks for significant drops, that can change the behavior, but that's not enough - value might not have a Drop itself but one of its children might have it.

A good example is passing a reference to PathBuf to std::fs::File::open. There's no benefits to pass PathBuf by value, but since clippy can't see Drop on Vec several layers down it complains forcing pass by value and making it impossible to use the same name later.

New implementation only looks at copy values or values created in place so existing variable will never be moved but things that take a string reference created and value is created inplace &"".to_owned() will make it to suggest to use "".to_owned() still.

Fixes #12454

changelog: [needless_borrows_for_generic_args]: avoid moving variables

@rustbot
Copy link
Collaborator

rustbot commented Apr 23, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dswij (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 23, 2024
@pacak pacak force-pushed the less-aggressive-needless-borrows branch 2 times, most recently from 9a5a614 to 8e67bf1 Compare April 23, 2024 15:58
Current implementation looks for significant drops, that can change the
behavior, but that's not enough - value might not have a Drop itself but
one of its children might have it.

A good example is passing a reference to `PathBuf` to `std::fs::File::open`.
There's no benefits to pass `PathBuf` by value, but since clippy can't
see `Drop` on `Vec` several layers down it complains forcing pass by
value and making it impossible to use the same name later.

New implementation only looks at copy values or values created inplace
so existing variable will never be moved but things that take a string
reference created and value is created inplace `&"".to_owned()` will
make it to suggest to use `"".to_owned()` still.

Fixes rust-lang#12454
@pacak pacak force-pushed the less-aggressive-needless-borrows branch from 8e67bf1 to 79a14de Compare May 5, 2024 16:08
@dswij
Copy link
Member

dswij commented May 15, 2024

Thank you. @bors r+

@bors
Copy link
Collaborator

bors commented May 15, 2024

📌 Commit 79a14de has been approved by dswij

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented May 15, 2024

⌛ Testing commit 79a14de with merge e669d97...

@bors
Copy link
Collaborator

bors commented May 15, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: dswij
Pushing e669d97 to master...

@bors bors merged commit e669d97 into rust-lang:master May 15, 2024
5 checks passed
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
4 participants