Skip to content

Commit 59aaa2a

Browse files
committed
Auto 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 b1964e6 + 28e0d2f commit 59aaa2a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: library/core/tests/mem.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::mem::*;
22

3+
#[cfg(panic = "unwind")]
34
use std::rc::Rc;
45

56
#[test]
@@ -250,14 +251,19 @@ fn uninit_write_slice_cloned_mid_panic() {
250251

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

255263
let mut dst = [MaybeUninit::uninit()];
256-
let src = [rc.clone()];
264+
let src = [Bomb];
257265

258266
MaybeUninit::write_slice_cloned(&mut dst, &src);
259267

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

0 commit comments

Comments
 (0)