//@ run-pass // Transmuting to/from ZSTs that contain generics. #![feature(transmute_generic_consts)] // Verify non-generic ZST -> generic ZST transmute unsafe fn cast_zst0(from: ()) -> [T; 0] { ::std::mem::transmute::<(), [T; 0]>(from) } // Verify generic ZST -> non-generic ZST transmute unsafe fn cast_zst1(from: [T; 0]) -> () { ::std::mem::transmute::<[T; 0], ()>(from) } // Verify transmute with generic compound types unsafe fn cast_zst2(from: ()) -> [(T, T); 0] { ::std::mem::transmute::<(), [(T, T); 0]>(from) } // Verify transmute with ZST propagation through arrays unsafe fn cast_zst3(from: ()) -> [[T; 0]; 8] { ::std::mem::transmute::<(), [[T; 0]; 8]>(from) } // Verify transmute with an extra ZST field pub struct PtrAndZst { _inner: *mut T, _other: (), } pub unsafe fn cast_ptr(from: *mut T) -> PtrAndZst { std::mem::transmute(from) } pub fn main() { unsafe { let _: [u32; 0] = cast_zst0(()); let _ = cast_zst1::([]); let _: [(u32, u32); 0] = cast_zst2(()); let _: [[u32; 0]; 8] = cast_zst3(()); cast_ptr(&mut 42); }; }