@@ -7,8 +7,8 @@ use core::ops::Drop;
77use core:: ptr:: { self , NonNull , Unique } ;
88use core:: slice;
99
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 , * } ;
1212use crate :: boxed:: Box ;
1313
1414#[ cfg( test) ]
@@ -385,7 +385,7 @@ impl<T, A: Alloc> RawVec<T, A> {
385385
386386 /// The same as `reserve_exact`, but returns on errors instead of panicking or aborting.
387387 pub fn try_reserve_exact ( & mut self , used_capacity : usize , needed_extra_capacity : usize )
388- -> Result < ( ) , CollectionAllocErr > {
388+ -> Result < ( ) , TryReserveError > {
389389
390390 self . reserve_internal ( used_capacity, needed_extra_capacity, Fallible , Exact )
391391 }
@@ -413,7 +413,7 @@ impl<T, A: Alloc> RawVec<T, A> {
413413 pub fn reserve_exact ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) {
414414 match self . reserve_internal ( used_capacity, needed_extra_capacity, Infallible , Exact ) {
415415 Err ( CapacityOverflow ) => capacity_overflow ( ) ,
416- Err ( AllocErr ) => unreachable ! ( ) ,
416+ Err ( AllocError { .. } ) => unreachable ! ( ) ,
417417 Ok ( ( ) ) => { /* yay */ }
418418 }
419419 }
@@ -422,7 +422,7 @@ impl<T, A: Alloc> RawVec<T, A> {
422422 /// needed_extra_capacity` elements. This logic is used in amortized reserve methods.
423423 /// Returns `(new_capacity, new_alloc_size)`.
424424 fn amortized_new_size ( & self , used_capacity : usize , needed_extra_capacity : usize )
425- -> Result < usize , CollectionAllocErr > {
425+ -> Result < usize , TryReserveError > {
426426
427427 // Nothing we can really do about these checks :(
428428 let required_cap = used_capacity. checked_add ( needed_extra_capacity)
@@ -435,7 +435,7 @@ impl<T, A: Alloc> RawVec<T, A> {
435435
436436 /// The same as `reserve`, but returns on errors instead of panicking or aborting.
437437 pub fn try_reserve ( & mut self , used_capacity : usize , needed_extra_capacity : usize )
438- -> Result < ( ) , CollectionAllocErr > {
438+ -> Result < ( ) , TryReserveError > {
439439 self . reserve_internal ( used_capacity, needed_extra_capacity, Fallible , Amortized )
440440 }
441441
@@ -494,7 +494,7 @@ impl<T, A: Alloc> RawVec<T, A> {
494494 pub fn reserve ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) {
495495 match self . reserve_internal ( used_capacity, needed_extra_capacity, Infallible , Amortized ) {
496496 Err ( CapacityOverflow ) => capacity_overflow ( ) ,
497- Err ( AllocErr ) => unreachable ! ( ) ,
497+ Err ( AllocError { .. } ) => unreachable ! ( ) ,
498498 Ok ( ( ) ) => { /* yay */ }
499499 }
500500 }
@@ -640,10 +640,8 @@ impl<T, A: Alloc> RawVec<T, A> {
640640 needed_extra_capacity : usize ,
641641 fallibility : Fallibility ,
642642 strategy : ReserveStrategy ,
643- ) -> Result < ( ) , CollectionAllocErr > {
643+ ) -> Result < ( ) , TryReserveError > {
644644 unsafe {
645- use crate :: alloc:: AllocErr ;
646-
647645 // NOTE: we don't early branch on ZSTs here because we want this
648646 // to actually catch "asking for more than usize::MAX" in that case.
649647 // If we make it past the first branch then we are guaranteed to
@@ -672,12 +670,16 @@ impl<T, A: Alloc> RawVec<T, A> {
672670 None => self . a . alloc ( new_layout) ,
673671 } ;
674672
675- match ( & res, fallibility) {
673+ let ptr = match ( res, fallibility) {
676674 ( 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+ } ;
679681
680- self . ptr = res? . cast ( ) . into ( ) ;
682+ self . ptr = ptr . cast ( ) . into ( ) ;
681683 self . cap = new_cap;
682684
683685 Ok ( ( ) )
@@ -737,7 +739,7 @@ unsafe impl<#[may_dangle] T, A: Alloc> Drop for RawVec<T, A> {
737739// all 4GB in user-space. e.g., PAE or x32
738740
739741#[ inline]
740- fn alloc_guard ( alloc_size : usize ) -> Result < ( ) , CollectionAllocErr > {
742+ fn alloc_guard ( alloc_size : usize ) -> Result < ( ) , TryReserveError > {
741743 if mem:: size_of :: < usize > ( ) < 8 && alloc_size > core:: isize:: MAX as usize {
742744 Err ( CapacityOverflow )
743745 } else {
0 commit comments