-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.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
use std::rc::Rc;
#[derive(Clone)]
struct ContainsRc<T> {
value: Rc<T>,
}
fn clone_me<T>(x: &ContainsRc<T>) -> ContainsRc<T> {
x.clone()
}
results in
error[E0308]: mismatched types
--> src/lib.rs:9:5
|
8 | fn clone_me<T>(x: &ContainsRc<T>) -> ContainsRc<T> {
| ------------- expected `ContainsRc<T>` because of return type
9 | x.clone()
| ^^^^^^^^^ expected `ContainsRc<T>`, found `&ContainsRc<T>`
|
= note: expected struct `ContainsRc<_>`
found reference `&ContainsRc<_>`
note: `ContainsRc<T>` does not implement `Clone`, so `&ContainsRc<T>` was cloned instead
--> src/lib.rs:9:5
|
9 | x.clone()
| ^
= help: `Clone` is not implemented because the trait bound `T: Clone` is not satisfied
help: consider annotating `ContainsRc<T>` with `#[derive(Clone)]`
|
4 + #[derive(Clone)]
5 | struct ContainsRc<T> {
|
We should not suggest adding #[derive(Clone)]
if the struct already derives Clone
:> the issue is the unnecessary T: Clone
constraint added by the derive.
issokuosasquared31415
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.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.