1 // Copyright 2014-2015 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.
15 assert_eq!(size_of::<u8>(), 1u);
16 assert_eq!(size_of::<u16>(), 2u);
17 assert_eq!(size_of::<u32>(), 4u);
18 assert_eq!(size_of::<u64>(), 8u);
22 #[cfg(any(target_arch = "x86",
25 target_arch = "mipsel"))]
27 assert_eq!(size_of::<uint>(), 4u);
28 assert_eq!(size_of::<*const uint>(), 4u);
32 #[cfg(any(target_arch = "x86_64",
33 target_arch = "aarch64"))]
35 assert_eq!(size_of::<uint>(), 8u);
36 assert_eq!(size_of::<*const uint>(), 8u);
40 fn size_of_val_basic() {
41 assert_eq!(size_of_val(&1u8), 1);
42 assert_eq!(size_of_val(&1u16), 2);
43 assert_eq!(size_of_val(&1u32), 4);
44 assert_eq!(size_of_val(&1u64), 8);
49 assert_eq!(align_of::<u8>(), 1u);
50 assert_eq!(align_of::<u16>(), 2u);
51 assert_eq!(align_of::<u32>(), 4u);
55 #[cfg(any(target_arch = "x86",
58 target_arch = "mipsel"))]
60 assert_eq!(align_of::<uint>(), 4u);
61 assert_eq!(align_of::<*const uint>(), 4u);
65 #[cfg(any(target_arch = "x86_64",
66 target_arch = "aarch64"))]
68 assert_eq!(align_of::<uint>(), 8u);
69 assert_eq!(align_of::<*const uint>(), 8u);
73 fn align_of_val_basic() {
74 assert_eq!(align_of_val(&1u8), 1u);
75 assert_eq!(align_of_val(&1u16), 2u);
76 assert_eq!(align_of_val(&1u32), 4u);
90 let mut x = Some("test".to_string());
91 let y = replace(&mut x, None);
97 fn test_transmute_copy() {
98 assert_eq!(1u, unsafe { transmute_copy(&1i) });
102 fn test_transmute() {
106 let a = box 100i as Box<Foo>;
108 let x: ::core::raw::TraitObject = transmute(a);
109 assert!(*(x.data as *const int) == 100);
110 let _x: Box<Foo> = transmute(x);
114 assert!(vec![76u8] == transmute::<_, Vec<u8>>("L".to_string()));
118 // FIXME #13642 (these benchmarks should be in another place)
119 /// Completely miscellaneous language-construct benchmarks.
120 // Static/dynamic method dispatch
127 fn method(&self) -> int;
130 impl Trait for Struct {
131 fn method(&self) -> int {
137 fn trait_vtable_method_call(b: &mut Bencher) {
138 let s = Struct { field: 10 };
139 let t = &s as &Trait;
146 fn trait_static_method_call(b: &mut Bencher) {
147 let s = Struct { field: 10 };
153 // Overhead of various match forms
156 fn match_option_some(b: &mut Bencher) {
167 fn match_vec_pattern(b: &mut Bencher) {
168 let x = [1i,2,3,4,5,6];