@@ -468,10 +468,6 @@ impl<A: Allocator> RawVecInner<A> {
468468 return Ok ( Self :: new_in ( alloc, elem_layout. alignment ( ) ) ) ;
469469 }
470470
471- if let Err ( err) = alloc_guard ( layout. size ( ) ) {
472- return Err ( err) ;
473- }
474-
475471 let result = match init {
476472 AllocInit :: Uninitialized => alloc. allocate ( layout) ,
477473 #[ cfg( not( no_global_oom_handling) ) ]
@@ -662,7 +658,7 @@ impl<A: Allocator> RawVecInner<A> {
662658 let new_layout = layout_array ( cap, elem_layout) ?;
663659
664660 let ptr = finish_grow ( new_layout, self . current_memory ( elem_layout) , & mut self . alloc ) ?;
665- // SAFETY: finish_grow would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
661+ // SAFETY: layout_array would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
666662
667663 unsafe { self . set_ptr_and_cap ( ptr, cap) } ;
668664 Ok ( ( ) )
@@ -684,7 +680,7 @@ impl<A: Allocator> RawVecInner<A> {
684680 let new_layout = layout_array ( cap, elem_layout) ?;
685681
686682 let ptr = finish_grow ( new_layout, self . current_memory ( elem_layout) , & mut self . alloc ) ?;
687- // SAFETY: finish_grow would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
683+ // SAFETY: layout_array would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
688684 unsafe {
689685 self . set_ptr_and_cap ( ptr, cap) ;
690686 }
@@ -771,8 +767,6 @@ fn finish_grow<A>(
771767where
772768 A : Allocator ,
773769{
774- alloc_guard ( new_layout. size ( ) ) ?;
775-
776770 let memory = if let Some ( ( ptr, old_layout) ) = current_memory {
777771 debug_assert_eq ! ( old_layout. align( ) , new_layout. align( ) ) ;
778772 unsafe {
@@ -799,23 +793,6 @@ fn handle_error(e: TryReserveError) -> ! {
799793 }
800794}
801795
802- // We need to guarantee the following:
803- // * We don't ever allocate `> isize::MAX` byte-size objects.
804- // * We don't overflow `usize::MAX` and actually allocate too little.
805- //
806- // On 64-bit we just need to check for overflow since trying to allocate
807- // `> isize::MAX` bytes will surely fail. On 32-bit and 16-bit we need to add
808- // an extra guard for this in case we're running on a platform which can use
809- // all 4GB in user-space, e.g., PAE or x32.
810- #[ inline]
811- fn alloc_guard ( alloc_size : usize ) -> Result < ( ) , TryReserveError > {
812- if usize:: BITS < 64 && alloc_size > isize:: MAX as usize {
813- Err ( CapacityOverflow . into ( ) )
814- } else {
815- Ok ( ( ) )
816- }
817- }
818-
819796#[ inline]
820797fn layout_array ( cap : usize , elem_layout : Layout ) -> Result < Layout , TryReserveError > {
821798 elem_layout. repeat ( cap) . map ( |( layout, _pad) | layout) . map_err ( |_| CapacityOverflow . into ( ) )
0 commit comments