Skip to content

Commit 4a8f870

Browse files
authored
Rollup merge of #80123 - DrMeepster:maybe_uninit_write_slice, r=RalfJung
Fix memory leak in test "mem::uninit_write_slice_cloned_no_drop" This fixes #80116. I replaced the `Rc` based method I was using with a type that panics when dropped.
2 parents 32123a3 + 01f36c5 commit 4a8f870

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

library/core/tests/mem.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,19 @@ fn uninit_write_slice_cloned_mid_panic() {
250250

251251
#[test]
252252
fn uninit_write_slice_cloned_no_drop() {
253-
let rc = Rc::new(());
253+
#[derive(Clone)]
254+
struct Bomb;
255+
256+
impl Drop for Bomb {
257+
fn drop(&mut self) {
258+
panic!("dropped a bomb! kaboom")
259+
}
260+
}
254261

255262
let mut dst = [MaybeUninit::uninit()];
256-
let src = [rc.clone()];
263+
let src = [Bomb];
257264

258265
MaybeUninit::write_slice_cloned(&mut dst, &src);
259266

260-
drop(src);
261-
262-
assert_eq!(Rc::strong_count(&rc), 2);
267+
forget(src);
263268
}

0 commit comments

Comments
 (0)