@@ -165,6 +165,11 @@ use crate::str::from_boxed_utf8_unchecked;
165
165
#[ cfg( not( no_global_oom_handling) ) ]
166
166
use crate :: vec:: Vec ;
167
167
168
+ #[ unstable( feature = "thin_box" , issue = "92791" ) ]
169
+ pub use thin:: ThinBox ;
170
+
171
+ mod thin;
172
+
168
173
/// A pointer type for heap allocation.
169
174
///
170
175
/// See the [module-level documentation](../../std/boxed/index.html) for more.
@@ -351,10 +356,9 @@ impl<T, A: Allocator> Box<T, A> {
351
356
#[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
352
357
#[ must_use]
353
358
#[ inline]
354
- #[ cfg_attr( not( bootstrap) , allow( drop_bounds) ) ] // FIXME remove `~const Drop` and this attr when bumping
355
359
pub const fn new_in ( x : T , alloc : A ) -> Self
356
360
where
357
- A : ~const Allocator + ~const Drop + ~ const Destruct ,
361
+ A : ~const Allocator + ~const Destruct ,
358
362
{
359
363
let mut boxed = Self :: new_uninit_in ( alloc) ;
360
364
unsafe {
@@ -381,11 +385,10 @@ impl<T, A: Allocator> Box<T, A> {
381
385
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
382
386
#[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
383
387
#[ inline]
384
- #[ cfg_attr( not( bootstrap) , allow( drop_bounds) ) ] // FIXME remove `~const Drop` and this attr when bumping
385
388
pub const fn try_new_in ( x : T , alloc : A ) -> Result < Self , AllocError >
386
389
where
387
- T : ~const Drop + ~ const Destruct ,
388
- A : ~const Allocator + ~const Drop + ~ const Destruct ,
390
+ T : ~const Destruct ,
391
+ A : ~const Allocator + ~const Destruct ,
389
392
{
390
393
let mut boxed = Self :: try_new_uninit_in ( alloc) ?;
391
394
unsafe {
@@ -419,10 +422,9 @@ impl<T, A: Allocator> Box<T, A> {
419
422
#[ cfg( not( no_global_oom_handling) ) ]
420
423
#[ must_use]
421
424
// #[unstable(feature = "new_uninit", issue = "63291")]
422
- #[ cfg_attr( not( bootstrap) , allow( drop_bounds) ) ] // FIXME remove `~const Drop` and this attr when bumping
423
425
pub const fn new_uninit_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A >
424
426
where
425
- A : ~const Allocator + ~const Drop + ~ const Destruct ,
427
+ A : ~const Allocator + ~const Destruct ,
426
428
{
427
429
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
428
430
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -458,10 +460,9 @@ impl<T, A: Allocator> Box<T, A> {
458
460
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
459
461
// #[unstable(feature = "new_uninit", issue = "63291")]
460
462
#[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
461
- #[ cfg_attr( not( bootstrap) , allow( drop_bounds) ) ] // FIXME remove `~const Drop` and this attr when bumping
462
463
pub const fn try_new_uninit_in ( alloc : A ) -> Result < Box < mem:: MaybeUninit < T > , A > , AllocError >
463
464
where
464
- A : ~const Allocator + ~const Drop + ~ const Destruct ,
465
+ A : ~const Allocator + ~const Destruct ,
465
466
{
466
467
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
467
468
let ptr = alloc. allocate ( layout) ?. cast ( ) ;
@@ -493,10 +494,9 @@ impl<T, A: Allocator> Box<T, A> {
493
494
#[ cfg( not( no_global_oom_handling) ) ]
494
495
// #[unstable(feature = "new_uninit", issue = "63291")]
495
496
#[ must_use]
496
- #[ cfg_attr( not( bootstrap) , allow( drop_bounds) ) ] // FIXME remove `~const Drop` and this attr when bumping
497
497
pub const fn new_zeroed_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A >
498
498
where
499
- A : ~const Allocator + ~const Drop + ~ const Destruct ,
499
+ A : ~const Allocator + ~const Destruct ,
500
500
{
501
501
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
502
502
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -532,10 +532,9 @@ impl<T, A: Allocator> Box<T, A> {
532
532
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
533
533
// #[unstable(feature = "new_uninit", issue = "63291")]
534
534
#[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
535
- #[ cfg_attr( not( bootstrap) , allow( drop_bounds) ) ] // FIXME remove `~const Drop` and this attr when bumping
536
535
pub const fn try_new_zeroed_in ( alloc : A ) -> Result < Box < mem:: MaybeUninit < T > , A > , AllocError >
537
536
where
538
- A : ~const Allocator + ~const Drop + ~ const Destruct ,
537
+ A : ~const Allocator + ~const Destruct ,
539
538
{
540
539
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
541
540
let ptr = alloc. allocate_zeroed ( layout) ?. cast ( ) ;
@@ -549,10 +548,9 @@ impl<T, A: Allocator> Box<T, A> {
549
548
#[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
550
549
#[ must_use]
551
550
#[ inline( always) ]
552
- #[ cfg_attr( not( bootstrap) , allow( drop_bounds) ) ] // FIXME remove `~const Drop` and this attr when bumping
553
551
pub const fn pin_in ( x : T , alloc : A ) -> Pin < Self >
554
552
where
555
- A : ' static + ~const Allocator + ~const Drop + ~ const Destruct ,
553
+ A : ' static + ~const Allocator + ~const Destruct ,
556
554
{
557
555
Self :: into_pin ( Self :: new_in ( x, alloc) )
558
556
}
@@ -581,10 +579,9 @@ impl<T, A: Allocator> Box<T, A> {
581
579
#[ unstable( feature = "box_into_inner" , issue = "80437" ) ]
582
580
#[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
583
581
#[ inline]
584
- #[ cfg_attr( not( bootstrap) , allow( drop_bounds) ) ] // FIXME remove `~const Drop` and this attr when bumping
585
582
pub const fn into_inner ( boxed : Self ) -> T
586
583
where
587
- Self : ~const Drop + ~ const Destruct ,
584
+ Self : ~const Destruct ,
588
585
{
589
586
* boxed
590
587
}
@@ -1197,17 +1194,25 @@ impl<T: Default> Default for Box<T> {
1197
1194
1198
1195
#[ cfg( not( no_global_oom_handling) ) ]
1199
1196
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1200
- impl < T > Default for Box < [ T ] > {
1197
+ #[ rustc_const_unstable( feature = "const_default_impls" , issue = "87864" ) ]
1198
+ impl < T > const Default for Box < [ T ] > {
1201
1199
fn default ( ) -> Self {
1202
- Box :: < [ T ; 0 ] > :: new ( [ ] )
1200
+ let ptr: Unique < [ T ] > = Unique :: < [ T ; 0 ] > :: dangling ( ) ;
1201
+ Box ( ptr, Global )
1203
1202
}
1204
1203
}
1205
1204
1206
1205
#[ cfg( not( no_global_oom_handling) ) ]
1207
1206
#[ stable( feature = "default_box_extra" , since = "1.17.0" ) ]
1208
- impl Default for Box < str > {
1207
+ #[ rustc_const_unstable( feature = "const_default_impls" , issue = "87864" ) ]
1208
+ impl const Default for Box < str > {
1209
1209
fn default ( ) -> Self {
1210
- unsafe { from_boxed_utf8_unchecked ( Default :: default ( ) ) }
1210
+ // SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
1211
+ let ptr: Unique < str > = unsafe {
1212
+ let bytes: Unique < [ u8 ] > = Unique :: < [ u8 ; 0 ] > :: dangling ( ) ;
1213
+ Unique :: new_unchecked ( bytes. as_ptr ( ) as * mut str )
1214
+ } ;
1215
+ Box ( ptr, Global )
1211
1216
}
1212
1217
}
1213
1218
@@ -1366,6 +1371,12 @@ impl<T: ?Sized + Hasher, A: Allocator> Hasher for Box<T, A> {
1366
1371
fn write_isize ( & mut self , i : isize ) {
1367
1372
( * * self ) . write_isize ( i)
1368
1373
}
1374
+ fn write_length_prefix ( & mut self , len : usize ) {
1375
+ ( * * self ) . write_length_prefix ( len)
1376
+ }
1377
+ fn write_str ( & mut self , s : & str ) {
1378
+ ( * * self ) . write_str ( s)
1379
+ }
1369
1380
}
1370
1381
1371
1382
#[ cfg( not( no_global_oom_handling) ) ]
0 commit comments