@@ -49,6 +49,15 @@ pub static HEAP: () = ();
4949#[ stable]
5050pub struct Box < T > ( Unique < T > ) ;
5151
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+
5261#[ stable]
5362impl < T : Default > Default for Box < T > {
5463 #[ stable]
@@ -186,36 +195,36 @@ impl<T: ?Sized> DerefMut for Box<T> {
186195mod test {
187196 #[ test]
188197 fn test_owned_clone ( ) {
189- let a = box 5 i ;
198+ let a = Box :: new ( 5 i ) ;
190199 let b: Box < int > = a. clone ( ) ;
191200 assert ! ( a == b) ;
192201 }
193202
194203 #[ test]
195204 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 > ;
198207
199208 match a. downcast :: < uint > ( ) {
200- Ok ( a) => { assert ! ( a == box 8 u ) ; }
209+ Ok ( a) => { assert ! ( a == Box :: new ( 8 u ) ) ; }
201210 Err ( ..) => panic ! ( )
202211 }
203212 match b. downcast :: < Test > ( ) {
204- Ok ( a) => { assert ! ( a == box Test ) ; }
213+ Ok ( a) => { assert ! ( a == Box :: new ( Test ) ) ; }
205214 Err ( ..) => panic ! ( )
206215 }
207216
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 > ;
210219
211220 assert ! ( a. downcast:: <Box <Test >>( ) . is_err( ) ) ;
212221 assert ! ( b. downcast:: <Box <uint>>( ) . is_err( ) ) ;
213222 }
214223
215224 #[ test]
216225 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 > ;
219228 let a_str = a. to_str ( ) ;
220229 let b_str = b. to_str ( ) ;
221230 assert_eq ! ( a_str, "Box<Any>" ) ;
@@ -232,6 +241,6 @@ mod test {
232241 #[ test]
233242 fn deref ( ) {
234243 fn homura < T : Deref < Target =i32 > > ( _: T ) { }
235- homura ( box 765i32 ) ;
244+ homura ( Box :: new ( 765i32 ) ) ;
236245 }
237246}
0 commit comments