]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/enum-null-pointer-opt.rs
Merge branch 'master' into cfg_tmp_dir
[rust.git] / src / test / run-pass / enum-null-pointer-opt.rs
1 // Copyright 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.
4 //
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.
10
11
12 use std::mem::size_of;
13
14 trait Trait {}
15
16 fn main() {
17     // Closures - ||
18     assert_eq!(size_of::<||>(), size_of::<Option<||>>());
19
20     // Functions
21     assert_eq!(size_of::<fn(int)>(), size_of::<Option<fn(int)>>());
22     assert_eq!(size_of::<extern "C" fn(int)>(), size_of::<Option<extern "C" fn(int)>>());
23
24     // Slices - &str / &[T] / &mut [T]
25     assert_eq!(size_of::<&str>(), size_of::<Option<&str>>());
26     assert_eq!(size_of::<&[int]>(), size_of::<Option<&[int]>>());
27     assert_eq!(size_of::<&mut [int]>(), size_of::<Option<&mut [int]>>());
28
29     // Traits - Box<Trait> / &Trait / &mut Trait
30     assert_eq!(size_of::<Box<Trait>>(), size_of::<Option<Box<Trait>>>());
31     assert_eq!(size_of::<&Trait>(), size_of::<Option<&Trait>>());
32     assert_eq!(size_of::<&mut Trait>(), size_of::<Option<&mut Trait>>());
33
34     // Pointers - Box<T>
35     assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>());
36
37
38     // The optimization can't apply to raw pointers
39     assert!(size_of::<Option<*const int>>() != size_of::<*const int>());
40     assert!(Some(0 as *const int).is_some()); // Can't collapse None to null
41
42 }