2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(dead_code)]
|
2018-08-31 08:02:01 -05:00
|
|
|
#![allow(deprecated)]
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2013-10-16 20:34:01 -05:00
|
|
|
use std::mem;
|
2013-05-24 21:35:29 -05:00
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn addr_of<T>(ptr: &T) -> usize {
|
|
|
|
ptr as *const T as usize
|
2013-03-11 03:04:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_aligned<T>(ptr: &T) -> bool {
|
2013-04-26 16:04:39 -05:00
|
|
|
unsafe {
|
2015-03-25 19:06:52 -05:00
|
|
|
let addr: usize = mem::transmute(ptr);
|
2013-10-16 20:34:01 -05:00
|
|
|
(addr % mem::min_align_of::<T>()) == 0
|
2013-04-26 16:04:39 -05:00
|
|
|
}
|
2013-03-11 03:04:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let x = Some(0u64);
|
|
|
|
match x {
|
2014-10-09 14:17:22 -05:00
|
|
|
None => panic!(),
|
2013-03-28 20:39:09 -05:00
|
|
|
Some(ref y) => assert!(is_aligned(y))
|
2013-03-11 03:04:08 -05:00
|
|
|
}
|
|
|
|
}
|