about summary refs log tree commit diff
path: root/tests/ui/structs-enums/enum-alignment.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/structs-enums/enum-alignment.rs')
-rw-r--r--tests/ui/structs-enums/enum-alignment.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/ui/structs-enums/enum-alignment.rs b/tests/ui/structs-enums/enum-alignment.rs
new file mode 100644
index 00000000000..108dfe2e62d
--- /dev/null
+++ b/tests/ui/structs-enums/enum-alignment.rs
@@ -0,0 +1,24 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(deprecated)]
+
+use std::mem;
+
+fn addr_of<T>(ptr: &T) -> usize {
+    ptr as *const T as usize
+}
+
+fn is_aligned<T>(ptr: &T) -> bool {
+    unsafe {
+        let addr: usize = mem::transmute(ptr);
+        (addr % mem::min_align_of::<T>()) == 0
+    }
+}
+
+pub fn main() {
+    let x = Some(0u64);
+    match x {
+        None => panic!(),
+        Some(ref y) => assert!(is_aligned(y))
+    }
+}