We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5bbaac3 commit 7e81c11Copy full SHA for 7e81c11
src/liballoc/vec.rs
@@ -963,14 +963,15 @@ impl<T> Vec<T> {
963
#[inline]
964
#[stable(feature = "rust1", since = "1.0.0")]
965
pub fn swap_remove(&mut self, index: usize) -> T {
966
- assert!(index < self.len);
+ let len = self.len();
967
+ assert!(index < len);
968
unsafe {
969
// We replace self[index] with the last element. Note that if the
970
// bounds check above succeeds there must be a last element (which
971
// can be self[index] itself).
- let last = ptr::read(self.as_ptr().add(self.len - 1));
972
+ let last = ptr::read(self.as_ptr().add(len - 1));
973
let hole: *mut T = self.as_mut_ptr().add(index);
- self.len -= 1;
974
+ self.set_len(len - 1);
975
ptr::replace(hole, last)
976
}
977
0 commit comments