// run-pass use std::mem::size_of; use std::num::NonZeroUsize; use std::ptr::NonNull; use std::rc::Rc; use std::sync::Arc; trait Trait { fn dummy(&self) { } } trait Mirror { type Image; } impl Mirror for T { type Image = T; } struct ParamTypeStruct(T); struct AssocTypeStruct(::Image); fn main() { // Functions assert_eq!(size_of::(), size_of::>()); assert_eq!(size_of::(), size_of::>()); // Slices - &str / &[T] / &mut [T] assert_eq!(size_of::<&str>(), size_of::>()); assert_eq!(size_of::<&[isize]>(), size_of::>()); assert_eq!(size_of::<&mut [isize]>(), size_of::>()); // Traits - Box / &Trait / &mut Trait assert_eq!(size_of::>(), size_of::>>()); assert_eq!(size_of::<&Trait>(), size_of::>()); assert_eq!(size_of::<&mut Trait>(), size_of::>()); // Pointers - Box assert_eq!(size_of::>(), size_of::>>()); // The optimization can't apply to raw pointers assert!(size_of::>() != size_of::<*const isize>()); assert!(Some(0 as *const isize).is_some()); // Can't collapse None to null struct Foo { _a: Box } struct Bar(Box); // Should apply through structs assert_eq!(size_of::(), size_of::>()); assert_eq!(size_of::(), size_of::>()); // and tuples assert_eq!(size_of::<(u8, Box)>(), size_of::)>>()); // and fixed-size arrays assert_eq!(size_of::<[Box; 1]>(), size_of::; 1]>>()); // Should apply to NonZero assert_eq!(size_of::(), size_of::>()); assert_eq!(size_of::>(), size_of::>>()); // Should apply to types that use NonZero internally assert_eq!(size_of::>(), size_of::>>()); assert_eq!(size_of::>(), size_of::>>()); assert_eq!(size_of::>(), size_of::>>()); // Should apply to types that have NonZero transitively assert_eq!(size_of::(), size_of::>()); // Should apply to types where the pointer is substituted assert_eq!(size_of::<&u8>(), size_of::>>()); assert_eq!(size_of::<&u8>(), size_of::>>()); }