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
{{ message }}
Repository navigation
Requires Copy constraint on parametrized struct that is already known to #[derive(Copy)] #32872
Private struct IterBase is known to implement Copy for all types it supports. However, #[derive(Copy)] for public struct FwdIter (which simply wraps IterBase) gives the following error:
<anon>:12:17: 12:21 error: the trait `Copy` may not be implemented for this type; field `iter` does not implement `Copy` [E0204]
<anon>:12 #[derive(Clone, Copy)]
^~~~
<anon>:12:17: 12:21 note: in this expansion of #[derive_Copy] (defined in <anon>)
<anon>:12:17: 12:21 help: see the detailed explanation for E0204
error: aborting due to previous error
playpen: application terminated with error code 101
One workaround is to make IterBase public and explicitly add IterBase<'a, Meta>: Copy to the where clause of FwdIter (and all its impls).
So looking at the expanded code, it looks like the problem is with the impl of Copy for FwdIter. The current implementation only requires that Meta: Copy, but that doesn't mean that Meta::AssocType: Copy, which leads to this error. I think this is a bug in the derive code, but I'm not sure it's all that easy to fix--if even possible--because in order to know whether Meta::AssocType: Copy is required, you need to inspect the IterBase type to see if it uses AssocType as a field, which I don't think is possible.
I'm thinking we should close this as not really possible to fix, but since I'm uncertain, I'll leave open for the time being. Perhaps someone more familiar with this code could comment? Otherwise, I'll close in a week or two.
Activity
Aatch commentedon Apr 11, 2016
This is a limitation of derive, you can just do
impl Copy for FwdIter(with the appropriate type params added) instead.marcianx commentedon Apr 11, 2016
I just tried that:
but I received the same error on this impl line.
Aatch commentedon Apr 11, 2016
Ah, right, that's because the same limitation affects
IterBase, it's requiring thatMetabeCopytoo.bluss commentedon Apr 11, 2016
And both Copy and Clone need manual implementations here. (Clone can reuse Copy though).
marcianx commentedon Apr 12, 2016
It's strange that
IterBaserequiresMetato be copy asIterBaseit only contains a shared reference.But sure enough, as it says https://doc.rust-lang.org/std/marker/trait.Copy.html
Thanks for the clarification.
huonw commentedon Apr 12, 2016
Duplicate of #26925, thanks for filing!
marcianx commentedon Apr 12, 2016
@huonw My last message is related to the bug you marked this as a dupe of. But isn't the original bug reported here different? The error says
But it is implement right above it in my example up top. So some information is not being propagated correctly.
huonw commentedon Apr 21, 2016
@marcianx, oh, sorry, you are correct that this seems different!
Mark-Simulacrum commentedon May 3, 2017
So looking at the expanded code, it looks like the problem is with the impl of Copy for
FwdIter. The current implementation only requires thatMeta: Copy, but that doesn't mean thatMeta::AssocType: Copy, which leads to this error. I think this is a bug in the derive code, but I'm not sure it's all that easy to fix--if even possible--because in order to know whetherMeta::AssocType: Copyis required, you need to inspect theIterBasetype to see if it usesAssocTypeas a field, which I don't think is possible.I'm thinking we should close this as not really possible to fix, but since I'm uncertain, I'll leave open for the time being. Perhaps someone more familiar with this code could comment? Otherwise, I'll close in a week or two.
Mark-Simulacrum commentedon May 7, 2017
Closing in favor of #26925.