@@ -578,8 +578,7 @@ impl<T, A: Allocator> Box<T, A> {
578578 ///
579579 /// This conversion does not allocate on the heap and happens in place.
580580 #[ unstable( feature = "box_into_boxed_slice" , issue = "71582" ) ]
581- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
582- pub const fn into_boxed_slice ( boxed : Self ) -> Box < [ T ] , A > {
581+ pub fn into_boxed_slice ( boxed : Self ) -> Box < [ T ] , A > {
583582 let ( raw, alloc) = Box :: into_raw_with_allocator ( boxed) ;
584583 unsafe { Box :: from_raw_in ( raw as * mut [ T ; 1 ] , alloc) }
585584 }
@@ -811,9 +810,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
811810 /// assert_eq!(*five, 5)
812811 /// ```
813812 #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
814- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
815813 #[ inline]
816- pub const unsafe fn assume_init ( self ) -> Box < T , A > {
814+ pub unsafe fn assume_init ( self ) -> Box < T , A > {
817815 let ( raw, alloc) = Box :: into_raw_with_allocator ( self ) ;
818816 unsafe { Box :: from_raw_in ( raw as * mut T , alloc) }
819817 }
@@ -846,9 +844,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
846844 /// }
847845 /// ```
848846 #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
849- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
850847 #[ inline]
851- pub const fn write ( mut boxed : Self , value : T ) -> Box < T , A > {
848+ pub fn write ( mut boxed : Self , value : T ) -> Box < T , A > {
852849 unsafe {
853850 ( * boxed) . write ( value) ;
854851 boxed. assume_init ( )
@@ -1092,9 +1089,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
10921089 ///
10931090 /// [memory layout]: self#memory-layout
10941091 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
1095- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
10961092 #[ inline]
1097- pub const fn into_raw_with_allocator ( b : Self ) -> ( * mut T , A ) {
1093+ pub fn into_raw_with_allocator ( b : Self ) -> ( * mut T , A ) {
10981094 let ( leaked, alloc) = Box :: into_unique ( b) ;
10991095 ( leaked. as_ptr ( ) , alloc)
11001096 }
@@ -1104,10 +1100,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11041100 issue = "none" ,
11051101 reason = "use `Box::leak(b).into()` or `Unique::from(Box::leak(b))` instead"
11061102 ) ]
1107- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
11081103 #[ inline]
11091104 #[ doc( hidden) ]
1110- pub const fn into_unique ( b : Self ) -> ( Unique < T > , A ) {
1105+ pub fn into_unique ( b : Self ) -> ( Unique < T > , A ) {
11111106 // Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
11121107 // raw pointer for the type system. Turning it directly into a raw pointer would not be
11131108 // recognized as "releasing" the unique pointer to permit aliased raw accesses,
@@ -1165,9 +1160,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11651160 /// assert_eq!(*static_ref, [4, 2, 3]);
11661161 /// ```
11671162 #[ stable( feature = "box_leak" , since = "1.26.0" ) ]
1168- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
11691163 #[ inline]
1170- pub const fn leak < ' a > ( b : Self ) -> & ' a mut T
1164+ pub fn leak < ' a > ( b : Self ) -> & ' a mut T
11711165 where
11721166 A : ' a ,
11731167 {
@@ -1236,8 +1230,7 @@ impl<T: Default> Default for Box<T> {
12361230
12371231#[ cfg( not( no_global_oom_handling) ) ]
12381232#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1239- #[ rustc_const_unstable( feature = "const_default_impls" , issue = "87864" ) ]
1240- impl < T > const Default for Box < [ T ] > {
1233+ impl < T > Default for Box < [ T ] > {
12411234 #[ inline]
12421235 fn default ( ) -> Self {
12431236 let ptr: Unique < [ T ] > = Unique :: < [ T ; 0 ] > :: dangling ( ) ;
@@ -1247,8 +1240,7 @@ impl<T> const Default for Box<[T]> {
12471240
12481241#[ cfg( not( no_global_oom_handling) ) ]
12491242#[ stable( feature = "default_box_extra" , since = "1.17.0" ) ]
1250- #[ rustc_const_unstable( feature = "const_default_impls" , issue = "87864" ) ]
1251- impl const Default for Box < str > {
1243+ impl Default for Box < str > {
12521244 #[ inline]
12531245 fn default ( ) -> Self {
12541246 // SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
@@ -1445,8 +1437,7 @@ impl<T> From<T> for Box<T> {
14451437}
14461438
14471439#[ stable( feature = "pin" , since = "1.33.0" ) ]
1448- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
1449- impl < T : ?Sized , A : Allocator > const From < Box < T , A > > for Pin < Box < T , A > >
1440+ impl < T : ?Sized , A : Allocator > From < Box < T , A > > for Pin < Box < T , A > >
14501441where
14511442 A : ' static ,
14521443{
@@ -1466,9 +1457,36 @@ where
14661457 }
14671458}
14681459
1460+ /// Specialization trait used for `From<&[T]>`.
1461+ #[ cfg( not( no_global_oom_handling) ) ]
1462+ trait BoxFromSlice < T > {
1463+ fn from_slice ( slice : & [ T ] ) -> Self ;
1464+ }
1465+
1466+ #[ cfg( not( no_global_oom_handling) ) ]
1467+ impl < T : Clone > BoxFromSlice < T > for Box < [ T ] > {
1468+ #[ inline]
1469+ default fn from_slice ( slice : & [ T ] ) -> Self {
1470+ slice. to_vec ( ) . into_boxed_slice ( )
1471+ }
1472+ }
1473+
1474+ #[ cfg( not( no_global_oom_handling) ) ]
1475+ impl < T : Copy > BoxFromSlice < T > for Box < [ T ] > {
1476+ #[ inline]
1477+ fn from_slice ( slice : & [ T ] ) -> Self {
1478+ let len = slice. len ( ) ;
1479+ let buf = RawVec :: with_capacity ( len) ;
1480+ unsafe {
1481+ ptr:: copy_nonoverlapping ( slice. as_ptr ( ) , buf. ptr ( ) , len) ;
1482+ buf. into_box ( slice. len ( ) ) . assume_init ( )
1483+ }
1484+ }
1485+ }
1486+
14691487#[ cfg( not( no_global_oom_handling) ) ]
14701488#[ stable( feature = "box_from_slice" , since = "1.17.0" ) ]
1471- impl < T : Copy > From < & [ T ] > for Box < [ T ] > {
1489+ impl < T : Clone > From < & [ T ] > for Box < [ T ] > {
14721490 /// Converts a `&[T]` into a `Box<[T]>`
14731491 ///
14741492 /// This conversion allocates on the heap
@@ -1482,19 +1500,15 @@ impl<T: Copy> From<&[T]> for Box<[T]> {
14821500 ///
14831501 /// println!("{boxed_slice:?}");
14841502 /// ```
1503+ #[ inline]
14851504 fn from ( slice : & [ T ] ) -> Box < [ T ] > {
1486- let len = slice. len ( ) ;
1487- let buf = RawVec :: with_capacity ( len) ;
1488- unsafe {
1489- ptr:: copy_nonoverlapping ( slice. as_ptr ( ) , buf. ptr ( ) , len) ;
1490- buf. into_box ( slice. len ( ) ) . assume_init ( )
1491- }
1505+ <Self as BoxFromSlice < T > >:: from_slice ( slice)
14921506 }
14931507}
14941508
14951509#[ cfg( not( no_global_oom_handling) ) ]
14961510#[ stable( feature = "box_from_cow" , since = "1.45.0" ) ]
1497- impl < T : Copy > From < Cow < ' _ , [ T ] > > for Box < [ T ] > {
1511+ impl < T : Clone > From < Cow < ' _ , [ T ] > > for Box < [ T ] > {
14981512 /// Converts a `Cow<'_, [T]>` into a `Box<[T]>`
14991513 ///
15001514 /// When `cow` is the `Cow::Borrowed` variant, this
@@ -1882,8 +1896,7 @@ impl<T: ?Sized, A: Allocator> fmt::Pointer for Box<T, A> {
18821896}
18831897
18841898#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1885- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
1886- impl < T : ?Sized , A : Allocator > const Deref for Box < T , A > {
1899+ impl < T : ?Sized , A : Allocator > Deref for Box < T , A > {
18871900 type Target = T ;
18881901
18891902 fn deref ( & self ) -> & T {
@@ -1892,8 +1905,7 @@ impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> {
18921905}
18931906
18941907#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1895- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
1896- impl < T : ?Sized , A : Allocator > const DerefMut for Box < T , A > {
1908+ impl < T : ?Sized , A : Allocator > DerefMut for Box < T , A > {
18971909 fn deref_mut ( & mut self ) -> & mut T {
18981910 & mut * * self
18991911 }
0 commit comments