diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-08-26 19:23:42 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-09-03 13:39:35 +0300 |
| commit | 436cfe56534b405786816d4bbcccd11ed7571981 (patch) | |
| tree | 21c4e2972397731442e7753a991f69288fb9b3c8 /src/test/run-pass/union/union-basic.rs | |
| parent | 93067ca089ea570e4e2bdfc456958c81a4d1e092 (diff) | |
Fix type encoding/decoding for unions
Fix union debuginfo test on lldb
Diffstat (limited to 'src/test/run-pass/union/union-basic.rs')
| -rw-r--r-- | src/test/run-pass/union/union-basic.rs | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/src/test/run-pass/union/union-basic.rs b/src/test/run-pass/union/union-basic.rs index 1651aa901b9..d23af4b41b7 100644 --- a/src/test/run-pass/union/union-basic.rs +++ b/src/test/run-pass/union/union-basic.rs @@ -8,47 +8,51 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// aux-build:union.rs + #![feature(untagged_unions)] +extern crate union; use std::mem::{size_of, align_of, zeroed}; union U { a: u8, + b: u16 } -union U64 { - a: u64, -} +fn local() { + assert_eq!(size_of::<U>(), 2); + assert_eq!(align_of::<U>(), 2); -union W { - a: u8, - b: u64, -} + let u = U { a: 10 }; + unsafe { + assert_eq!(u.a, 10); + let U { a } = u; + assert_eq!(a, 10); + } -#[repr(C)] -union Y { - f1: u16, - f2: [u8; 4], + let mut w = U { b: 0 }; + unsafe { + assert_eq!(w.a, 0); + assert_eq!(w.b, 0); + w.a = 1; + assert_eq!(w.a, 1); + assert_eq!(w.b, 1); + } } -fn main() { - assert_eq!(size_of::<U>(), 1); - assert_eq!(size_of::<U64>(), 8); - assert_eq!(size_of::<W>(), 8); - assert_eq!(align_of::<U>(), 1); - assert_eq!(align_of::<U64>(), align_of::<u64>()); - assert_eq!(align_of::<W>(), align_of::<u64>()); - assert_eq!(size_of::<Y>(), 4); - assert_eq!(align_of::<Y>(), 2); +fn xcrate() { + assert_eq!(size_of::<union::U>(), 2); + assert_eq!(align_of::<union::U>(), 2); - let u = U { a: 10 }; + let u = union::U { a: 10 }; unsafe { assert_eq!(u.a, 10); - let U { a } = u; + let union::U { a } = u; assert_eq!(a, 10); } - let mut w = W { b: 0 }; + let mut w = union::U { b: 0 }; unsafe { assert_eq!(w.a, 0); assert_eq!(w.b, 0); @@ -57,3 +61,8 @@ fn main() { assert_eq!(w.b, 1); } } + +fn main() { + local(); + xcrate(); +} |
