@@ -578,8 +578,7 @@ impl<T, A: Allocator> Box<T, A> {
578
578
///
579
579
/// This conversion does not allocate on the heap and happens in place.
580
580
#[ 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 > {
583
582
let ( raw, alloc) = Box :: into_raw_with_allocator ( boxed) ;
584
583
unsafe { Box :: from_raw_in ( raw as * mut [ T ; 1 ] , alloc) }
585
584
}
@@ -811,9 +810,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
811
810
/// assert_eq!(*five, 5)
812
811
/// ```
813
812
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
814
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
815
813
#[ inline]
816
- pub const unsafe fn assume_init ( self ) -> Box < T , A > {
814
+ pub unsafe fn assume_init ( self ) -> Box < T , A > {
817
815
let ( raw, alloc) = Box :: into_raw_with_allocator ( self ) ;
818
816
unsafe { Box :: from_raw_in ( raw as * mut T , alloc) }
819
817
}
@@ -846,9 +844,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
846
844
/// }
847
845
/// ```
848
846
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
849
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
850
847
#[ 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 > {
852
849
unsafe {
853
850
( * boxed) . write ( value) ;
854
851
boxed. assume_init ( )
@@ -1092,9 +1089,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
1092
1089
///
1093
1090
/// [memory layout]: self#memory-layout
1094
1091
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
1095
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
1096
1092
#[ 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 ) {
1098
1094
let ( leaked, alloc) = Box :: into_unique ( b) ;
1099
1095
( leaked. as_ptr ( ) , alloc)
1100
1096
}
@@ -1104,10 +1100,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
1104
1100
issue = "none" ,
1105
1101
reason = "use `Box::leak(b).into()` or `Unique::from(Box::leak(b))` instead"
1106
1102
) ]
1107
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
1108
1103
#[ inline]
1109
1104
#[ doc( hidden) ]
1110
- pub const fn into_unique ( b : Self ) -> ( Unique < T > , A ) {
1105
+ pub fn into_unique ( b : Self ) -> ( Unique < T > , A ) {
1111
1106
// Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
1112
1107
// raw pointer for the type system. Turning it directly into a raw pointer would not be
1113
1108
// recognized as "releasing" the unique pointer to permit aliased raw accesses,
@@ -1165,9 +1160,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
1165
1160
/// assert_eq!(*static_ref, [4, 2, 3]);
1166
1161
/// ```
1167
1162
#[ stable( feature = "box_leak" , since = "1.26.0" ) ]
1168
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
1169
1163
#[ inline]
1170
- pub const fn leak < ' a > ( b : Self ) -> & ' a mut T
1164
+ pub fn leak < ' a > ( b : Self ) -> & ' a mut T
1171
1165
where
1172
1166
A : ' a ,
1173
1167
{
@@ -1236,8 +1230,7 @@ impl<T: Default> Default for Box<T> {
1236
1230
1237
1231
#[ cfg( not( no_global_oom_handling) ) ]
1238
1232
#[ 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 ] > {
1241
1234
#[ inline]
1242
1235
fn default ( ) -> Self {
1243
1236
let ptr: Unique < [ T ] > = Unique :: < [ T ; 0 ] > :: dangling ( ) ;
@@ -1247,8 +1240,7 @@ impl<T> const Default for Box<[T]> {
1247
1240
1248
1241
#[ cfg( not( no_global_oom_handling) ) ]
1249
1242
#[ 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 > {
1252
1244
#[ inline]
1253
1245
fn default ( ) -> Self {
1254
1246
// 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> {
1445
1437
}
1446
1438
1447
1439
#[ 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 > >
1450
1441
where
1451
1442
A : ' static ,
1452
1443
{
@@ -1466,9 +1457,36 @@ where
1466
1457
}
1467
1458
}
1468
1459
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
+
1469
1487
#[ cfg( not( no_global_oom_handling) ) ]
1470
1488
#[ 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 ] > {
1472
1490
/// Converts a `&[T]` into a `Box<[T]>`
1473
1491
///
1474
1492
/// This conversion allocates on the heap
@@ -1482,19 +1500,15 @@ impl<T: Copy> From<&[T]> for Box<[T]> {
1482
1500
///
1483
1501
/// println!("{boxed_slice:?}");
1484
1502
/// ```
1503
+ #[ inline]
1485
1504
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)
1492
1506
}
1493
1507
}
1494
1508
1495
1509
#[ cfg( not( no_global_oom_handling) ) ]
1496
1510
#[ 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 ] > {
1498
1512
/// Converts a `Cow<'_, [T]>` into a `Box<[T]>`
1499
1513
///
1500
1514
/// When `cow` is the `Cow::Borrowed` variant, this
@@ -1882,8 +1896,7 @@ impl<T: ?Sized, A: Allocator> fmt::Pointer for Box<T, A> {
1882
1896
}
1883
1897
1884
1898
#[ 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 > {
1887
1900
type Target = T ;
1888
1901
1889
1902
fn deref ( & self ) -> & T {
@@ -1892,8 +1905,7 @@ impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> {
1892
1905
}
1893
1906
1894
1907
#[ 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 > {
1897
1909
fn deref_mut ( & mut self ) -> & mut T {
1898
1910
& mut * * self
1899
1911
}
0 commit comments