mirror of
https://github.com/openharmony/third_party_rust_tinyvec.git
synced 2026-07-18 12:25:35 -04:00
Test and fix removal at past-the-end index
This commit is contained in:
+3
-5
@@ -384,12 +384,10 @@ impl<A: Array> ArrayVec<A> {
|
||||
#[inline]
|
||||
pub fn remove(&mut self, index: usize) -> A::Item {
|
||||
let targets: &mut [A::Item] = &mut self.deref_mut()[index..];
|
||||
let mut spare = A::Item::default();
|
||||
for target in targets.iter_mut().rev() {
|
||||
spare = replace(target, spare);
|
||||
}
|
||||
let item = replace(&mut targets[0], A::Item::default());
|
||||
targets.rotate_left(1);
|
||||
self.len -= 1;
|
||||
spare
|
||||
item
|
||||
}
|
||||
|
||||
// NIGHTLY: remove_item, https://github.com/rust-lang/rust/issues/40062
|
||||
|
||||
@@ -123,6 +123,14 @@ fn ArrayVec_remove() {
|
||||
assert_eq!(&av[..], &[1, 3][..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn ArrayVec_remove_invalid() {
|
||||
let mut av: ArrayVec<[i32; 1]> = Default::default();
|
||||
av.push(1);
|
||||
av.remove(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ArrayVec_swap_remove() {
|
||||
let mut av: ArrayVec<[i32; 10]> = Default::default();
|
||||
|
||||
Reference in New Issue
Block a user