File tree Expand file tree Collapse file tree 1 file changed +3
-8
lines changed Expand file tree Collapse file tree 1 file changed +3
-8
lines changed Original file line number Diff line number Diff line change @@ -291,15 +291,10 @@ where
291
291
pub fn push ( & mut self , v : T , flags : Flags ) -> Result < ( ) , AllocError > {
292
292
self . reserve ( 1 , flags) ?;
293
293
294
- // SAFETY:
295
- // - `self.len` is smaller than `self.capacity` and hence, the resulting pointer is
296
- // guaranteed to be part of the same allocated object.
297
- // - `self.len` can not overflow `isize`.
298
- let ptr = unsafe { self . as_mut_ptr ( ) . add ( self . len ) } ;
294
+ let spare = self . spare_capacity_mut ( ) ;
299
295
300
- // SAFETY:
301
- // - `ptr` is properly aligned and valid for writes.
302
- unsafe { core:: ptr:: write ( ptr, v) } ;
296
+ // SAFETY: The call to `reserve` was successful so the spare capacity is at least 1.
297
+ unsafe { spare. get_unchecked_mut ( 0 ) } . write ( v) ;
303
298
304
299
// SAFETY: We just initialised the first spare entry, so it is safe to increase the length
305
300
// by 1. We also know that the new length is <= capacity because of the previous call to
You can’t perform that action at this time.
0 commit comments