Use ptr::drop_in_place in Vec::truncate
This commit is contained in:
parent
c0f8b08594
commit
1da364e98f
1 changed files with 4 additions and 3 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue