@@ -152,15 +152,13 @@ use core::any::Any;
152
152
use core:: async_iter:: AsyncIterator ;
153
153
use core:: borrow;
154
154
use core:: cmp:: Ordering ;
155
- use core:: convert:: { From , TryFrom } ;
156
155
use core:: error:: Error ;
157
156
use core:: fmt;
158
157
use core:: future:: Future ;
159
158
use 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 ;
164
162
use core:: mem;
165
163
use core:: ops:: {
166
164
CoerceUnsized , Deref , DerefMut , DispatchFromDyn , Generator , GeneratorState , Receiver ,
@@ -187,7 +185,7 @@ pub use thin::ThinBox;
187
185
188
186
mod thin;
189
187
190
- /// A pointer type for heap allocation.
188
+ /// A pointer type that uniquely owns a heap allocation of type `T` .
191
189
///
192
190
/// See the [module-level documentation](../../std/boxed/index.html) for more.
193
191
#[ lang = "owned_box" ]
@@ -215,6 +213,7 @@ impl<T> Box<T> {
215
213
#[ inline( always) ]
216
214
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
217
215
#[ must_use]
216
+ #[ rustc_diagnostic_item = "box_new" ]
218
217
pub fn new ( x : T ) -> Self {
219
218
#[ rustc_box]
220
219
Box :: new ( x)
@@ -284,9 +283,7 @@ impl<T> Box<T> {
284
283
#[ must_use]
285
284
#[ inline( always) ]
286
285
pub fn pin ( x : T ) -> Pin < Box < T > > {
287
- ( #[ rustc_box]
288
- Box :: new ( x) )
289
- . into ( )
286
+ Box :: new ( x) . into ( )
290
287
}
291
288
292
289
/// Allocates memory on the heap then places `x` into it,
@@ -378,12 +375,11 @@ impl<T, A: Allocator> Box<T, A> {
378
375
/// ```
379
376
#[ cfg( not( no_global_oom_handling) ) ]
380
377
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
381
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
382
378
#[ must_use]
383
379
#[ inline]
384
- pub const fn new_in ( x : T , alloc : A ) -> Self
380
+ pub fn new_in ( x : T , alloc : A ) -> Self
385
381
where
386
- A : ~ const Allocator + ~ const Destruct ,
382
+ A : Allocator ,
387
383
{
388
384
let mut boxed = Self :: new_uninit_in ( alloc) ;
389
385
unsafe {
@@ -408,12 +404,10 @@ impl<T, A: Allocator> Box<T, A> {
408
404
/// # Ok::<(), std::alloc::AllocError>(())
409
405
/// ```
410
406
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
411
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
412
407
#[ 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 >
414
409
where
415
- T : ~const Destruct ,
416
- A : ~const Allocator + ~const Destruct ,
410
+ A : Allocator ,
417
411
{
418
412
let mut boxed = Self :: try_new_uninit_in ( alloc) ?;
419
413
unsafe {
@@ -443,13 +437,12 @@ impl<T, A: Allocator> Box<T, A> {
443
437
/// assert_eq!(*five, 5)
444
438
/// ```
445
439
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
446
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
447
440
#[ cfg( not( no_global_oom_handling) ) ]
448
441
#[ must_use]
449
442
// #[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 >
451
444
where
452
- A : ~ const Allocator + ~ const Destruct ,
445
+ A : Allocator ,
453
446
{
454
447
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
455
448
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -484,10 +477,9 @@ impl<T, A: Allocator> Box<T, A> {
484
477
/// ```
485
478
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
486
479
// #[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 >
489
481
where
490
- A : ~ const Allocator + ~ const Destruct ,
482
+ A : Allocator ,
491
483
{
492
484
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
493
485
let ptr = alloc. allocate ( layout) ?. cast ( ) ;
@@ -515,13 +507,12 @@ impl<T, A: Allocator> Box<T, A> {
515
507
///
516
508
/// [zeroed]: mem::MaybeUninit::zeroed
517
509
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
518
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
519
510
#[ cfg( not( no_global_oom_handling) ) ]
520
511
// #[unstable(feature = "new_uninit", issue = "63291")]
521
512
#[ 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 >
523
514
where
524
- A : ~ const Allocator + ~ const Destruct ,
515
+ A : Allocator ,
525
516
{
526
517
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
527
518
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -556,10 +547,9 @@ impl<T, A: Allocator> Box<T, A> {
556
547
/// [zeroed]: mem::MaybeUninit::zeroed
557
548
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
558
549
// #[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 >
561
551
where
562
- A : ~ const Allocator + ~ const Destruct ,
552
+ A : Allocator ,
563
553
{
564
554
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
565
555
let ptr = alloc. allocate_zeroed ( layout) ?. cast ( ) ;
@@ -575,12 +565,11 @@ impl<T, A: Allocator> Box<T, A> {
575
565
/// construct a (pinned) `Box` in a different way than with [`Box::new_in`].
576
566
#[ cfg( not( no_global_oom_handling) ) ]
577
567
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
578
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
579
568
#[ must_use]
580
569
#[ 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 >
582
571
where
583
- A : ' static + ~ const Allocator + ~ const Destruct ,
572
+ A : ' static + Allocator ,
584
573
{
585
574
Self :: into_pin ( Self :: new_in ( x, alloc) )
586
575
}
@@ -607,12 +596,8 @@ impl<T, A: Allocator> Box<T, A> {
607
596
/// assert_eq!(Box::into_inner(c), 5);
608
597
/// ```
609
598
#[ unstable( feature = "box_into_inner" , issue = "80437" ) ]
610
- #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
611
599
#[ 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 {
616
601
* boxed
617
602
}
618
603
}
@@ -954,7 +939,7 @@ impl<T: ?Sized> Box<T> {
954
939
/// [`Layout`]: crate::Layout
955
940
#[ stable( feature = "box_raw" , since = "1.4.0" ) ]
956
941
#[ 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`" ]
958
943
pub unsafe fn from_raw ( raw : * mut T ) -> Self {
959
944
unsafe { Self :: from_raw_in ( raw, Global ) }
960
945
}
@@ -1243,8 +1228,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
1243
1228
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1244
1229
impl < T : Default > Default for Box < T > {
1245
1230
/// Creates a `Box<T>`, with the `Default` value for T.
1231
+ #[ inline]
1246
1232
fn default ( ) -> Self {
1247
- #[ rustc_box]
1248
1233
Box :: new ( T :: default ( ) )
1249
1234
}
1250
1235
}
@@ -1253,6 +1238,7 @@ impl<T: Default> Default for Box<T> {
1253
1238
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1254
1239
#[ rustc_const_unstable( feature = "const_default_impls" , issue = "87864" ) ]
1255
1240
impl < T > const Default for Box < [ T ] > {
1241
+ #[ inline]
1256
1242
fn default ( ) -> Self {
1257
1243
let ptr: Unique < [ T ] > = Unique :: < [ T ; 0 ] > :: dangling ( ) ;
1258
1244
Box ( ptr, Global )
@@ -1263,6 +1249,7 @@ impl<T> const Default for Box<[T]> {
1263
1249
#[ stable( feature = "default_box_extra" , since = "1.17.0" ) ]
1264
1250
#[ rustc_const_unstable( feature = "const_default_impls" , issue = "87864" ) ]
1265
1251
impl const Default for Box < str > {
1252
+ #[ inline]
1266
1253
fn default ( ) -> Self {
1267
1254
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
1268
1255
let ptr: Unique < str > = unsafe {
@@ -1617,7 +1604,6 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
1617
1604
/// println!("{boxed:?}");
1618
1605
/// ```
1619
1606
fn from ( array : [ T ; N ] ) -> Box < [ T ] > {
1620
- #[ rustc_box]
1621
1607
Box :: new ( array)
1622
1608
}
1623
1609
}
@@ -1982,7 +1968,7 @@ impl<I: ExactSizeIterator + ?Sized, A: Allocator> ExactSizeIterator for Box<I, A
1982
1968
impl < I : FusedIterator + ?Sized , A : Allocator > FusedIterator for Box < I , A > { }
1983
1969
1984
1970
#[ 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 > {
1986
1972
type Output = <F as FnOnce < Args > >:: Output ;
1987
1973
1988
1974
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> {
1991
1977
}
1992
1978
1993
1979
#[ 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 > {
1995
1981
extern "rust-call" fn call_mut ( & mut self , args : Args ) -> Self :: Output {
1996
1982
<F as FnMut < Args > >:: call_mut ( self , args)
1997
1983
}
1998
1984
}
1999
1985
2000
1986
#[ 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 > {
2002
1988
extern "rust-call" fn call ( & self , args : Args ) -> Self :: Output {
2003
1989
<F as Fn < Args > >:: call ( self , args)
2004
1990
}
2005
1991
}
2006
1992
2007
- #[ unstable( feature = "coerce_unsized" , issue = "27732 " ) ]
1993
+ #[ unstable( feature = "coerce_unsized" , issue = "18598 " ) ]
2008
1994
impl < T : ?Sized + Unsize < U > , U : ?Sized , A : Allocator > CoerceUnsized < Box < U , A > > for Box < T , A > { }
2009
1995
2010
1996
#[ unstable( feature = "dispatch_from_dyn" , issue = "none" ) ]
0 commit comments