Skip to content

Commit 2908385

Browse files
committed
Rollup merge of #30760 - jonastepe:nomicon_vec_insert_remove_len, r=apasel422
len needs to be prefixed by self for this to work. That is something which trips me up all the time. It's reassuring to see that happening to seasoned Rust programmers.
2 parents 3836578 + a073100 commit 2908385

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/doc/nomicon/vec-insert-remove.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn insert(&mut self, index: usize, elem: T) {
2424
// ptr::copy(src, dest, len): "copy from source to dest len elems"
2525
ptr::copy(self.ptr.offset(index as isize),
2626
self.ptr.offset(index as isize + 1),
27-
len - index);
27+
self.len - index);
2828
}
2929
ptr::write(self.ptr.offset(index as isize), elem);
3030
self.len += 1;
@@ -44,7 +44,7 @@ pub fn remove(&mut self, index: usize) -> T {
4444
let result = ptr::read(self.ptr.offset(index as isize));
4545
ptr::copy(self.ptr.offset(index as isize + 1),
4646
self.ptr.offset(index as isize),
47-
len - index);
47+
self.len - index);
4848
result
4949
}
5050
}

0 commit comments

Comments
 (0)