-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
In <&NotClone as Clone>::clone()
call, account for bindings
#112977
Conversation
Address rust-lang#112857: ``` error[E0308]: mismatched types --> $DIR/explain_clone_autoref.rs:28:5 | LL | fn clone_thing3(nc: &NotClone) -> NotClone { | -------- expected `NotClone` because of return type ... LL | nc | ^^ expected `NotClone`, found `&NotClone` | note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead --> $DIR/explain_clone_autoref.rs:26:14 | LL | let nc = nc.clone(); | ^^ help: consider annotating `NotClone` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | struct NotClone; | ```
(rustbot has picked a reviewer for you, use r? to override) |
@strottos you might want to look at the changes here and see if there are other kind of expressions that we might want to also support, not just single bindings. |
The job Click to see the possible cause of the failure (guessed by this bot)
|
This is great, thanks Esteban. So it can be triggered still further by this kind of (rather contrived) example:
We could I guess keep looping through till no parents found but there maybe should be a limit too and maybe a single round is going to catch enough. This is still an improvement. On the other hand these are all slightly contrived examples and in the real world something more complex is likely to be the program, maybe wouldn't hurt to loop a little bit further through. Will have another look over the weekend to see if there's anything else worth thinking about. |
So I had another look at this over the weekend. I think there are improvements but I certainly see no issue with this PR so feel free to push it whenever for this issue. I did put together a separate PR #112995 as an improvement that takes it a step further and recursively trails back up in case we do the above of:
Apologies @estebank as it builds on your work but wasn't sure how best to push suggestions. Not trying to take credit for your work at all and hope it doesn't come across that way. I'd suggest we either: With regards to (ii) and (iii) options my minor concerns are: |
☔ The latest upstream changes (presumably #113637) made this pull request unmergeable. Please resolve the merge conflicts. |
…fee1-dead Check for `<&NotClone as Clone>::clone()` calls and suggest to add Clone trait appropriately Added recursive checking back up the HIR to see if a `Clone` suggestion would be helpful. Addresses rust-lang#112857 Largely based on: rust-lang#112977
Address #112857: