@@ -291,6 +291,9 @@ impl<T, A: Allocator> RawVec<T, A> {
291
291
292
292
if self . needs_to_grow ( len, additional) {
293
293
do_reserve_and_handle ( self , len, additional) ;
294
+ if self . needs_to_grow ( len, additional) {
295
+ unsafe { core:: hint:: unreachable_unchecked ( ) ; }
296
+ }
294
297
}
295
298
}
296
299
@@ -305,10 +308,12 @@ impl<T, A: Allocator> RawVec<T, A> {
305
308
/// The same as `reserve`, but returns on errors instead of panicking or aborting.
306
309
pub fn try_reserve ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
307
310
if self . needs_to_grow ( len, additional) {
308
- self . grow_amortized ( len, additional)
309
- } else {
310
- Ok ( ( ) )
311
+ self . grow_amortized ( len, additional) ?;
312
+ if self . needs_to_grow ( len, additional) {
313
+ unsafe { core:: hint:: unreachable_unchecked ( ) ; }
314
+ }
311
315
}
316
+ Ok ( ( ) )
312
317
}
313
318
314
319
/// Ensures that the buffer contains at least enough space to hold `len +
@@ -339,7 +344,13 @@ impl<T, A: Allocator> RawVec<T, A> {
339
344
len : usize ,
340
345
additional : usize ,
341
346
) -> Result < ( ) , TryReserveError > {
342
- if self . needs_to_grow ( len, additional) { self . grow_exact ( len, additional) } else { Ok ( ( ) ) }
347
+ if self . needs_to_grow ( len, additional) {
348
+ self . grow_exact ( len, additional) ?;
349
+ if self . needs_to_grow ( len, additional) {
350
+ unsafe { core:: hint:: unreachable_unchecked ( ) ; }
351
+ }
352
+ }
353
+ Ok ( ( ) )
343
354
}
344
355
345
356
/// Shrinks the buffer down to the specified capacity. If the given amount
0 commit comments