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 | |
| parent | 93067ca089ea570e4e2bdfc456958c81a4d1e092 (diff) | |
| download | rust-436cfe56534b405786816d4bbcccd11ed7571981.tar.gz rust-436cfe56534b405786816d4bbcccd11ed7571981.zip | |
Fix type encoding/decoding for unions
Fix union debuginfo test on lldb
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/debuginfo/union-smoke.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/union/auxiliary/union.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/union/union-basic.rs | 55 | ||||
| -rw-r--r-- | src/test/run-pass/union/union-xcrate.rs | 21 |
4 files changed, 36 insertions, 48 deletions
diff --git a/src/test/debuginfo/union-smoke.rs b/src/test/debuginfo/union-smoke.rs index 17dea300ff9..319927c979b 100644 --- a/src/test/debuginfo/union-smoke.rs +++ b/src/test/debuginfo/union-smoke.rs @@ -23,10 +23,10 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print a -// lldb-check:[...]$0 = {a = {__0 = 2 '\002', __1 = 2 '\002'}, b = 514} +// lldb-command:print u +// lldb-check:[...]$0 = { a = ('\x02', '\x02') b = 514 } // lldb-command:print union_smoke::SU -// lldb-check:[...]$1 = {a = {__0 = 1 '\001', __1 = 1 '\001'}, b = 257} +// lldb-check:[...]$1 = 257 #![allow(unused)] #![feature(omit_gdb_pretty_printer_section)] diff --git a/src/test/run-pass/union/auxiliary/union.rs b/src/test/run-pass/union/auxiliary/union.rs index dc0ca7c81c0..0231e38a729 100644 --- a/src/test/run-pass/union/auxiliary/union.rs +++ b/src/test/run-pass/union/auxiliary/union.rs @@ -12,5 +12,5 @@ pub union U { pub a: u8, - b: u16, + pub b: u16, } 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(); +} diff --git a/src/test/run-pass/union/union-xcrate.rs b/src/test/run-pass/union/union-xcrate.rs deleted file mode 100644 index 2a76c96ef25..00000000000 --- a/src/test/run-pass/union/union-xcrate.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// 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; - -type A = union::U; - -fn main() { - assert_eq!(std::mem::size_of::<A>(), 8); -} |
