diff options
| author | The8472 <git@infinite-source.de> | 2021-11-20 01:29:04 +0100 |
|---|---|---|
| committer | The8472 <git@infinite-source.de> | 2021-11-20 01:29:04 +0100 |
| commit | 6851b8d931381c4e7b6d60dab70002efd85dc7a9 (patch) | |
| tree | 531d96ece62a42c7328fc57484d42db64b458cc2 /library/alloc/src/vec | |
| parent | ce994027fe2ce57a4759a4c1327dbfb3592bfdff (diff) | |
| download | rust-6851b8d931381c4e7b6d60dab70002efd85dc7a9.tar.gz rust-6851b8d931381c4e7b6d60dab70002efd85dc7a9.zip | |
document why we're not directly passing drop_ptr to drop_in_place
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; |
