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>(), 1);
16 assert_eq!(size_of::<u16>(), 2);
17 assert_eq!(size_of::<u32>(), 4);
18 assert_eq!(size_of::<u64>(), 8);
22 #[cfg(target_pointer_width = "32")]
24 assert_eq!(size_of::<uint>(), 4);
25 assert_eq!(size_of::<*const uint>(), 4);
29 #[cfg(target_pointer_width = "64")]
31 assert_eq!(size_of::<uint>(), 8);
32 assert_eq!(size_of::<*const uint>(), 8);
36 fn size_of_val_basic() {
37 assert_eq!(size_of_val(&1u8), 1);
38 assert_eq!(size_of_val(&1u16), 2);
39 assert_eq!(size_of_val(&1u32), 4);
40 assert_eq!(size_of_val(&1u64), 8);
45 assert_eq!(align_of::<u8>(), 1);
46 assert_eq!(align_of::<u16>(), 2);
47 assert_eq!(align_of::<u32>(), 4);
51 #[cfg(target_pointer_width = "32")]
53 assert_eq!(align_of::<uint>(), 4);
54 assert_eq!(align_of::<*const uint>(), 4);
58 #[cfg(target_pointer_width = "64")]
60 assert_eq!(align_of::<uint>(), 8);
61 assert_eq!(align_of::<*const uint>(), 8);
65 fn align_of_val_basic() {
66 assert_eq!(align_of_val(&1u8), 1);
67 assert_eq!(align_of_val(&1u16), 2);
68 assert_eq!(align_of_val(&1u32), 4);
82 let mut x = Some("test".to_string());
83 let y = replace(&mut x, None);
89 fn test_transmute_copy() {
90 assert_eq!(1, unsafe { transmute_copy(&1) });
98 let a = box 100 as Box<Foo>;
100 let x: ::core::raw::TraitObject = transmute(a);
101 assert!(*(x.data as *const int) == 100);
102 let _x: Box<Foo> = transmute(x);
106 assert!(vec![76u8] == transmute::<_, Vec<u8>>("L".to_string()));
110 // FIXME #13642 (these benchmarks should be in another place)
111 /// Completely miscellaneous language-construct benchmarks.
112 // Static/dynamic method dispatch
119 fn method(&self) -> int;
122 impl Trait for Struct {
123 fn method(&self) -> int {
129 fn trait_vtable_method_call(b: &mut Bencher) {
130 let s = Struct { field: 10 };
131 let t = &s as &Trait;
138 fn trait_static_method_call(b: &mut Bencher) {
139 let s = Struct { field: 10 };
145 // Overhead of various match forms
148 fn match_option_some(b: &mut Bencher) {
159 fn match_vec_pattern(b: &mut Bencher) {
160 let x = [1,2,3,4,5,6];