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:
bors-servo
2020-04-11 14:07:45 -04:00
committed by GitHub
2 changed files with 15 additions and 5 deletions
+12 -2
View File
@@ -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
View File
@@ -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