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 = "16")]
24 assert_eq
!(size_of
::<usize>(), 2);
25 assert_eq
!(size_of
::<*const usize>(), 2);
29 #[cfg(target_pointer_width = "32")]
31 assert_eq
!(size_of
::<usize>(), 4);
32 assert_eq
!(size_of
::<*const usize>(), 4);
36 #[cfg(target_pointer_width = "64")]
38 assert_eq
!(size_of
::<usize>(), 8);
39 assert_eq
!(size_of
::<*const usize>(), 8);
43 fn size_of_val_basic() {
44 assert_eq
!(size_of_val(&1u8), 1);
45 assert_eq
!(size_of_val(&1u16), 2);
46 assert_eq
!(size_of_val(&1u32), 4);
47 assert_eq
!(size_of_val(&1u64), 8);
52 assert_eq
!(align_of
::<u8>(), 1);
53 assert_eq
!(align_of
::<u16>(), 2);
54 assert_eq
!(align_of
::<u32>(), 4);
58 #[cfg(target_pointer_width = "16")]
60 assert_eq
!(align_of
::<usize>(), 2);
61 assert_eq
!(align_of
::<*const usize>(), 2);
65 #[cfg(target_pointer_width = "32")]
67 assert_eq
!(align_of
::<usize>(), 4);
68 assert_eq
!(align_of
::<*const usize>(), 4);
72 #[cfg(target_pointer_width = "64")]
74 assert_eq
!(align_of
::<usize>(), 8);
75 assert_eq
!(align_of
::<*const usize>(), 8);
79 fn align_of_val_basic() {
80 assert_eq
!(align_of_val(&1u8), 1);
81 assert_eq
!(align_of_val(&1u16), 2);
82 assert_eq
!(align_of_val(&1u32), 4);
96 let mut x
= Some("test".to_string());
97 let y
= replace(&mut x
, None
);
103 fn test_transmute_copy() {
104 assert_eq
!(1, unsafe { transmute_copy(&1) }
);
108 fn test_transmute() {
109 trait Foo { fn dummy(&self) { }
}
110 impl Foo
for isize {}
112 let a
= box 100isize
as Box
<Foo
>;
114 let x
: ::core
::raw
::TraitObject
= transmute(a
);
115 assert
!(*(x
.data
as *const isize) == 100);
116 let _x
: Box
<Foo
> = transmute(x
);
120 assert_eq
!(transmute
::<_
, Vec
<u8>>("L".to_string()), [76]);
126 fn test_discriminant_send_sync() {
135 fn is_send_sync
<T
: Send
+ Sync
>() { }
137 is_send_sync
::<Discriminant
<Regular
>>();
138 is_send_sync
::<Discriminant
<NotSendSync
>>();