1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // ignore-linux #7340 fails on 32-bit linux
12 // ignore-macos #7340 fails on 32-bit macos
28 fn mk_rec<A,B>(a: A, b: B) -> Rec<A,B> {
29 Rec { chA:0u8, tA:VarA(a), chB:1u8, tB:VarB(b) }
32 fn is_aligned<A>(amnt: uint, u: &A) -> bool {
33 let p: uint = unsafe { cast::transmute(u) };
34 return (p & (amnt-1u)) == 0u;
37 fn variant_data_is_aligned<A,B>(amnt: uint, u: &Tag<A,B>) -> bool {
39 &VarA(ref a) => is_aligned(amnt, a),
40 &VarB(ref b) => is_aligned(amnt, b)
45 let x = mk_rec(22u64, 23u64);
46 assert!(is_aligned(8u, &x.tA));
47 assert!(variant_data_is_aligned(8u, &x.tA));
48 assert!(is_aligned(8u, &x.tB));
49 assert!(variant_data_is_aligned(8u, &x.tB));
51 let x = mk_rec(22u64, 23u32);
52 assert!(is_aligned(8u, &x.tA));
53 assert!(variant_data_is_aligned(8u, &x.tA));
54 assert!(is_aligned(8u, &x.tB));
55 assert!(variant_data_is_aligned(4u, &x.tB));
57 let x = mk_rec(22u32, 23u64);
58 assert!(is_aligned(8u, &x.tA));
59 assert!(variant_data_is_aligned(4u, &x.tA));
60 assert!(is_aligned(8u, &x.tB));
61 assert!(variant_data_is_aligned(8u, &x.tB));
63 let x = mk_rec(22u32, 23u32);
64 assert!(is_aligned(4u, &x.tA));
65 assert!(variant_data_is_aligned(4u, &x.tA));
66 assert!(is_aligned(4u, &x.tB));
67 assert!(variant_data_is_aligned(4u, &x.tB));
69 let x = mk_rec(22f64, 23f64);
70 assert!(is_aligned(8u, &x.tA));
71 assert!(variant_data_is_aligned(8u, &x.tA));
72 assert!(is_aligned(8u, &x.tB));
73 assert!(variant_data_is_aligned(8u, &x.tB));