1
Fork 0

Use ptr::drop_in_place in Vec::truncate

This commit is contained in:
Ulrik Sverdrup 2016-03-02 17:48:50 +01:00
parent c0f8b08594
commit 1da364e98f

View file

@ -497,10 +497,11 @@ impl<T> Vec<T> {
unsafe {
// drop any extra elements
while len < self.len {
// decrement len before the read(), so a panic on Drop doesn't
// re-drop the just-failed value.
// decrement len before the drop_in_place(), so a panic on Drop
// doesn't re-drop the just-failed value.
self.len -= 1;
ptr::read(self.get_unchecked(self.len));
let len = self.len;
ptr::drop_in_place(self.get_unchecked_mut(len));
}
}
}