-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Better error message for transitive req of #[deriving]. (Also, how to use deriving here?) #9607
Comments
I don't think it's possible to derive here :( #7229 would be an avenue for a solution, but it seems people aren't particularly keen on that. |
Triage: the above snippet compiles cleanly now, should be closed. |
The underlying issue still exists, that snippet compiles due to unrelated library changes. struct Foo<T>;
trait Bar {}
impl<T: Bar> Clone for Foo<T> {
fn clone(&self) -> Foo<T> { Foo }
}
#[deriving(Clone)]
struct Baz<T> {
x: Foo<T>
}
fn main() {}
|
I actually have run into this issue before and have had to manually implement Clone. I think that this issue is actually unrelated to the stated issue because it has to do with the way that the generated impl for Clone automatically binds all type parameters with Clone, which isn't fixable without more type information at the syntax extension stage. |
It is definitely related. The contained value |
Ah, I see now. Does deriving play nice with struct bounds? i.e. if I did |
Yes it looks like it does, but that doesn't solve the general case, since |
Triage bump: Updated test: use std::marker::{MarkerTrait, PhantomData};
struct Foo<T> {
marker: PhantomData<T>
}
trait Bar: MarkerTrait {}
impl<T: Bar> Clone for Foo<T> {
fn clone(&self) -> Foo<T> { Foo {marker: PhantomData} }
}
#[derive(Clone)]
struct Baz<T> {
x: Foo<T>
}
fn main() {} Output:
|
Triaging: Updated the latest snippet by removing the MarkerTrait. use std::marker::PhantomData;
struct Foo<T> {
marker: PhantomData<T>
}
trait Bar {}
impl<T: Bar> Clone for Foo<T> {
fn clone(&self) -> Foo<T> { Foo {marker: PhantomData} }
}
#[derive(Clone)]
struct Baz<T> {
x: Foo<T>
}
fn main() {} Output:
|
Update: The error output is now
Which is only missing a note about the Related to the original question of why we can't use Couldn't the code generated by |
Triage: no change. |
@oli-obk asked:
Would we be able to make that change backward compatibly? Probably not because it would make existing types that did not previously implement |
It would be interesting implementing the behavior and make a crater run to see if there would be significant impact in the ecosystem. |
Triage: current output:
|
Update:
|
Triage: the current error message is pretty good IMO. (playground)
Perhaps the only improvement could be to point to the specific derive macro that is causing this?
Removing |
Why would that be a breaking change? If |
With #87225, the output is now
There are details in the wording we could improve and some things we could take out, but I feel all the relevant information is there. @pnkfelix what do you think? Should we close this ticket? (It's always a good day when I get to close a pre-1.0 ticket 😄) |
For posterity, this is what it looks like now:
|
Updated test (play):
(I'll try to update the above as necessary.)
The error message is pretty good now, actually; the only thing I'd want beyond this is for the diagnostic to point out that
Baz
is trying to automatically deriveClone
(which is why it is missing the necessaryT: Bar
bound), and that a manual implementation with that bound would work.Original bug report follows.
Error message from rustc:
I saw the above, and said "why does it matter about whether I implement
IterBytes
when I want to implementClone
here. (Then I read source code forhashmap.rs
and saw that we actually build up the new table from scratch, rather than copying the existing underlying representation directly; so that explains why one needs it.)Anyway, it would be good if the error message actually pointed us at the use of
HashSet<T>
in the definition ofstruct FollowSet
above.Oh, also: Is there actually a way for one to use deriving here for this? As far as I can tell, I'm going to be forced to manually implement
Clone
. (Its not hard to do, just a little surprising.)(not a true dupe of #7621 since that discussing errors when deriving Clone and constituents do not implement Clone. Here, we determine that the constituent does implement Clone, if some it implements some other trait as well. But its possible that a solution for one would also resolve the other.)
The text was updated successfully, but these errors were encountered: