-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
PhantomData should implement Clone #29005
Comments
What version of Rust are you using? Can you post some source code that doesn't compile due to this issue? |
Agreed with @apasel422, so closing, but feel free to post an error message here so we can help debug! |
Here's a minimized misleading sample: use std::marker::PhantomData;
trait Foo<T>: Clone {
}
#[derive(Clone)]
pub struct KeyedIgnoring<T> {
witness: PhantomData<T>,
}
impl<T> Foo<T> for KeyedIgnoring<T> /* where Foo<T> : Clone */ {
// error: the trait `core::clone::Clone` is not implemented for the type `T`
}
fn main() {
println!("Hello, world!");
} Now, if I uncomment |
Also, adding |
See #26925; you should be able to get around the issue by implementing Clone manually. ( |
Yes, hence
in my original comment. As it is, I had to revert my change in which I added |
Yes currently |
Summary: Major refactoring of the parser in hope of squeezing noticeable gains by not passing around SmartConstructors state. Basically, replace the following: make_XYZ(state: State, ...) -> (State, R) with make_XYZ(&mut self, ...) -> R and make each of the 5 implementors of SmartConstructors stateful by turning the old method `initial_state(...)` into constructor `new`. Unfortunately, this means more boilerplate in the **user code** (i.e., implementors of SmartConstructors): - implementing Clone for each implementor of StateType - implementing Clone for each implementor of SmartConstructors this *cannot* be auto-generated via `#[derive(Clone)` because of the [`PhantomData`](rust-lang/rust#29005 (comment)) that is needed to narrow down trait impl of `StateType`. Reviewed By: shiqicao Differential Revision: D16374645 fbshipit-source-id: 37c248e70d93dd505e5478a57b646ad469907d7c
I don't see any good reason to prevent it, and this would have saved me lots of manual implementations of
Clone
.The text was updated successfully, but these errors were encountered: