-
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
Clone suggestion appears inconsistently #112857
Comments
I can see two ways around this, not sure which would be better or indeed if there's a better solution. Would love to have a go myself but would almost certainly need some guidance:
Neither seem trivial to me, as I say I'm very new to this and still finding my way round |
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 claim As I'm looking into this still. Ongoing. |
…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
This is now resolved after the above linked PR closed it last night. Checked in later master and no longer happening. |
Code
Current output
Desired output
Rationale and extra context
This program gives the right hint:
Similarly we have the following that gives the hint:
Not the end of the world certainly but the diagnostic is really helpful and it would be nice if we could get the first one to output the issue too.
I think (having gone through the code a bit, though I'm new to this) that
&a
is being cloned rather thana
asa
doesn't necessarily implement Clone and then on a line 3 a type mismatch is found on a line that doesn't specifyclone
. So when it does thenot_type_is_not_clone
check in therustc_hir_typeck
crate it's only checkingret
and it doesn't see that it comes from a clone attempt on the wrong type.Other cases
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: