File tree 4 files changed +26
-6
lines changed
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 {
339
339
}
340
340
}
341
341
342
- /// The allocator for unique pointers .
342
+ /// The allocator for `Box` .
343
343
#[ cfg( all( not( no_global_oom_handling) , not( test) ) ) ]
344
344
#[ lang = "exchange_malloc" ]
345
345
#[ inline]
Original file line number Diff line number Diff line change @@ -233,6 +233,27 @@ pub struct Box<
233
233
#[ unstable( feature = "allocator_api" , issue = "32838" ) ] A : Allocator = Global ,
234
234
> ( Unique < T > , A ) ;
235
235
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
+
236
257
impl < T > Box < T > {
237
258
/// Allocates memory on the heap and then places `x` into it.
238
259
///
@@ -250,8 +271,7 @@ impl<T> Box<T> {
250
271
#[ rustc_diagnostic_item = "box_new" ]
251
272
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
252
273
pub fn new ( x : T ) -> Self {
253
- #[ rustc_box]
254
- Box :: new ( x)
274
+ return box_new ( x) ;
255
275
}
256
276
257
277
/// Constructs a new box with uninitialized contents.
Original file line number Diff line number Diff line change 168
168
#![ feature( dropck_eyepatch) ]
169
169
#![ feature( fundamental) ]
170
170
#![ feature( hashmap_internals) ]
171
+ #![ feature( intrinsics) ]
171
172
#![ feature( lang_items) ]
172
173
#![ feature( min_specialization) ]
173
174
#![ feature( multiple_supertrait_upcastable) ]
Original file line number Diff line number Diff line change @@ -48,10 +48,9 @@ macro_rules! vec {
48
48
) ;
49
49
( $( $x: expr) ,+ $( , ) ?) => (
50
50
<[ _] >:: 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
52
52
// time when constructing arrays with many elements.
53
- #[ rustc_box]
54
- $crate:: boxed:: Box :: new( [ $( $x) ,+] )
53
+ $crate:: boxed:: box_new( [ $( $x) ,+] )
55
54
)
56
55
) ;
57
56
}
You can’t perform that action at this time.
0 commit comments