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`.
This commit is contained in:
+4
-4
@@ -461,11 +461,11 @@ impl<A: Array> ArrayVec<A> {
|
|||||||
/// array.truncate(4);
|
/// array.truncate(4);
|
||||||
/// assert_eq!(&array[..], &[1, 2, 3]);
|
/// assert_eq!(&array[..], &[1, 2, 3]);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn truncate(&mut self, len: usize) {
|
pub fn truncate(&mut self, new_len: usize) {
|
||||||
unsafe {
|
unsafe {
|
||||||
if len < self.len() {
|
if new_len < self.len() {
|
||||||
let tail: *mut [_] = &mut self[len..];
|
let tail: *mut [_] = &mut self[new_len..];
|
||||||
self.set_len(len);
|
self.len = Index::from(new_len);
|
||||||
ptr::drop_in_place(tail);
|
ptr::drop_in_place(tail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user