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 @@ -288,15 +288,10 @@ where
288
288
pub fn push ( & mut self , v : T , flags : Flags ) -> Result < ( ) , AllocError > {
289
289
self . reserve ( 1 , flags) ?;
290
290
291
- // SAFETY:
292
- // - `self.len` is smaller than `self.capacity` and hence, the resulting pointer is
293
- // guaranteed to be part of the same allocated object.
294
- // - `self.len` can not overflow `isize`.
295
- let ptr = unsafe { self . as_mut_ptr ( ) . add ( self . len ) } ;
291
+ let spare = self . spare_capacity_mut ( ) ;
296
292
297
- // SAFETY:
298
- // - `ptr` is properly aligned and valid for writes.
299
- unsafe { core:: ptr:: write ( ptr, v) } ;
293
+ // SAFETY: The call to `reserve` was successful so the spare capacity is at least 1.
294
+ unsafe { spare. get_unchecked_mut ( 0 ) } . write ( v) ;
300
295
301
296
// SAFETY: We just initialised the first spare entry, so it is safe to increase the length
302
297
// 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