You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::sync;
trait Trait {}
struct DontCloneMe {
pub value: int
}
impl Trait for DontCloneMe {}
#[deriving(Clone)]
struct CloneMe<T: Trait> {
pub arc: sync::Arc<T>,
}
fn main() {
let v = CloneMe {
arc: sync::Arc::new(DontCloneMe { value: 0 })
};
v.clone();
}
Without Trait it would work as expected. With trait deriving seems to succeed, but compilation fails on calling clone:
demo.rs:21:7: 21:14 error: type `CloneMe<DontCloneMe>` does not implement any method in scope named `clone`
demo.rs:21 v.clone();
^~~~~~~
error: aborting due to previous error
If this is invalid deriving (though I don't see reasons why), it should fail with some meaningful message.
The text was updated successfully, but these errors were encountered:
Hm this is interesting! The problem here is that #[deriving] adds the trait as a bound to any type parameters, so even though Arc<T> implements Clone for all T, the #[deriving] implementation still adds the Clone bound on the impl that it generates.
If you remove the Clone bound (by writing the impl manually), then the error will go away. I believe that the error happens at the callsite because that's the point at which the type parameter T is known. The impl itself is valid, you just can't call it because the DontCloneMe type doesn't implement Clone (not matching the impl).
I'm going to close this as working as intended for now, but thanks for the report!
The example:
Without Trait it would work as expected. With trait deriving seems to succeed, but compilation fails on calling clone:
If this is invalid deriving (though I don't see reasons why), it should fail with some meaningful message.
The text was updated successfully, but these errors were encountered: