Skip to main content

RustSpec

Derive Macro RustSpec 

Source
#[derive(RustSpec)]
{
    // Attributes available to this derive:
    #[rust_spec]
}
Expand description

Derives RustSpec for a struct, enum, or union.

Add #[rust_spec(custom_drop)] if the type itself implements Drop. Add #[rust_spec(custom_niche)] if a struct has a custom niche. Add #[rust_spec(opaque)] to classify the type as Opacity = Opaque

§Safety hazards of private invariants

The derive infers RustSpec axes from the fields. It cannot see invariants enforced through private constructors.

For example, if an invariant of #[repr(C)] Wrapper(u8) is that it may never hold u8::MAX, RustSpec will infer Layout = Stable and Trap = Robust which downstream consumers may interpret as a permission to transmute u8 into Wrapper and cause UB.

Likewise, be very careful when the inner fields are raw pointers, NonNull<T> or MaybeUninit<T>. UnsafeCell<T> and ManuallyDrop<T> fields, however, don’t require special care from the user.