@@ -69,7 +69,7 @@ use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState};
69
69
use core:: ptr:: { self , NonNull , Unique } ;
70
70
use core:: task:: { Context , Poll } ;
71
71
72
- use alloc:: { Alloc , Global , Layout , handle_alloc_error} ;
72
+ use alloc:: { Alloc , AllocHelper , AllocErr , Global , Layout , handle_alloc_error} ;
73
73
use raw_vec:: RawVec ;
74
74
use str:: from_boxed_utf8_unchecked;
75
75
@@ -79,7 +79,7 @@ use str::from_boxed_utf8_unchecked;
79
79
#[ lang = "owned_box" ]
80
80
#[ fundamental]
81
81
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
82
- pub struct Box < T : ?Sized , A : Alloc = Global > ( Unique < T > , A ) ;
82
+ pub struct Box < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > = Global > ( Unique < T > , A ) ;
83
83
84
84
impl < T > Box < T > {
85
85
/// Allocates memory on the heap and then places `x` into it.
@@ -98,7 +98,7 @@ impl<T> Box<T> {
98
98
}
99
99
}
100
100
101
- impl < T , A : Alloc > Box < T , A > {
101
+ impl < T , A : Alloc + AllocHelper < Err = AllocErr > > Box < T , A > {
102
102
/// Allocates memory in the given allocator and then places `x` into it.
103
103
///
104
104
/// This doesn't actually allocate if `T` is zero-sized.
@@ -159,7 +159,7 @@ impl<T: ?Sized> Box<T> {
159
159
}
160
160
}
161
161
162
- impl < T : ?Sized , A : Alloc > Box < T , A > {
162
+ impl < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > Box < T , A > {
163
163
/// Constructs a box from a raw pointer in the given allocator.
164
164
///
165
165
/// This is similar to the [`Box::from_raw`] function, but assumes
@@ -303,7 +303,7 @@ impl<T: ?Sized, A: Alloc> Box<T, A> {
303
303
}
304
304
305
305
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
306
- unsafe impl < #[ may_dangle] T : ?Sized , A : Alloc > Drop for Box < T , A > {
306
+ unsafe impl < #[ may_dangle] T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > Drop for Box < T , A > {
307
307
fn drop ( & mut self ) {
308
308
// FIXME: Do nothing, drop is currently performed by compiler.
309
309
}
@@ -318,15 +318,15 @@ impl<T: Default> Default for Box<T> {
318
318
}
319
319
320
320
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
321
- impl < T : Default , A : Alloc + Default > Default for Box < T , A > {
321
+ impl < T : Default , A : Alloc + AllocHelper < Err = AllocErr > + Default > Default for Box < T , A > {
322
322
/// Creates a `Box<T, A>`, with the `Default` value for T.
323
323
default fn default ( ) -> Box < T , A > {
324
324
Box :: new_in ( Default :: default ( ) , Default :: default ( ) )
325
325
}
326
326
}
327
327
328
328
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
329
- impl < T , A : Alloc + Default > Default for Box < [ T ] , A > {
329
+ impl < T , A : Alloc + AllocHelper < Err = AllocErr > + Default > Default for Box < [ T ] , A > {
330
330
fn default ( ) -> Box < [ T ] , A > {
331
331
Box :: < [ T ; 0 ] , A > :: new_in ( [ ] , A :: default ( ) )
332
332
}
@@ -374,7 +374,7 @@ impl<T: Clone> Clone for Box<T> {
374
374
}
375
375
376
376
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
377
- impl < T : Clone , A : Alloc + Clone > Clone for Box < T , A > {
377
+ impl < T : Clone , A : Alloc + AllocHelper < Err = AllocErr > + Clone > Clone for Box < T , A > {
378
378
#[ inline]
379
379
default fn clone ( & self ) -> Box < T , A > {
380
380
Box :: new_in ( ( * * self ) . clone ( ) , self . 1 . clone ( ) )
@@ -399,7 +399,7 @@ impl Clone for Box<str> {
399
399
}
400
400
401
401
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
402
- impl < T : ?Sized + PartialEq , A : Alloc > PartialEq for Box < T , A > {
402
+ impl < T : ?Sized + PartialEq , A : Alloc + AllocHelper < Err = AllocErr > > PartialEq for Box < T , A > {
403
403
#[ inline]
404
404
fn eq ( & self , other : & Box < T , A > ) -> bool {
405
405
PartialEq :: eq ( & * * self , & * * other)
@@ -410,7 +410,7 @@ impl<T: ?Sized + PartialEq, A: Alloc> PartialEq for Box<T, A> {
410
410
}
411
411
}
412
412
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
413
- impl < T : ?Sized + PartialOrd , A : Alloc > PartialOrd for Box < T , A > {
413
+ impl < T : ?Sized + PartialOrd , A : Alloc + AllocHelper < Err = AllocErr > > PartialOrd for Box < T , A > {
414
414
#[ inline]
415
415
fn partial_cmp ( & self , other : & Box < T , A > ) -> Option < Ordering > {
416
416
PartialOrd :: partial_cmp ( & * * self , & * * other)
@@ -433,24 +433,24 @@ impl<T: ?Sized + PartialOrd, A: Alloc> PartialOrd for Box<T, A> {
433
433
}
434
434
}
435
435
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
436
- impl < T : ?Sized + Ord , A : Alloc > Ord for Box < T , A > {
436
+ impl < T : ?Sized + Ord , A : Alloc + AllocHelper < Err = AllocErr > > Ord for Box < T , A > {
437
437
#[ inline]
438
438
fn cmp ( & self , other : & Box < T , A > ) -> Ordering {
439
439
Ord :: cmp ( & * * self , & * * other)
440
440
}
441
441
}
442
442
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
443
- impl < T : ?Sized + Eq , A : Alloc > Eq for Box < T , A > { }
443
+ impl < T : ?Sized + Eq , A : Alloc + AllocHelper < Err = AllocErr > > Eq for Box < T , A > { }
444
444
445
445
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
446
- impl < T : ?Sized + Hash , A : Alloc > Hash for Box < T , A > {
446
+ impl < T : ?Sized + Hash , A : Alloc + AllocHelper < Err = AllocErr > > Hash for Box < T , A > {
447
447
fn hash < H : Hasher > ( & self , state : & mut H ) {
448
448
( * * self ) . hash ( state) ;
449
449
}
450
450
}
451
451
452
452
#[ stable( feature = "indirect_hasher_impl" , since = "1.22.0" ) ]
453
- impl < T : ?Sized + Hasher , A : Alloc > Hasher for Box < T , A > {
453
+ impl < T : ?Sized + Hasher , A : Alloc + AllocHelper < Err = AllocErr > > Hasher for Box < T , A > {
454
454
fn finish ( & self ) -> u64 {
455
455
( * * self ) . finish ( )
456
456
}
@@ -503,14 +503,14 @@ impl<T> From<T> for Box<T> {
503
503
}
504
504
505
505
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
506
- impl < T , A : Alloc + Default > From < T > for Box < T , A > {
506
+ impl < T , A : Alloc + AllocHelper < Err = AllocErr > + Default > From < T > for Box < T , A > {
507
507
default fn from ( t : T ) -> Self {
508
508
Box :: new_in ( t, A :: default ( ) )
509
509
}
510
510
}
511
511
512
512
#[ stable( feature = "box_from_slice" , since = "1.17.0" ) ]
513
- impl < ' a , T : Copy , A : Alloc + Default > From < & ' a [ T ] > for Box < [ T ] , A > {
513
+ impl < ' a , T : Copy , A : Alloc + AllocHelper < Err = AllocErr > + Default > From < & ' a [ T ] > for Box < [ T ] , A > {
514
514
fn from ( slice : & ' a [ T ] ) -> Box < [ T ] , A > {
515
515
let a = A :: default ( ) ;
516
516
let mut boxed = unsafe { RawVec :: with_capacity_in ( slice. len ( ) , a) . into_box ( ) } ;
@@ -600,21 +600,21 @@ impl Box<dyn Any + Send> {
600
600
}
601
601
602
602
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
603
- impl < T : fmt:: Display + ?Sized , A : Alloc > fmt:: Display for Box < T , A > {
603
+ impl < T : fmt:: Display + ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > fmt:: Display for Box < T , A > {
604
604
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
605
605
fmt:: Display :: fmt ( & * * self , f)
606
606
}
607
607
}
608
608
609
609
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
610
- impl < T : fmt:: Debug + ?Sized , A : Alloc > fmt:: Debug for Box < T , A > {
610
+ impl < T : fmt:: Debug + ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > fmt:: Debug for Box < T , A > {
611
611
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
612
612
fmt:: Debug :: fmt ( & * * self , f)
613
613
}
614
614
}
615
615
616
616
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
617
- impl < T : ?Sized , A : Alloc > fmt:: Pointer for Box < T , A > {
617
+ impl < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > fmt:: Pointer for Box < T , A > {
618
618
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
619
619
// It's not possible to extract the inner Uniq directly from the Box,
620
620
// instead we cast it to a *const which aliases the Unique
@@ -624,7 +624,7 @@ impl<T: ?Sized, A: Alloc> fmt::Pointer for Box<T, A> {
624
624
}
625
625
626
626
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
627
- impl < T : ?Sized , A : Alloc > Deref for Box < T , A > {
627
+ impl < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > Deref for Box < T , A > {
628
628
type Target = T ;
629
629
630
630
fn deref ( & self ) -> & T {
@@ -633,14 +633,14 @@ impl<T: ?Sized, A: Alloc> Deref for Box<T, A> {
633
633
}
634
634
635
635
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
636
- impl < T : ?Sized , A : Alloc > DerefMut for Box < T , A > {
636
+ impl < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > DerefMut for Box < T , A > {
637
637
fn deref_mut ( & mut self ) -> & mut T {
638
638
& mut * * self
639
639
}
640
640
}
641
641
642
642
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
643
- impl < I : Iterator + ?Sized , A : Alloc > Iterator for Box < I , A > {
643
+ impl < I : Iterator + ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > Iterator for Box < I , A > {
644
644
type Item = I :: Item ;
645
645
fn next ( & mut self ) -> Option < I :: Item > {
646
646
( * * self ) . next ( )
@@ -653,13 +653,13 @@ impl<I: Iterator + ?Sized, A: Alloc> Iterator for Box<I, A> {
653
653
}
654
654
}
655
655
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
656
- impl < I : DoubleEndedIterator + ?Sized , A : Alloc > DoubleEndedIterator for Box < I , A > {
656
+ impl < I : DoubleEndedIterator + ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > DoubleEndedIterator for Box < I , A > {
657
657
fn next_back ( & mut self ) -> Option < I :: Item > {
658
658
( * * self ) . next_back ( )
659
659
}
660
660
}
661
661
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
662
- impl < I : ExactSizeIterator + ?Sized , A : Alloc > ExactSizeIterator for Box < I , A > {
662
+ impl < I : ExactSizeIterator + ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > ExactSizeIterator for Box < I , A > {
663
663
fn len ( & self ) -> usize {
664
664
( * * self ) . len ( )
665
665
}
@@ -669,7 +669,7 @@ impl<I: ExactSizeIterator + ?Sized, A: Alloc> ExactSizeIterator for Box<I, A> {
669
669
}
670
670
671
671
#[ stable( feature = "fused" , since = "1.26.0" ) ]
672
- impl < I : FusedIterator + ?Sized , A : Alloc > FusedIterator for Box < I , A > { }
672
+ impl < I : FusedIterator + ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > FusedIterator for Box < I , A > { }
673
673
674
674
675
675
/// `FnBox` is a version of the `FnOnce` intended for use with boxed
@@ -751,10 +751,10 @@ impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + 'a> {
751
751
}
752
752
753
753
#[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
754
- impl < T : ?Sized + Unsize < U > , U : ?Sized , A : Alloc > CoerceUnsized < Box < U , A > > for Box < T , A > { }
754
+ impl < T : ?Sized + Unsize < U > , U : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > CoerceUnsized < Box < U , A > > for Box < T , A > { }
755
755
756
756
#[ stable( feature = "box_slice_clone" , since = "1.3.0" ) ]
757
- impl < T : Clone , A : Alloc + Clone > Clone for Box < [ T ] , A > {
757
+ impl < T : Clone , A : Alloc + AllocHelper < Err = AllocErr > + Clone > Clone for Box < [ T ] , A > {
758
758
fn clone ( & self ) -> Self {
759
759
let mut new = BoxBuilder {
760
760
data : RawVec :: with_capacity_in ( self . len ( ) , self . 1 . clone ( ) ) ,
@@ -775,20 +775,20 @@ impl<T: Clone, A: Alloc + Clone> Clone for Box<[T], A> {
775
775
return unsafe { new. into_box ( ) } ;
776
776
777
777
// Helper type for responding to panics correctly.
778
- struct BoxBuilder < T , A : Alloc > {
778
+ struct BoxBuilder < T , A : Alloc + AllocHelper < Err = AllocErr > + AllocHelper < Err = AllocErr > > {
779
779
data : RawVec < T , A > ,
780
780
len : usize ,
781
781
}
782
782
783
- impl < T , A : Alloc > BoxBuilder < T , A > {
783
+ impl < T , A : Alloc + AllocHelper < Err = AllocErr > > BoxBuilder < T , A > {
784
784
unsafe fn into_box ( self ) -> Box < [ T ] , A > {
785
785
let raw = ptr:: read ( & self . data ) ;
786
786
mem:: forget ( self ) ;
787
787
raw. into_box ( )
788
788
}
789
789
}
790
790
791
- impl < T , A : Alloc > Drop for BoxBuilder < T , A > {
791
+ impl < T , A : Alloc + AllocHelper < Err = AllocErr > > Drop for BoxBuilder < T , A > {
792
792
fn drop ( & mut self ) {
793
793
let mut data = self . data . ptr ( ) ;
794
794
let max = unsafe { data. offset ( self . len as isize ) } ;
@@ -805,35 +805,35 @@ impl<T: Clone, A: Alloc + Clone> Clone for Box<[T], A> {
805
805
}
806
806
807
807
#[ stable( feature = "box_borrow" , since = "1.1.0" ) ]
808
- impl < T : ?Sized , A : Alloc > borrow:: Borrow < T > for Box < T , A > {
808
+ impl < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > borrow:: Borrow < T > for Box < T , A > {
809
809
fn borrow ( & self ) -> & T {
810
810
& * * self
811
811
}
812
812
}
813
813
814
814
#[ stable( feature = "box_borrow" , since = "1.1.0" ) ]
815
- impl < T : ?Sized , A : Alloc > borrow:: BorrowMut < T > for Box < T , A > {
815
+ impl < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > borrow:: BorrowMut < T > for Box < T , A > {
816
816
fn borrow_mut ( & mut self ) -> & mut T {
817
817
& mut * * self
818
818
}
819
819
}
820
820
821
821
#[ stable( since = "1.5.0" , feature = "smart_ptr_as_ref" ) ]
822
- impl < T : ?Sized , A : Alloc > AsRef < T > for Box < T , A > {
822
+ impl < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > AsRef < T > for Box < T , A > {
823
823
fn as_ref ( & self ) -> & T {
824
824
& * * self
825
825
}
826
826
}
827
827
828
828
#[ stable( since = "1.5.0" , feature = "smart_ptr_as_ref" ) ]
829
- impl < T : ?Sized , A : Alloc > AsMut < T > for Box < T , A > {
829
+ impl < T : ?Sized , A : Alloc + AllocHelper < Err = AllocErr > > AsMut < T > for Box < T , A > {
830
830
fn as_mut ( & mut self ) -> & mut T {
831
831
& mut * * self
832
832
}
833
833
}
834
834
835
835
#[ unstable( feature = "generator_trait" , issue = "43122" ) ]
836
- impl < T , A : Alloc > Generator for Box < T , A >
836
+ impl < T , A : Alloc + AllocHelper < Err = AllocErr > > Generator for Box < T , A >
837
837
where T : Generator + ?Sized
838
838
{
839
839
type Yield = T :: Yield ;
0 commit comments