mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
document why we're not directly passing drop_ptr to drop_in_place
This commit is contained in:
parent
ce994027fe
commit
6851b8d931
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user