diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-03-02 17:48:50 +0100 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-03-02 18:05:40 +0100 |
| commit | 1da364e98f46c828e5746be299b58b995e5f5007 (patch) | |
| tree | c7af353353b0d565eb4462999bad16147b6894f5 | |
| parent | c0f8b085942c0c914c3c9d175303c23e1b4158e3 (diff) | |
| download | rust-1da364e98f46c828e5746be299b58b995e5f5007.tar.gz rust-1da364e98f46c828e5746be299b58b995e5f5007.zip | |
Use ptr::drop_in_place in Vec::truncate
| -rw-r--r-- | src/libcollections/vec.rs | 7 |
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)); } } } |
