Skip to content

Commit f40e708

Browse files
committed
FIX: In truncate, don't access self while holding raw pointer derived from self
Again, stacked borrows model makes the `self.set_len()` call illegal because we are holding (and are going to use) another raw pointer derived from self, `tail`.
1 parent 2312827 commit f40e708

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,11 @@ impl<A: Array> ArrayVec<A> {
461461
/// array.truncate(4);
462462
/// assert_eq!(&array[..], &[1, 2, 3]);
463463
/// ```
464-
pub fn truncate(&mut self, len: usize) {
464+
pub fn truncate(&mut self, new_len: usize) {
465465
unsafe {
466-
if len < self.len() {
467-
let tail: *mut [_] = &mut self[len..];
468-
self.set_len(len);
466+
if new_len < self.len() {
467+
let tail: *mut [_] = &mut self[new_len..];
468+
self.len = Index::from(new_len);
469469
ptr::drop_in_place(tail);
470470
}
471471
}

0 commit comments

Comments
 (0)