From 1da364e98f46c828e5746be299b58b995e5f5007 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Wed, 2 Mar 2016 17:48:50 +0100 Subject: [PATCH] Use ptr::drop_in_place in Vec::truncate --- src/libcollections/vec.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e010c32f8ea..efcb5d2ceb3 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -497,10 +497,11 @@ impl Vec { 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)); } } }