Skip to content

Commit 2d8a11b

Browse files
committed
Use *mut [T] instead of [MaybeUninit<T>]
1 parent 6851b8d commit 2d8a11b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

library/alloc/src/vec/drain.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::alloc::{Allocator, Global};
22
use core::fmt;
33
use core::iter::{FusedIterator, TrustedLen};
4-
use core::mem::{self, MaybeUninit};
4+
use core::mem;
55
use core::ptr::{self, NonNull};
66
use core::slice::{self};
77

@@ -160,12 +160,10 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
160160
// a pointer with mutable provenance is necessary. Therefore we must reconstruct
161161
// it from the original vec but also avoid creating a &mut to the front since that could
162162
// invalidate raw pointers to it which some unsafe code might rely on.
163-
let vec = vec.as_mut();
164-
let spare_capacity = vec.spare_capacity_mut();
165-
let drop_offset = drop_ptr.offset_from(spare_capacity.as_ptr() as *const _) as usize;
166-
let drop_range = drop_offset..(drop_offset + drop_len);
167-
let to_drop = &mut spare_capacity[drop_range];
168-
ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(to_drop));
163+
let vec_ptr = vec.as_mut().as_mut_ptr();
164+
let drop_offset = drop_ptr.offset_from(vec_ptr) as usize;
165+
let to_drop = ptr::slice_from_raw_parts_mut(vec_ptr.add(drop_offset), drop_len);
166+
ptr::drop_in_place(to_drop);
169167
}
170168
}
171169
}

0 commit comments

Comments
 (0)