1 // Copyright 2012 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.
23 fn mk_rec<A:Copy,B:Copy>(a: A, b: B) -> t_rec<A,B> {
24 return t_rec{ chA:0u8, tA:varA(a), chB:1u8, tB:varB(b) };
27 fn is_aligned<A>(amnt: uint, u: &A) -> bool {
28 let p = ptr::to_unsafe_ptr(u) as uint;
29 return (p & (amnt-1u)) == 0u;
32 fn variant_data_is_aligned<A,B>(amnt: uint, u: &a_tag<A,B>) -> bool {
34 &varA(ref a) => is_aligned(amnt, a),
35 &varB(ref b) => is_aligned(amnt, b)
40 let x = mk_rec(22u64, 23u64);
41 assert!(is_aligned(8u, &x.tA));
42 assert!(variant_data_is_aligned(8u, &x.tA));
43 assert!(is_aligned(8u, &x.tB));
44 assert!(variant_data_is_aligned(8u, &x.tB));
46 let x = mk_rec(22u64, 23u32);
47 assert!(is_aligned(8u, &x.tA));
48 assert!(variant_data_is_aligned(8u, &x.tA));
49 assert!(is_aligned(8u, &x.tB));
50 assert!(variant_data_is_aligned(4u, &x.tB));
52 let x = mk_rec(22u32, 23u64);
53 assert!(is_aligned(8u, &x.tA));
54 assert!(variant_data_is_aligned(4u, &x.tA));
55 assert!(is_aligned(8u, &x.tB));
56 assert!(variant_data_is_aligned(8u, &x.tB));
58 let x = mk_rec(22u32, 23u32);
59 assert!(is_aligned(4u, &x.tA));
60 assert!(variant_data_is_aligned(4u, &x.tA));
61 assert!(is_aligned(4u, &x.tB));
62 assert!(variant_data_is_aligned(4u, &x.tB));
64 let x = mk_rec(22f64, 23f64);
65 assert!(is_aligned(8u, &x.tA));
66 assert!(variant_data_is_aligned(8u, &x.tA));
67 assert!(is_aligned(8u, &x.tB));
68 assert!(variant_data_is_aligned(8u, &x.tB));