Skip to content

Ignore zero-width fields like PhantomData #437

@raklaptudirm

Description

@raklaptudirm

Ignore zero-width fields to allow complier hinting with types like PhantomData while deriving trait imlementations.

// This should work.
#[derive(derive_more::Add)]
struct A<B>(u16, PhantomData<B>);

// Equivalent to:
impl<B> Add for A<B> {
    type Output = Self;

    fn add(self, rhs: Self) -> Self::Output {
        Self(self.0 + rhs.0, PhantomData)
    }
}

This behavior can be seen in #[repr(transparent)], where the annotation will work as long as there is only one non-zero-width type.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions