Originally posted by @simonbuchan in #26925 (comment)
I think I would be a lot happier with the current situation with "just" adding more information to the compiler diagnostic.
At the moment, you get something like:
error[E0599]: no method named `clone` found for type `Ptr<Foo>` in the current scope
--> src/main.rs:9:15
|
2 | struct Ptr<T>(*mut T);
| ---------------------- method `clone` not found for this
...
9 | let b = a.clone();
| ^^^^^ method not found in `Ptr<Foo>`
|
= note: the method `clone` exists but the following trait bounds were not satisfied:
`Ptr<Foo> : std::clone::Clone`
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `clone`, perhaps you need to implement it:
candidate #1: `std::clone::Clone`
or
error[E0382]: use of moved value: `a`
--> src/main.rs:10:15
|
8 | let a = Ptr(&mut foo);
| - move occurs because `a` has type `Ptr<Foo>`, which does not implement the `Copy` trait
9 | let b = a;
| - value moved here
10 | let ptr = a.0;
| ^^^ value used here after move
Neither of these tell you that the reason Ptr doesn't implement Copy or Clone, despite #[derive(Copy, Clone)] being right there. I think some logic to add another sentence for this would get rid of the case where derive doesn't implement when it should, which I think newer users (like me!) would be more likely to hit.
Originally posted by @simonbuchan in #26925 (comment)
I think I would be a lot happier with the current situation with "just" adding more information to the compiler diagnostic.
At the moment, you get something like:
or
Neither of these tell you that the reason
Ptrdoesn't implementCopyorClone, despite#[derive(Copy, Clone)]being right there. I think some logic to add another sentence for this would get rid of the case wherederivedoesn't implement when it should, which I think newer users (like me!) would be more likely to hit.