1 //! Test casts for alignment issues
3 #![feature(rustc_private)]
6 #[warn(clippy::cast_ptr_alignment)]
7 #[allow(clippy::no_effect, clippy::unnecessary_operation, clippy::cast_lossless)]
9 /* These should be warned against */
11 // cast to more-strictly-aligned type
12 (&1u8 as *const u8) as *const u16;
13 (&mut 1u8 as *mut u8) as *mut u16;
15 // cast to more-strictly-aligned type, but with the `pointer::cast` function.
16 (&1u8 as *const u8).cast::<u16>();
17 (&mut 1u8 as *mut u8).cast::<u16>();
19 /* These should be ok */
23 // cast to less-strictly-aligned type
24 (&1u16 as *const u16) as *const u8;
25 (&mut 1u16 as *mut u16) as *mut u8;
26 // For c_void, we should trust the user. See #2677
27 (&1u32 as *const u32 as *const std::os::raw::c_void) as *const u32;
28 (&1u32 as *const u32 as *const libc::c_void) as *const u32;
29 // For ZST, we should trust the user. See #4256
30 (&1u32 as *const u32 as *const ()) as *const u32;