diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-07 17:42:47 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-07 17:42:47 -0800 |
| commit | 373cbab5b08d6630da58f28d2166c19afc327fa6 (patch) | |
| tree | 860d19575778256a9345ce33d5eeef6b54f91300 /src/liballoc | |
| parent | d11bfba71bb71e05ab93e1576a07a48269b13021 (diff) | |
| parent | ae4bcd41e8014b6057fe0a328c87f32f917396ba (diff) | |
| download | rust-373cbab5b08d6630da58f28d2166c19afc327fa6.tar.gz rust-373cbab5b08d6630da58f28d2166c19afc327fa6.zip | |
rollup merge of #20723: pnkfelix/feature-gate-box-syntax
Conflicts: src/compiletest/compiletest.rs src/libcollections/lib.rs src/libserialize/lib.rs src/libsyntax/feature_gate.rs
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 29 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 1 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index b42337a8982..fdc3b52c4d3 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -49,6 +49,15 @@ pub static HEAP: () = (); #[stable] pub struct Box<T>(Unique<T>); +#[unstable] +impl<T> Box<T> { + /// Moves `x` into a freshly allocated box on the global exchange heap. + #[unstable] + pub fn new(x: T) -> Box<T> { + box x + } +} + #[stable] impl<T: Default> Default for Box<T> { #[stable] @@ -186,27 +195,27 @@ impl<T: ?Sized> DerefMut for Box<T> { mod test { #[test] fn test_owned_clone() { - let a = box 5i; + let a = Box::new(5i); let b: Box<int> = a.clone(); assert!(a == b); } #[test] fn any_move() { - let a = box 8u as Box<Any>; - let b = box Test as Box<Any>; + let a = Box::new(8u) as Box<Any>; + let b = Box::new(Test) as Box<Any>; match a.downcast::<uint>() { - Ok(a) => { assert!(a == box 8u); } + Ok(a) => { assert!(a == Box::new(8u)); } Err(..) => panic!() } match b.downcast::<Test>() { - Ok(a) => { assert!(a == box Test); } + Ok(a) => { assert!(a == Box::new(Test)); } Err(..) => panic!() } - let a = box 8u as Box<Any>; - let b = box Test as Box<Any>; + let a = Box::new(8u) as Box<Any>; + let b = Box::new(Test) as Box<Any>; assert!(a.downcast::<Box<Test>>().is_err()); assert!(b.downcast::<Box<uint>>().is_err()); @@ -214,8 +223,8 @@ mod test { #[test] fn test_show() { - let a = box 8u as Box<Any>; - let b = box Test as Box<Any>; + let a = Box::new(8u) as Box<Any>; + let b = Box::new(Test) as Box<Any>; let a_str = a.to_str(); let b_str = b.to_str(); assert_eq!(a_str, "Box<Any>"); @@ -232,6 +241,6 @@ mod test { #[test] fn deref() { fn homura<T: Deref<Target=i32>>(_: T) { } - homura(box 765i32); + homura(Box::new(765i32)); } } diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index dc6037c3c0c..0bb8ba669ec 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -67,6 +67,7 @@ #![no_std] #![allow(unknown_features)] #![feature(lang_items, unsafe_destructor)] +#![feature(box_syntax)] #[macro_use] extern crate core; |
