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.
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.
12 use std::mem::size_of;
18 assert_eq!(size_of::<||>(), size_of::<Option<||>>());
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)>>());
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]>>());
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>>());
35 assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>());
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