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