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