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

Avoid emitting `assigning_clones` when cloned data borrows from the place to clone into

Open y21 opened this issue 1 year ago • 1 comments

Fixes #12444 Fixes #12460 Fixes #12749 Fixes #12757

I think the documentation for the function should describe what- and how this is fixing the issues well. It avoids emitting a warning when the data being cloned borrows from the place to clone into, which is information that we can get from PossibleBorrowerMap. Unfortunately, it is a tiny bit tedious to match on the MIR like that and I'm not sure if this is possibly relying a bit too much on the exact MIR lowering for assignments.

Things left to do:

  • [x] Handle place projections (or verify that they work as expected)
  • [x] Handle non-Drop types

changelog: [assigning_clones]: avoid warning when the suggestion would lead to a borrow-check error

y21 avatar May 02 '24 21:05 y21

r? @Alexendoo

rustbot has assigned @Alexendoo. 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 avatar May 02 '24 21:05 rustbot

:umbrella: The latest upstream changes (presumably #12783) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar May 09 '24 22:05 bors

It would be great to merge this. Even if it's not perfect, it's much better than what has shipped in stable and causing numerous annoyances.

kornelski avatar Jun 14 '24 10:06 kornelski

@bors r+

It seems reasonable to me, it is relying on the MIR layout a bit but it seems like it would be fairly straightforward to adapt if that ever changes

Alexendoo avatar Jun 15 '24 18:06 Alexendoo

:pushpin: Commit 60508f546a07fa51169736766b7e16676724c496 has been approved by Alexendoo

It is now in the queue for this repository.

bors avatar Jun 15 '24 18:06 bors

:hourglass: Testing commit 60508f546a07fa51169736766b7e16676724c496 with merge 0dc265ff82fe861f673f20003e4370df52f50ff3...

bors avatar Jun 15 '24 18:06 bors

:sunny: Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test Approved by: Alexendoo Pushing 0dc265ff82fe861f673f20003e4370df52f50ff3 to master...

bors avatar Jun 15 '24 18:06 bors