File tree Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -339,7 +339,7 @@ unsafe impl Allocator for Global {
339339 }
340340}
341341
342- /// The allocator for unique pointers .
342+ /// The allocator for `Box` .
343343#[ cfg( all( not( no_global_oom_handling) , not( test) ) ) ]
344344#[ lang = "exchange_malloc" ]
345345#[ inline]
Original file line number Diff line number Diff line change @@ -233,6 +233,27 @@ pub struct Box<
233233 #[ unstable( feature = "allocator_api" , issue = "32838" ) ] A : Allocator = Global ,
234234> ( Unique < T > , A ) ;
235235
236+ /// Constructs a `Box<T>` by calling the `exchange_malloc` lang item and moving the argument into
237+ /// the newly allocated memory. This is an intrinsic to avoid unnecessary copies.
238+ ///
239+ /// This is the surface syntax for `box <expr>` expressions.
240+ #[ cfg( not( bootstrap) ) ]
241+ #[ rustc_intrinsic]
242+ #[ rustc_intrinsic_must_be_overridden]
243+ #[ unstable( feature = "liballoc_internals" , issue = "none" ) ]
244+ pub fn box_new < T > ( _x : T ) -> Box < T > {
245+ unreachable ! ( )
246+ }
247+
248+ /// Transition function for the next bootstrap bump.
249+ #[ cfg( bootstrap) ]
250+ #[ unstable( feature = "liballoc_internals" , issue = "none" ) ]
251+ #[ inline( always) ]
252+ pub fn box_new < T > ( x : T ) -> Box < T > {
253+ #[ rustc_box]
254+ Box :: new ( x)
255+ }
256+
236257impl < T > Box < T > {
237258 /// Allocates memory on the heap and then places `x` into it.
238259 ///
@@ -250,8 +271,7 @@ impl<T> Box<T> {
250271 #[ rustc_diagnostic_item = "box_new" ]
251272 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
252273 pub fn new ( x : T ) -> Self {
253- #[ rustc_box]
254- Box :: new ( x)
274+ return box_new ( x) ;
255275 }
256276
257277 /// Constructs a new box with uninitialized contents.
Original file line number Diff line number Diff line change 168168#![ feature( dropck_eyepatch) ]
169169#![ feature( fundamental) ]
170170#![ feature( hashmap_internals) ]
171+ #![ feature( intrinsics) ]
171172#![ feature( lang_items) ]
172173#![ feature( min_specialization) ]
173174#![ feature( multiple_supertrait_upcastable) ]
Original file line number Diff line number Diff line change @@ -48,10 +48,9 @@ macro_rules! vec {
4848 ) ;
4949 ( $( $x: expr) ,+ $( , ) ?) => (
5050 <[ _] >:: into_vec(
51- // This rustc_box is not required, but it produces a dramatic improvement in compile
51+ // Using the intrinsic produces a dramatic improvement in compile
5252 // time when constructing arrays with many elements.
53- #[ rustc_box]
54- $crate:: boxed:: Box :: new( [ $( $x) ,+] )
53+ $crate:: boxed:: box_new( [ $( $x) ,+] )
5554 )
5655 ) ;
5756}
You can’t perform that action at this time.
0 commit comments