rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

less aggressive needless_borrows_for_generic_args

Open pacak opened this issue 1 year ago • 1 comments

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 https://github.com/rust-lang/rust-clippy/issues/12454

changelog: [needless_borrows_for_generic_args]: avoid moving variables

pacak avatar Apr 23 '24 13:04 pacak

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 avatar Apr 23 '24 13:04 rustbot

Thank you. @bors r+

dswij avatar May 15 '24 15:05 dswij

:pushpin: Commit 79a14dea86fe8e8f5588fb2a32f5b73f065529a3 has been approved by dswij

It is now in the queue for this repository.

bors avatar May 15 '24 15:05 bors

:hourglass: Testing commit 79a14dea86fe8e8f5588fb2a32f5b73f065529a3 with merge e669d97494e82741b2a06cab2e5eb163c9986833...

bors avatar May 15 '24 15:05 bors

:sunny: Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test Approved by: dswij Pushing e669d97494e82741b2a06cab2e5eb163c9986833 to master...

bors avatar May 15 '24 16:05 bors