@@ -192,7 +192,25 @@ impl<T> Box<T> {
192
192
/// ```
193
193
/// let five = Box::new(5);
194
194
/// ```
195
- #[ cfg( not( no_global_oom_handling) ) ]
195
+ #[ cfg( all( not( no_global_oom_handling) , not( bootstrap) ) ) ]
196
+ #[ inline( always) ]
197
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
198
+ #[ must_use]
199
+ pub fn new ( x : T ) -> Self {
200
+ #[ rustc_box]
201
+ Box :: new ( x)
202
+ }
203
+
204
+ /// Allocates memory on the heap and then places `x` into it.
205
+ ///
206
+ /// This doesn't actually allocate if `T` is zero-sized.
207
+ ///
208
+ /// # Examples
209
+ ///
210
+ /// ```
211
+ /// let five = Box::new(5);
212
+ /// ```
213
+ #[ cfg( all( not( no_global_oom_handling) , bootstrap) ) ]
196
214
#[ inline( always) ]
197
215
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
198
216
#[ must_use]
@@ -259,7 +277,9 @@ impl<T> Box<T> {
259
277
#[ must_use]
260
278
#[ inline( always) ]
261
279
pub fn pin ( x : T ) -> Pin < Box < T > > {
262
- ( box x) . into ( )
280
+ ( #[ cfg_attr( not( bootstrap) , rustc_box) ]
281
+ Box :: new ( x) )
282
+ . into ( )
263
283
}
264
284
265
285
/// Allocates memory on the heap then places `x` into it,
@@ -1186,7 +1206,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
1186
1206
impl < T : Default > Default for Box < T > {
1187
1207
/// Creates a `Box<T>`, with the `Default` value for T.
1188
1208
fn default ( ) -> Self {
1189
- box T :: default ( )
1209
+ #[ cfg_attr( not( bootstrap) , rustc_box) ]
1210
+ Box :: new ( T :: default ( ) )
1190
1211
}
1191
1212
}
1192
1213
@@ -1550,7 +1571,8 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
1550
1571
/// println!("{boxed:?}");
1551
1572
/// ```
1552
1573
fn from ( array : [ T ; N ] ) -> Box < [ T ] > {
1553
- box array
1574
+ #[ cfg_attr( not( bootstrap) , rustc_box) ]
1575
+ Box :: new ( array)
1554
1576
}
1555
1577
}
1556
1578
0 commit comments