//! Test various invalid implementations of DispatchFromDyn trait. //! //! DispatchFromDyn is a special trait used by the compiler for dyn-compatible dynamic dispatch. //! This checks that the compiler correctly rejects invalid implementations: //! - Structs with extra non-coercible fields //! - Structs with multiple pointer fields //! - Structs with no coercible fields //! - Structs with repr(C) or other incompatible representations //! - Structs with over-aligned fields #![feature(unsize, dispatch_from_dyn)] use std::marker::{PhantomData, Unsize}; use std::ops::DispatchFromDyn; // Extra field prevents DispatchFromDyn struct WrapperWithExtraField(T, i32); impl DispatchFromDyn> for WrapperWithExtraField //~^ ERROR [E0378] where T: DispatchFromDyn { } // Multiple pointer fields create ambiguous coercion struct MultiplePointers { ptr1: *const T, ptr2: *const T, } impl DispatchFromDyn> for MultiplePointers //~^ ERROR implementing `DispatchFromDyn` does not allow multiple fields to be coerced where T: Unsize { } // No coercible fields (only PhantomData) struct NothingToCoerce { data: PhantomData, } impl DispatchFromDyn> for NothingToCoerce {} //~^ ERROR implementing `DispatchFromDyn` requires a field to be coerced // repr(C) is incompatible with DispatchFromDyn #[repr(C)] struct HasReprC(Box); impl DispatchFromDyn> for HasReprC //~^ ERROR [E0378] where T: Unsize { } // Over-aligned fields are incompatible #[repr(align(64))] struct OverAlignedZst; struct OverAligned(Box, OverAlignedZst); impl DispatchFromDyn> for OverAligned //~^ ERROR [E0378] where T: Unsize { } fn main() {}