|
| 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::gc::Gc; |
| 13 | +use std::mem::size_of; |
| 14 | + |
| 15 | +trait Trait {} |
| 16 | + |
| 17 | +fn main() { |
| 18 | + // Closures - || / proc() |
| 19 | + assert_eq!(size_of::<proc()>(), size_of::<Option<proc()>>()); |
| 20 | + assert_eq!(size_of::<||>(), size_of::<Option<||>>()); |
| 21 | + |
| 22 | + // Functions |
| 23 | + assert_eq!(size_of::<fn(int)>(), size_of::<Option<fn(int)>>()); |
| 24 | + assert_eq!(size_of::<extern "C" fn(int)>(), size_of::<Option<extern "C" fn(int)>>()); |
| 25 | + |
| 26 | + // Slices - &str / &[T] / &mut [T] |
| 27 | + assert_eq!(size_of::<&str>(), size_of::<Option<&str>>()); |
| 28 | + assert_eq!(size_of::<&[int]>(), size_of::<Option<&[int]>>()); |
| 29 | + assert_eq!(size_of::<&mut [int]>(), size_of::<Option<&mut [int]>>()); |
| 30 | + |
| 31 | + // Traits - Box<Trait> / &Trait / &mut Trait |
| 32 | + assert_eq!(size_of::<Box<Trait>>(), size_of::<Option<Box<Trait>>>()); |
| 33 | + assert_eq!(size_of::<&Trait>(), size_of::<Option<&Trait>>()); |
| 34 | + assert_eq!(size_of::<&mut Trait>(), size_of::<Option<&mut Trait>>()); |
| 35 | + |
| 36 | + // Pointers - Box<T> / Gc<T> |
| 37 | + assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>()); |
| 38 | + assert_eq!(size_of::<Gc<int>>(), size_of::<Option<Gc<int>>>()); |
| 39 | + |
| 40 | +} |
0 commit comments