Skip to content

Commit

Permalink
fix memory leak in test
Browse files Browse the repository at this point in the history
  • Loading branch information
beepster4096 committed Dec 17, 2020
1 parent 4652a13 commit 01f36c5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions library/core/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,19 @@ fn uninit_write_slice_cloned_mid_panic() {

#[test]
fn uninit_write_slice_cloned_no_drop() {
let rc = Rc::new(());
#[derive(Clone)]
struct Bomb;

impl Drop for Bomb {
fn drop(&mut self) {
panic!("dropped a bomb! kaboom")
}
}

let mut dst = [MaybeUninit::uninit()];
let src = [rc.clone()];
let src = [Bomb];

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

drop(src);

assert_eq!(Rc::strong_count(&rc), 2);
forget(src);
}

0 comments on commit 01f36c5

Please sign in to comment.