mirror of
https://github.com/openharmony/third_party_rust_rust-smallvec.git
synced 2026-07-19 14:53:33 -04:00
Auto merge of #209 - RalfJung:miri, r=mbrubeck
enable Miri leak checker Works around https://github.com/servo/rust-smallvec/issues/208
This commit is contained in:
@@ -865,6 +865,8 @@ impl<A: Array> SmallVec<A> {
|
||||
|
||||
/// Insert multiple elements at position `index`, shifting all following elements toward the
|
||||
/// back.
|
||||
///
|
||||
/// Note: when the iterator panics, this can leak memory.
|
||||
pub fn insert_many<I: IntoIterator<Item = A::Item>>(&mut self, index: usize, iterable: I) {
|
||||
let iter = iterable.into_iter();
|
||||
if index == self.len() {
|
||||
@@ -2092,12 +2094,17 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
// These boxes are leaked on purpose by panicking `insert_many`,
|
||||
// so we clean them up manually to appease Miri's leak checker.
|
||||
let mut box1 = Box::new(false);
|
||||
let mut box2 = Box::new(false);
|
||||
|
||||
let mut vec: SmallVec<[PanicOnDoubleDrop; 0]> = vec![
|
||||
PanicOnDoubleDrop {
|
||||
dropped: Box::new(false),
|
||||
dropped: unsafe { Box::from_raw(&mut *box1) },
|
||||
},
|
||||
PanicOnDoubleDrop {
|
||||
dropped: Box::new(false),
|
||||
dropped: unsafe { Box::from_raw(&mut *box2) },
|
||||
},
|
||||
]
|
||||
.into();
|
||||
@@ -2105,6 +2112,9 @@ mod tests {
|
||||
vec.insert_many(0, BadIter);
|
||||
});
|
||||
assert!(result.is_err());
|
||||
|
||||
drop(box1);
|
||||
drop(box2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+3
-3
@@ -16,6 +16,6 @@ rustup default "$MIRI_NIGHTLY"
|
||||
rustup component add miri
|
||||
cargo miri setup
|
||||
|
||||
cargo miri test --verbose -- -Zmiri-ignore-leaks
|
||||
cargo miri test --verbose --features union -- -Zmiri-ignore-leaks
|
||||
cargo miri test --verbose --all-features -- -Zmiri-ignore-leaks
|
||||
cargo miri test --verbose
|
||||
cargo miri test --verbose --features union
|
||||
cargo miri test --verbose --all-features
|
||||
|
||||
Reference in New Issue
Block a user