@@ -192,7 +192,25 @@ impl<T> Box<T> {
192192 /// ```
193193 /// let five = Box::new(5);
194194 /// ```
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) ) ]
196214 #[ inline( always) ]
197215 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
198216 #[ must_use]
@@ -259,7 +277,9 @@ impl<T> Box<T> {
259277 #[ must_use]
260278 #[ inline( always) ]
261279 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 ( )
263283 }
264284
265285 /// 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> {
11861206impl < T : Default > Default for Box < T > {
11871207 /// Creates a `Box<T>`, with the `Default` value for T.
11881208 fn default ( ) -> Self {
1189- box T :: default ( )
1209+ #[ cfg_attr( not( bootstrap) , rustc_box) ]
1210+ Box :: new ( T :: default ( ) )
11901211 }
11911212}
11921213
@@ -1550,7 +1571,8 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
15501571 /// println!("{boxed:?}");
15511572 /// ```
15521573 fn from ( array : [ T ; N ] ) -> Box < [ T ] > {
1553- box array
1574+ #[ cfg_attr( not( bootstrap) , rustc_box) ]
1575+ Box :: new ( array)
15541576 }
15551577}
15561578
0 commit comments