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