@@ -152,15 +152,13 @@ use core::any::Any;
152152use core:: async_iter:: AsyncIterator ;
153153use core:: borrow;
154154use core:: cmp:: Ordering ;
155- use core:: convert:: { From , TryFrom } ;
156155use core:: error:: Error ;
157156use core:: fmt;
158157use core:: future:: Future ;
159158use core:: hash:: { Hash , Hasher } ;
160- #[ cfg( not( no_global_oom_handling) ) ]
161- use core:: iter:: FromIterator ;
162- use core:: iter:: { FusedIterator , Iterator } ;
163- use core:: marker:: { Destruct , Unpin , Unsize } ;
159+ use core:: iter:: FusedIterator ;
160+ use core:: marker:: Tuple ;
161+ use core:: marker:: Unsize ;
164162use core:: mem;
165163use core:: ops:: {
166164 CoerceUnsized , Deref , DerefMut , DispatchFromDyn , Generator , GeneratorState , Receiver ,
@@ -187,7 +185,7 @@ pub use thin::ThinBox;
187185
188186mod thin;
189187
190- /// A pointer type for heap allocation.
188+ /// A pointer type that uniquely owns a heap allocation of type `T` .
191189///
192190/// See the [module-level documentation](../../std/boxed/index.html) for more.
193191#[ lang = "owned_box" ]
@@ -215,6 +213,7 @@ impl<T> Box<T> {
215213 #[ inline( always) ]
216214 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
217215 #[ must_use]
216+ #[ rustc_diagnostic_item = "box_new" ]
218217 pub fn new ( x : T ) -> Self {
219218 #[ rustc_box]
220219 Box :: new ( x)
@@ -284,9 +283,7 @@ impl<T> Box<T> {
284283 #[ must_use]
285284 #[ inline( always) ]
286285 pub fn pin ( x : T ) -> Pin < Box < T > > {
287- ( #[ rustc_box]
288- Box :: new ( x) )
289- . into ( )
286+ Box :: new ( x) . into ( )
290287 }
291288
292289 /// Allocates memory on the heap then places `x` into it,
@@ -378,12 +375,11 @@ impl<T, A: Allocator> Box<T, A> {
378375 /// ```
379376 #[ cfg( not( no_global_oom_handling) ) ]
380377 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
381- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
382378 #[ must_use]
383379 #[ inline]
384- pub const fn new_in ( x : T , alloc : A ) -> Self
380+ pub fn new_in ( x : T , alloc : A ) -> Self
385381 where
386- A : ~ const Allocator + ~ const Destruct ,
382+ A : Allocator ,
387383 {
388384 let mut boxed = Self :: new_uninit_in ( alloc) ;
389385 unsafe {
@@ -408,12 +404,10 @@ impl<T, A: Allocator> Box<T, A> {
408404 /// # Ok::<(), std::alloc::AllocError>(())
409405 /// ```
410406 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
411- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
412407 #[ inline]
413- pub const fn try_new_in ( x : T , alloc : A ) -> Result < Self , AllocError >
408+ pub fn try_new_in ( x : T , alloc : A ) -> Result < Self , AllocError >
414409 where
415- T : ~const Destruct ,
416- A : ~const Allocator + ~const Destruct ,
410+ A : Allocator ,
417411 {
418412 let mut boxed = Self :: try_new_uninit_in ( alloc) ?;
419413 unsafe {
@@ -443,13 +437,12 @@ impl<T, A: Allocator> Box<T, A> {
443437 /// assert_eq!(*five, 5)
444438 /// ```
445439 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
446- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
447440 #[ cfg( not( no_global_oom_handling) ) ]
448441 #[ must_use]
449442 // #[unstable(feature = "new_uninit", issue = "63291")]
450- pub const fn new_uninit_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A >
443+ pub fn new_uninit_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A >
451444 where
452- A : ~ const Allocator + ~ const Destruct ,
445+ A : Allocator ,
453446 {
454447 let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
455448 // NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -484,10 +477,9 @@ impl<T, A: Allocator> Box<T, A> {
484477 /// ```
485478 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
486479 // #[unstable(feature = "new_uninit", issue = "63291")]
487- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
488- pub const fn try_new_uninit_in ( alloc : A ) -> Result < Box < mem:: MaybeUninit < T > , A > , AllocError >
480+ pub fn try_new_uninit_in ( alloc : A ) -> Result < Box < mem:: MaybeUninit < T > , A > , AllocError >
489481 where
490- A : ~ const Allocator + ~ const Destruct ,
482+ A : Allocator ,
491483 {
492484 let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
493485 let ptr = alloc. allocate ( layout) ?. cast ( ) ;
@@ -515,13 +507,12 @@ impl<T, A: Allocator> Box<T, A> {
515507 ///
516508 /// [zeroed]: mem::MaybeUninit::zeroed
517509 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
518- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
519510 #[ cfg( not( no_global_oom_handling) ) ]
520511 // #[unstable(feature = "new_uninit", issue = "63291")]
521512 #[ must_use]
522- pub const fn new_zeroed_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A >
513+ pub fn new_zeroed_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A >
523514 where
524- A : ~ const Allocator + ~ const Destruct ,
515+ A : Allocator ,
525516 {
526517 let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
527518 // NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -556,10 +547,9 @@ impl<T, A: Allocator> Box<T, A> {
556547 /// [zeroed]: mem::MaybeUninit::zeroed
557548 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
558549 // #[unstable(feature = "new_uninit", issue = "63291")]
559- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
560- pub const fn try_new_zeroed_in ( alloc : A ) -> Result < Box < mem:: MaybeUninit < T > , A > , AllocError >
550+ pub fn try_new_zeroed_in ( alloc : A ) -> Result < Box < mem:: MaybeUninit < T > , A > , AllocError >
561551 where
562- A : ~ const Allocator + ~ const Destruct ,
552+ A : Allocator ,
563553 {
564554 let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
565555 let ptr = alloc. allocate_zeroed ( layout) ?. cast ( ) ;
@@ -575,12 +565,11 @@ impl<T, A: Allocator> Box<T, A> {
575565 /// construct a (pinned) `Box` in a different way than with [`Box::new_in`].
576566 #[ cfg( not( no_global_oom_handling) ) ]
577567 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
578- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
579568 #[ must_use]
580569 #[ inline( always) ]
581- pub const fn pin_in ( x : T , alloc : A ) -> Pin < Self >
570+ pub fn pin_in ( x : T , alloc : A ) -> Pin < Self >
582571 where
583- A : ' static + ~ const Allocator + ~ const Destruct ,
572+ A : ' static + Allocator ,
584573 {
585574 Self :: into_pin ( Self :: new_in ( x, alloc) )
586575 }
@@ -607,12 +596,8 @@ impl<T, A: Allocator> Box<T, A> {
607596 /// assert_eq!(Box::into_inner(c), 5);
608597 /// ```
609598 #[ unstable( feature = "box_into_inner" , issue = "80437" ) ]
610- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
611599 #[ inline]
612- pub const fn into_inner ( boxed : Self ) -> T
613- where
614- Self : ~const Destruct ,
615- {
600+ pub fn into_inner ( boxed : Self ) -> T {
616601 * boxed
617602 }
618603}
@@ -954,7 +939,7 @@ impl<T: ?Sized> Box<T> {
954939 /// [`Layout`]: crate::Layout
955940 #[ stable( feature = "box_raw" , since = "1.4.0" ) ]
956941 #[ inline]
957- #[ must_use = "call `drop(from_raw(ptr))` if you intend to drop the `Box`" ]
942+ #[ must_use = "call `drop(Box:: from_raw(ptr))` if you intend to drop the `Box`" ]
958943 pub unsafe fn from_raw ( raw : * mut T ) -> Self {
959944 unsafe { Self :: from_raw_in ( raw, Global ) }
960945 }
@@ -1243,8 +1228,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
12431228#[ stable( feature = "rust1" , since = "1.0.0" ) ]
12441229impl < T : Default > Default for Box < T > {
12451230 /// Creates a `Box<T>`, with the `Default` value for T.
1231+ #[ inline]
12461232 fn default ( ) -> Self {
1247- #[ rustc_box]
12481233 Box :: new ( T :: default ( ) )
12491234 }
12501235}
@@ -1253,6 +1238,7 @@ impl<T: Default> Default for Box<T> {
12531238#[ stable( feature = "rust1" , since = "1.0.0" ) ]
12541239#[ rustc_const_unstable( feature = "const_default_impls" , issue = "87864" ) ]
12551240impl < T > const Default for Box < [ T ] > {
1241+ #[ inline]
12561242 fn default ( ) -> Self {
12571243 let ptr: Unique < [ T ] > = Unique :: < [ T ; 0 ] > :: dangling ( ) ;
12581244 Box ( ptr, Global )
@@ -1263,6 +1249,7 @@ impl<T> const Default for Box<[T]> {
12631249#[ stable( feature = "default_box_extra" , since = "1.17.0" ) ]
12641250#[ rustc_const_unstable( feature = "const_default_impls" , issue = "87864" ) ]
12651251impl const Default for Box < str > {
1252+ #[ inline]
12661253 fn default ( ) -> Self {
12671254 // SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
12681255 let ptr: Unique < str > = unsafe {
@@ -1617,7 +1604,6 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
16171604 /// println!("{boxed:?}");
16181605 /// ```
16191606 fn from ( array : [ T ; N ] ) -> Box < [ T ] > {
1620- #[ rustc_box]
16211607 Box :: new ( array)
16221608 }
16231609}
@@ -1982,7 +1968,7 @@ impl<I: ExactSizeIterator + ?Sized, A: Allocator> ExactSizeIterator for Box<I, A
19821968impl < I : FusedIterator + ?Sized , A : Allocator > FusedIterator for Box < I , A > { }
19831969
19841970#[ stable( feature = "boxed_closure_impls" , since = "1.35.0" ) ]
1985- impl < Args , F : FnOnce < Args > + ?Sized , A : Allocator > FnOnce < Args > for Box < F , A > {
1971+ impl < Args : Tuple , F : FnOnce < Args > + ?Sized , A : Allocator > FnOnce < Args > for Box < F , A > {
19861972 type Output = <F as FnOnce < Args > >:: Output ;
19871973
19881974 extern "rust-call" fn call_once ( self , args : Args ) -> Self :: Output {
@@ -1991,20 +1977,20 @@ impl<Args, F: FnOnce<Args> + ?Sized, A: Allocator> FnOnce<Args> for Box<F, A> {
19911977}
19921978
19931979#[ stable( feature = "boxed_closure_impls" , since = "1.35.0" ) ]
1994- impl < Args , F : FnMut < Args > + ?Sized , A : Allocator > FnMut < Args > for Box < F , A > {
1980+ impl < Args : Tuple , F : FnMut < Args > + ?Sized , A : Allocator > FnMut < Args > for Box < F , A > {
19951981 extern "rust-call" fn call_mut ( & mut self , args : Args ) -> Self :: Output {
19961982 <F as FnMut < Args > >:: call_mut ( self , args)
19971983 }
19981984}
19991985
20001986#[ stable( feature = "boxed_closure_impls" , since = "1.35.0" ) ]
2001- impl < Args , F : Fn < Args > + ?Sized , A : Allocator > Fn < Args > for Box < F , A > {
1987+ impl < Args : Tuple , F : Fn < Args > + ?Sized , A : Allocator > Fn < Args > for Box < F , A > {
20021988 extern "rust-call" fn call ( & self , args : Args ) -> Self :: Output {
20031989 <F as Fn < Args > >:: call ( self , args)
20041990 }
20051991}
20061992
2007- #[ unstable( feature = "coerce_unsized" , issue = "27732 " ) ]
1993+ #[ unstable( feature = "coerce_unsized" , issue = "18598 " ) ]
20081994impl < T : ?Sized + Unsize < U > , U : ?Sized , A : Allocator > CoerceUnsized < Box < U , A > > for Box < T , A > { }
20091995
20101996#[ unstable( feature = "dispatch_from_dyn" , issue = "none" ) ]
0 commit comments