about summary refs log tree commit diff
path: root/src/liballoc/vec.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-04-05 08:40:40 +0200
committerRalf Jung <post@ralfj.de>2020-04-05 08:40:40 +0200
commit7e81c11aa8ddcebf64c01579754b44930ecf4d04 (patch)
treef82e6afef895b5e0b0512c60dbf75077fec42cbf /src/liballoc/vec.rs
parent5bbaac357dd85092ed0fb822947df7a4d60c1db9 (diff)
downloadrust-7e81c11aa8ddcebf64c01579754b44930ecf4d04.tar.gz
rust-7e81c11aa8ddcebf64c01579754b44930ecf4d04.zip
tweak swap_remove
Diffstat (limited to 'src/liballoc/vec.rs')
-rw-r--r--src/liballoc/vec.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index c600a6b649f..aedb3724409 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -963,14 +963,15 @@ impl<T> Vec<T> {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn swap_remove(&mut self, index: usize) -> T {
-        assert!(index < self.len);
+        let len = self.len();
+        assert!(index < len);
         unsafe {
             // We replace self[index] with the last element. Note that if the
             // bounds check above succeeds there must be a last element (which
             // can be self[index] itself).
-            let last = ptr::read(self.as_ptr().add(self.len - 1));
+            let last = ptr::read(self.as_ptr().add(len - 1));
             let hole: *mut T = self.as_mut_ptr().add(index);
-            self.len -= 1;
+            self.set_len(len - 1);
             ptr::replace(hole, last)
         }
     }