-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Here's a reduced testcase:
use std::sync::Arc;
struct Foo;
#[derive(Clone)]
struct Bar<T>(Arc<T>);
fn main() {
let a = Bar(Arc::new(Foo));
let b = a.clone();
}
This fails to compile with:
error[E0599]: no method named `clone` found for type `Bar<Foo>` in the current scope
--> src/main.rs:10:15
|
6 | struct Bar<T>(Arc<T>);
| ---------------------- method `clone` not found for this
...
10 | let b = a.clone();
| ^^^^^
|
= note: the method `clone` exists but the following trait bounds were not satisfied:
`Bar<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`
The way #[derive]
works (#26925), and with 20/20 hindsight, it's obvious what's wrong. But even when you know about #26925 it takes a mental effort to go from that error message to "oh, right, #[derive(Clone)]
adds T: Clone
".
It would be useful if the compiler went further, and, considering there is an impl Clone for Bar<T>
, detailed why that impl doesn't apply to Foo
.
d-e-s-o
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.