about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrik Sverdrup <bluss@users.noreply.github.com>2016-03-02 17:48:50 +0100
committerUlrik Sverdrup <bluss@users.noreply.github.com>2016-03-02 18:05:40 +0100
commit1da364e98f46c828e5746be299b58b995e5f5007 (patch)
treec7af353353b0d565eb4462999bad16147b6894f5
parentc0f8b085942c0c914c3c9d175303c23e1b4158e3 (diff)
downloadrust-1da364e98f46c828e5746be299b58b995e5f5007.tar.gz
rust-1da364e98f46c828e5746be299b58b995e5f5007.zip
Use ptr::drop_in_place in Vec::truncate
-rw-r--r--src/libcollections/vec.rs7
1 files 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<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));
             }
         }
     }