Skip to content

Commit 562568b

Browse files
committed
manually clean up leaked Boxes, to enable Miri's leak checker
1 parent 3957cd8 commit 562568b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,19 +2092,27 @@ mod tests {
20922092
}
20932093
}
20942094

2095+
// These boxes are leaked on purpose by panicking `insert_many`,
2096+
// so we clean them up manually to appease Miri's leak checker.
2097+
let mut box1 = Box::new(false);
2098+
let mut box2 = Box::new(false);
2099+
20952100
let mut vec: SmallVec<[PanicOnDoubleDrop; 0]> = vec![
20962101
PanicOnDoubleDrop {
2097-
dropped: Box::new(false),
2102+
dropped: unsafe { Box::from_raw(&mut *box1) },
20982103
},
20992104
PanicOnDoubleDrop {
2100-
dropped: Box::new(false),
2105+
dropped: unsafe { Box::from_raw(&mut *box2) },
21012106
},
21022107
]
21032108
.into();
21042109
let result = ::std::panic::catch_unwind(move || {
21052110
vec.insert_many(0, BadIter);
21062111
});
21072112
assert!(result.is_err());
2113+
2114+
drop(box1);
2115+
drop(box2);
21082116
}
21092117

21102118
#[test]

scripts/run_miri.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ rustup default "$MIRI_NIGHTLY"
1616
rustup component add miri
1717
cargo miri setup
1818

19-
cargo miri test --verbose -- -Zmiri-ignore-leaks
20-
cargo miri test --verbose --features union -- -Zmiri-ignore-leaks
21-
cargo miri test --verbose --all-features -- -Zmiri-ignore-leaks
19+
cargo miri test --verbose
20+
cargo miri test --verbose --features union
21+
cargo miri test --verbose --all-features

0 commit comments

Comments
 (0)