@@ -7,8 +7,8 @@ use core::ops::Drop;
7
7
use core:: ptr:: { self , NonNull , Unique } ;
8
8
use core:: slice;
9
9
10
- use crate :: alloc:: { Alloc , Layout , Global , handle_alloc_error} ;
11
- use crate :: collections:: CollectionAllocErr :: { self , * } ;
10
+ use crate :: alloc:: { Alloc , Layout , Global , AllocErr , handle_alloc_error} ;
11
+ use crate :: collections:: TryReserveError :: { self , * } ;
12
12
use crate :: boxed:: Box ;
13
13
14
14
#[ cfg( test) ]
@@ -385,7 +385,7 @@ impl<T, A: Alloc> RawVec<T, A> {
385
385
386
386
/// The same as `reserve_exact`, but returns on errors instead of panicking or aborting.
387
387
pub fn try_reserve_exact ( & mut self , used_capacity : usize , needed_extra_capacity : usize )
388
- -> Result < ( ) , CollectionAllocErr > {
388
+ -> Result < ( ) , TryReserveError > {
389
389
390
390
self . reserve_internal ( used_capacity, needed_extra_capacity, Fallible , Exact )
391
391
}
@@ -413,7 +413,7 @@ impl<T, A: Alloc> RawVec<T, A> {
413
413
pub fn reserve_exact ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) {
414
414
match self . reserve_internal ( used_capacity, needed_extra_capacity, Infallible , Exact ) {
415
415
Err ( CapacityOverflow ) => capacity_overflow ( ) ,
416
- Err ( AllocErr ) => unreachable ! ( ) ,
416
+ Err ( AllocError { .. } ) => unreachable ! ( ) ,
417
417
Ok ( ( ) ) => { /* yay */ }
418
418
}
419
419
}
@@ -422,7 +422,7 @@ impl<T, A: Alloc> RawVec<T, A> {
422
422
/// needed_extra_capacity` elements. This logic is used in amortized reserve methods.
423
423
/// Returns `(new_capacity, new_alloc_size)`.
424
424
fn amortized_new_size ( & self , used_capacity : usize , needed_extra_capacity : usize )
425
- -> Result < usize , CollectionAllocErr > {
425
+ -> Result < usize , TryReserveError > {
426
426
427
427
// Nothing we can really do about these checks :(
428
428
let required_cap = used_capacity. checked_add ( needed_extra_capacity)
@@ -435,7 +435,7 @@ impl<T, A: Alloc> RawVec<T, A> {
435
435
436
436
/// The same as `reserve`, but returns on errors instead of panicking or aborting.
437
437
pub fn try_reserve ( & mut self , used_capacity : usize , needed_extra_capacity : usize )
438
- -> Result < ( ) , CollectionAllocErr > {
438
+ -> Result < ( ) , TryReserveError > {
439
439
self . reserve_internal ( used_capacity, needed_extra_capacity, Fallible , Amortized )
440
440
}
441
441
@@ -494,7 +494,7 @@ impl<T, A: Alloc> RawVec<T, A> {
494
494
pub fn reserve ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) {
495
495
match self . reserve_internal ( used_capacity, needed_extra_capacity, Infallible , Amortized ) {
496
496
Err ( CapacityOverflow ) => capacity_overflow ( ) ,
497
- Err ( AllocErr ) => unreachable ! ( ) ,
497
+ Err ( AllocError { .. } ) => unreachable ! ( ) ,
498
498
Ok ( ( ) ) => { /* yay */ }
499
499
}
500
500
}
@@ -640,10 +640,8 @@ impl<T, A: Alloc> RawVec<T, A> {
640
640
needed_extra_capacity : usize ,
641
641
fallibility : Fallibility ,
642
642
strategy : ReserveStrategy ,
643
- ) -> Result < ( ) , CollectionAllocErr > {
643
+ ) -> Result < ( ) , TryReserveError > {
644
644
unsafe {
645
- use crate :: alloc:: AllocErr ;
646
-
647
645
// NOTE: we don't early branch on ZSTs here because we want this
648
646
// to actually catch "asking for more than usize::MAX" in that case.
649
647
// If we make it past the first branch then we are guaranteed to
@@ -672,12 +670,16 @@ impl<T, A: Alloc> RawVec<T, A> {
672
670
None => self . a . alloc ( new_layout) ,
673
671
} ;
674
672
675
- match ( & res, fallibility) {
673
+ let ptr = match ( res, fallibility) {
676
674
( Err ( AllocErr ) , Infallible ) => handle_alloc_error ( new_layout) ,
677
- _ => { }
678
- }
675
+ ( Err ( AllocErr ) , Fallible ) => return Err ( TryReserveError :: AllocError {
676
+ layout : new_layout,
677
+ non_exhaustive : ( ) ,
678
+ } ) ,
679
+ ( Ok ( ptr) , _) => ptr,
680
+ } ;
679
681
680
- self . ptr = res? . cast ( ) . into ( ) ;
682
+ self . ptr = ptr . cast ( ) . into ( ) ;
681
683
self . cap = new_cap;
682
684
683
685
Ok ( ( ) )
@@ -737,7 +739,7 @@ unsafe impl<#[may_dangle] T, A: Alloc> Drop for RawVec<T, A> {
737
739
// all 4GB in user-space. e.g., PAE or x32
738
740
739
741
#[ inline]
740
- fn alloc_guard ( alloc_size : usize ) -> Result < ( ) , CollectionAllocErr > {
742
+ fn alloc_guard ( alloc_size : usize ) -> Result < ( ) , TryReserveError > {
741
743
if mem:: size_of :: < usize > ( ) < 8 && alloc_size > core:: isize:: MAX as usize {
742
744
Err ( CapacityOverflow )
743
745
} else {
0 commit comments