diff options
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/drain.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 75aa35c926c..053ee8033ba 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -156,6 +156,10 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> { } unsafe { + // drop_ptr comes from a slice::Iter which only gives us a &[T] but for drop_in_place + // a pointer with mutable provenance is necessary. Therefore we must reconstruct + // it from the original vec but also avoid creating a &mut to the front since that could + // invalidate raw pointers to it which some unsafe code might rely on. let vec = vec.as_mut(); let spare_capacity = vec.spare_capacity_mut(); let drop_offset = drop_ptr.offset_from(spare_capacity.as_ptr() as *const _) as usize; |
