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
For the Clone trait (I haven't tried other traits), derivative will impl Clone on a type even if one of its members doesn't and instead just has a function called clone() that matches the interface.
This also means if the members where to impl Clone and have a separate clone function, then the derivative impl would not call, Clone::clone but the Members::clone.
use derivative; // 2.2.0
struct DoesNotImplClone {}
impl DoesNotImplClone {
fn clone(&self) -> Self {
Self {}
}
}
// Works, but I would expect it to fail
#[derive(derivative::Derivative)]
#[derivative(Clone)]
struct Derivative {x: DoesNotImplClone}
// Fails as expected
//
// #[derive(Clone)]
// struct Derive {x: DoesNotImplClone}
fn main() {}
Expected behavior
I would expect the derived trait's impl to always use the struct/enum member's impls of that derived trait (and if they don't impl the trait fail to compile). And to importantly never call functions that just happen to have the same interface, as the trait.
Version (please complete the following information):
stable 1.69.0 (See Playground), derivative 2.2.0
Describe the bug
For the
Clone
trait (I haven't tried other traits),derivative
will implClone
on a type even if one of its members doesn't and instead just has a function calledclone()
that matches the interface.This also means if the members where to impl Clone and have a separate clone function, then the derivative impl would not call, Clone::clone but the Members::clone.
To Reproduce
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e357412d7e9b32c3aef52fb4b4b8a7a4
Expected behavior
I would expect the derived trait's impl to always use the struct/enum member's impls of that derived trait (and if they don't impl the trait fail to compile). And to importantly never call functions that just happen to have the same interface, as the trait.
Version (please complete the following information):
stable 1.69.0 (See Playground), derivative 2.2.0
I've also tried this locally:
derivative
: 2.2.0The text was updated successfully, but these errors were encountered: