Skip to content

Deriving for #[repr(packed)] types #52

Description

@funsafemath

It would be nice to be able to derive traits for Copyable packed types by moving out of the reference

#[repr(packed)]
struct Struct<T>(i32, PhantomData<T>);

educe:

#[educe(Clone)]
#[repr(packed)]
struct Struct<T>(i32, PhantomData<T>);
#[automatically_derived]
impl<T> ::core::clone::Clone for Struct<T> {
    #[inline]
    fn clone(&self) -> Self {
        Self(::core::clone::Clone::clone(&self.0), ::core::clone::Clone::clone(&self.1))
    }
    #[inline]
    fn clone_from(&mut self, source: &Self) {
        ::core::clone::Clone::clone_from(&mut self.0, &source.0);
        ::core::clone::Clone::clone_from(&mut self.1, &source.1);
    }
}

core:

#[repr(packed)]
struct Struct<T>(i32, PhantomData<T>);
#[automatically_derived]
impl<T: ::core::clone::Clone + ::core::marker::Copy> ::core::clone::Clone for Struct<T> {
    #[inline]
    fn clone(&self) -> Struct<T> {
        Struct(
            ::core::clone::Clone::clone(&{ self.0 }),
            ::core::clone::Clone::clone(&{ self.1 }),
        )
    }
}

derivative:

#[derivative(Clone)]
#[repr(packed)]
struct Struct<T>(i32, PhantomData<T>);
#[allow(unused_qualifications)]
impl<T> ::std::clone::Clone for Struct<T> {
    fn clone(&self) -> Self {
        match *self {
            Struct(__arg_0, __arg_1) => Struct(__arg_0.clone(), __arg_1.clone()),
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions