@@ -49,6 +49,15 @@ pub static HEAP: () = ();
49
49
#[ stable]
50
50
pub struct Box < T > ( Unique < T > ) ;
51
51
52
+ #[ unstable]
53
+ impl < T > Box < T > {
54
+ /// Moves `x` into a freshly allocated box on the global exchange heap.
55
+ #[ unstable]
56
+ pub fn new ( x : T ) -> Box < T > {
57
+ box x
58
+ }
59
+ }
60
+
52
61
#[ stable]
53
62
impl < T : Default > Default for Box < T > {
54
63
#[ stable]
@@ -186,36 +195,36 @@ impl<T: ?Sized> DerefMut for Box<T> {
186
195
mod test {
187
196
#[ test]
188
197
fn test_owned_clone ( ) {
189
- let a = box 5 i ;
198
+ let a = Box :: new ( 5 i ) ;
190
199
let b: Box < int > = a. clone ( ) ;
191
200
assert ! ( a == b) ;
192
201
}
193
202
194
203
#[ test]
195
204
fn any_move ( ) {
196
- let a = box 8 u as Box < Any > ;
197
- let b = box Test as Box < Any > ;
205
+ let a = Box :: new ( 8 u ) as Box < Any > ;
206
+ let b = Box :: new ( Test ) as Box < Any > ;
198
207
199
208
match a. downcast :: < uint > ( ) {
200
- Ok ( a) => { assert ! ( a == box 8 u ) ; }
209
+ Ok ( a) => { assert ! ( a == Box :: new ( 8 u ) ) ; }
201
210
Err ( ..) => panic ! ( )
202
211
}
203
212
match b. downcast :: < Test > ( ) {
204
- Ok ( a) => { assert ! ( a == box Test ) ; }
213
+ Ok ( a) => { assert ! ( a == Box :: new ( Test ) ) ; }
205
214
Err ( ..) => panic ! ( )
206
215
}
207
216
208
- let a = box 8 u as Box < Any > ;
209
- let b = box Test as Box < Any > ;
217
+ let a = Box :: new ( 8 u ) as Box < Any > ;
218
+ let b = Box :: new ( Test ) as Box < Any > ;
210
219
211
220
assert ! ( a. downcast:: <Box <Test >>( ) . is_err( ) ) ;
212
221
assert ! ( b. downcast:: <Box <uint>>( ) . is_err( ) ) ;
213
222
}
214
223
215
224
#[ test]
216
225
fn test_show ( ) {
217
- let a = box 8 u as Box < Any > ;
218
- let b = box Test as Box < Any > ;
226
+ let a = Box :: new ( 8 u ) as Box < Any > ;
227
+ let b = Box :: new ( Test ) as Box < Any > ;
219
228
let a_str = a. to_str ( ) ;
220
229
let b_str = b. to_str ( ) ;
221
230
assert_eq ! ( a_str, "Box<Any>" ) ;
@@ -232,6 +241,6 @@ mod test {
232
241
#[ test]
233
242
fn deref ( ) {
234
243
fn homura < T : Deref < Target =i32 > > ( _: T ) { }
235
- homura ( box 765i32 ) ;
244
+ homura ( Box :: new ( 765i32 ) ) ;
236
245
}
237
246
}
0 commit comments