Improve path to Clone::clone
call when deriving Clone
#3371
Labels
Milestone
Clone::clone
call when deriving Clone
#3371
Originally posted by @CohenArthur in #3343 (comment)
When derivine Clone, we have to perform "clone calls" to sub items. e.g. to clone a
struct Foo { a: T, b: U }
we need to create the following Clone implementation:The issue is that just calling
Clone::clone
is not valid, especially if the module structure is complex. So we can run into name collision issues with a user-definedClone
trait, which is not good. Similarly, we don't want to calla.clone()
as that may collide with a user defined trait.We can fix this by using the field's type and casting it as the known, official
Clone
trait and calling that trait's method. To do this, we need to generate the following code:Note that I think we could also do something like
#[lang = "clone"]::clone(self.a)
, but I think this requires yet another rework of lang items in the AST... and I'm not sure it's worth itThe text was updated successfully, but these errors were encountered: