Skip to content

Commit

Permalink
Add tests for null pointer opt.
Browse files Browse the repository at this point in the history
  • Loading branch information
luqmana committed Jul 4, 2014
1 parent 31570cb commit f48cc74
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/test/run-pass/enum-null-pointer-opt.rs
@@ -0,0 +1,40 @@
// 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::gc::Gc;
use std::mem::size_of;

trait Trait {}

fn main() {
// Closures - || / proc()
assert_eq!(size_of::<proc()>(), size_of::<Option<proc()>>());
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>>());

// Pointers - Box<T> / Gc<T>
assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>());
assert_eq!(size_of::<Gc<int>>(), size_of::<Option<Gc<int>>>());

}

0 comments on commit f48cc74

Please sign in to comment.