Skip to content
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

Deriving Clone may silently fail for Arc #19034

Closed
dtantsur opened this issue Nov 17, 2014 · 2 comments
Closed

Deriving Clone may silently fail for Arc #19034

dtantsur opened this issue Nov 17, 2014 · 2 comments

Comments

@dtantsur
Copy link

The example:

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.

@dtantsur
Copy link
Author

Note that manually implementing Clone works, so this should be a valid deriving IMO

@alexcrichton
Copy link
Member

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!

lnicola pushed a commit to lnicola/rust that referenced this issue Jan 27, 2025
…en-variant

fix: Don't complete doc(hidden) enum variants and use trees
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants