@@ -291,6 +291,11 @@ impl<T, A: Allocator> RawVec<T, A> {
291291
292292 if self . needs_to_grow ( len, additional) {
293293 do_reserve_and_handle ( self , len, additional) ;
294+ if self . needs_to_grow ( len, additional) {
295+ unsafe {
296+ core:: hint:: unreachable_unchecked ( ) ;
297+ }
298+ }
294299 }
295300 }
296301
@@ -305,10 +310,14 @@ impl<T, A: Allocator> RawVec<T, A> {
305310 /// The same as `reserve`, but returns on errors instead of panicking or aborting.
306311 pub fn try_reserve ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
307312 if self . needs_to_grow ( len, additional) {
308- self . grow_amortized ( len, additional)
309- } else {
310- Ok ( ( ) )
313+ self . grow_amortized ( len, additional) ?;
314+ if self . needs_to_grow ( len, additional) {
315+ unsafe {
316+ core:: hint:: unreachable_unchecked ( ) ;
317+ }
318+ }
311319 }
320+ Ok ( ( ) )
312321 }
313322
314323 /// Ensures that the buffer contains at least enough space to hold `len +
@@ -339,7 +348,15 @@ impl<T, A: Allocator> RawVec<T, A> {
339348 len : usize ,
340349 additional : usize ,
341350 ) -> Result < ( ) , TryReserveError > {
342- if self . needs_to_grow ( len, additional) { self . grow_exact ( len, additional) } else { Ok ( ( ) ) }
351+ if self . needs_to_grow ( len, additional) {
352+ self . grow_exact ( len, additional) ?;
353+ if self . needs_to_grow ( len, additional) {
354+ unsafe {
355+ core:: hint:: unreachable_unchecked ( ) ;
356+ }
357+ }
358+ }
359+ Ok ( ( ) )
343360 }
344361
345362 /// Shrinks the buffer down to the specified capacity. If the given amount
0 commit comments