#![warn(clippy::transmute_undefined_repr)] #![allow(clippy::unit_arg, clippy::transmute_ptr_to_ref)] use core::ffi::c_void; use core::mem::{size_of, transmute}; fn value() -> T { unimplemented!() } struct Empty; struct Ty(T); struct Ty2(T, U); #[repr(C)] struct Ty2C(T, U); fn main() { unsafe { let _: () = transmute(value::()); let _: Empty = transmute(value::<()>()); let _: Ty = transmute(value::()); let _: Ty = transmute(value::()); let _: Ty2C = transmute(value::>()); // Lint, Ty2 is unordered let _: Ty2 = transmute(value::>()); // Lint, Ty2 is unordered let _: Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same let _: Ty> = transmute(value::>()); // Ok, Ty2 types are the same let _: Ty2 = transmute(value::>>()); // Lint, different Ty2 instances let _: Ty> = transmute(value::>()); // Lint, different Ty2 instances let _: Ty<&()> = transmute(value::<&()>()); let _: &() = transmute(value::>()); let _: &Ty2 = transmute(value::>>()); // Lint, different Ty2 instances let _: Ty<&Ty2> = transmute(value::<&Ty2>()); // Lint, different Ty2 instances let _: Ty = transmute(value::<&Ty2>()); // Ok, pointer to usize conversion let _: &Ty2 = transmute(value::>()); // Ok, pointer to usize conversion let _: Ty<[u8; 8]> = transmute(value::>()); // Ok, transmute to byte array let _: Ty2 = transmute(value::>()); // Ok, transmute from byte array // issue #8417 let _: Ty2C, ()> = transmute(value::>()); // Ok, Ty2 types are the same let _: Ty2 = transmute(value::, ()>>()); // Ok, Ty2 types are the same let _: &'static mut Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same let _: Box> = transmute(value::<&'static mut Ty2>()); // Ok, Ty2 types are the same let _: *mut Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same let _: Box> = transmute(value::<*mut Ty2>()); // Ok, Ty2 types are the same let _: &'static mut Ty2 = transmute(value::>>()); // Lint, different Ty2 instances let _: Box> = transmute(value::<&'static mut Ty2>()); // Lint, different Ty2 instances let _: *const () = transmute(value::>>()); // Ok, type erasure let _: Ty<&Ty2> = transmute(value::<*const ()>()); // Ok, reverse type erasure let _: *const c_void = transmute(value::>>()); // Ok, type erasure let _: Ty<&Ty2> = transmute(value::<*const c_void>()); // Ok, reverse type erasure enum Erase {} let _: *const Erase = transmute(value::>>()); // Ok, type erasure let _: Ty<&Ty2> = transmute(value::<*const Erase>()); // Ok, reverse type erasure struct Erase2( [u8; 0], core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, ); let _: *const Erase2 = transmute(value::>>()); // Ok, type erasure let _: Ty<&Ty2> = transmute(value::<*const Erase2>()); // Ok, reverse type erasure let _: *const () = transmute(value::<&&[u8]>()); // Ok, type erasure let _: &&[u8] = transmute(value::<*const ()>()); // Ok, reverse type erasure let _: *mut c_void = transmute(value::<&mut &[u8]>()); // Ok, type erasure let _: &mut &[u8] = transmute(value::<*mut c_void>()); // Ok, reverse type erasure let _: [u8; size_of::<&[u8]>()] = transmute(value::<&[u8]>()); // Ok, transmute to byte array let _: &[u8] = transmute(value::<[u8; size_of::<&[u8]>()]>()); // Ok, transmute from byte array let _: [usize; 2] = transmute(value::<&[u8]>()); // Ok, transmute to int array let _: &[u8] = transmute(value::<[usize; 2]>()); // Ok, transmute from int array let _: *const [u8] = transmute(value::>()); // Ok let _: Box<[u8]> = transmute(value::<*mut [u8]>()); // Ok } }