2014-07-04 16:54:23 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
|
|
|
use std::mem::size_of;
|
|
|
|
|
|
|
|
trait Trait {}
|
|
|
|
|
|
|
|
fn main() {
|
2014-11-26 07:12:18 -06:00
|
|
|
// Closures - ||
|
2014-07-04 16:54:23 -05:00
|
|
|
assert_eq!(size_of::<||>(), size_of::<Option<||>>());
|
|
|
|
|
|
|
|
// Functions
|
|
|
|
assert_eq!(size_of::<fn(int)>(), size_of::<Option<fn(int)>>());
|
|
|
|
assert_eq!(size_of::<extern "C" fn(int)>(), size_of::<Option<extern "C" fn(int)>>());
|
|
|
|
|
|
|
|
// Slices - &str / &[T] / &mut [T]
|
|
|
|
assert_eq!(size_of::<&str>(), size_of::<Option<&str>>());
|
|
|
|
assert_eq!(size_of::<&[int]>(), size_of::<Option<&[int]>>());
|
|
|
|
assert_eq!(size_of::<&mut [int]>(), size_of::<Option<&mut [int]>>());
|
|
|
|
|
|
|
|
// Traits - Box<Trait> / &Trait / &mut Trait
|
|
|
|
assert_eq!(size_of::<Box<Trait>>(), size_of::<Option<Box<Trait>>>());
|
|
|
|
assert_eq!(size_of::<&Trait>(), size_of::<Option<&Trait>>());
|
|
|
|
assert_eq!(size_of::<&mut Trait>(), size_of::<Option<&mut Trait>>());
|
|
|
|
|
2014-10-02 00:10:09 -05:00
|
|
|
// Pointers - Box<T>
|
2014-07-04 16:54:23 -05:00
|
|
|
assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>());
|
|
|
|
|
2014-09-11 20:58:01 -05:00
|
|
|
|
|
|
|
// The optimization can't apply to raw pointers
|
|
|
|
assert!(size_of::<Option<*const int>>() != size_of::<*const int>());
|
|
|
|
assert!(Some(0 as *const int).is_some()); // Can't collapse None to null
|
|
|
|
|
2014-07-04 16:54:23 -05:00
|
|
|
}
|