rust-clippy/tests/ui/cast_alignment.rs
Devon Hollowood c6bc682325 Fix misaligned_transmute lint
This is done by adding two new lints: cast_ptr_alignment and
transmute_ptr_to_ptr. These will replace misaligned_transmute.
2018-04-11 02:17:59 -07:00

19 lines
496 B
Rust

//! Test casts for alignment issues
#[warn(cast_ptr_alignment)]
#[allow(no_effect, unnecessary_operation, cast_lossless)]
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;
/* These should be okay */
// 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;
}