Skip to content

Commit 1da364e

Browse files
committed
Use ptr::drop_in_place in Vec::truncate
1 parent c0f8b08 commit 1da364e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/libcollections/vec.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,11 @@ impl<T> Vec<T> {
497497
unsafe {
498498
// drop any extra elements
499499
while len < self.len {
500-
// decrement len before the read(), so a panic on Drop doesn't
501-
// re-drop the just-failed value.
500+
// decrement len before the drop_in_place(), so a panic on Drop
501+
// doesn't re-drop the just-failed value.
502502
self.len -= 1;
503-
ptr::read(self.get_unchecked(self.len));
503+
let len = self.len;
504+
ptr::drop_in_place(self.get_unchecked_mut(len));
504505
}
505506
}
506507
}

0 commit comments

Comments
 (0)