2018-04-11 04:17:59 -05:00
|
|
|
//! Test casts for alignment issues
|
|
|
|
|
2018-12-12 10:17:01 -06:00
|
|
|
#![feature(rustc_private)]
|
2018-04-17 19:13:19 -05:00
|
|
|
extern crate libc;
|
|
|
|
|
2018-07-28 10:34:52 -05:00
|
|
|
#[warn(clippy::cast_ptr_alignment)]
|
|
|
|
#[allow(clippy::no_effect, clippy::unnecessary_operation, clippy::cast_lossless)]
|
2018-04-11 04:17:59 -05:00
|
|
|
fn main() {
|
|
|
|
/* These should be warned against */
|
|
|
|
|
|
|
|
// cast to more-strictly-aligned type
|
|
|
|
(&1u8 as *const u8) as *const u16;
|
|
|
|
(&mut 1u8 as *mut u8) as *mut u16;
|
|
|
|
|
2019-01-30 19:15:29 -06:00
|
|
|
/* These should be ok */
|
2018-04-11 04:17:59 -05:00
|
|
|
|
|
|
|
// not a pointer type
|
|
|
|
1u8 as u16;
|
|
|
|
// cast to less-strictly-aligned type
|
|
|
|
(&1u16 as *const u16) as *const u8;
|
|
|
|
(&mut 1u16 as *mut u16) as *mut u8;
|
2018-04-17 19:13:19 -05:00
|
|
|
// For c_void, we should trust the user. See #2677
|
|
|
|
(&1u32 as *const u32 as *const std::os::raw::c_void) as *const u32;
|
|
|
|
(&1u32 as *const u32 as *const libc::c_void) as *const u32;
|
2019-07-06 04:40:14 -05:00
|
|
|
// For ZST, we should trust the user. See #4256
|
|
|
|
(&1u32 as *const u32 as *const ()) as *const u32;
|
2018-04-11 04:17:59 -05:00
|
|
|
}
|