Skip to content

Commit

Permalink
Rollup merge of rust-lang#80123 - DrMeepster:maybe_uninit_write_slice…
Browse files Browse the repository at this point in the history
…, r=RalfJung

Fix memory leak in test "mem::uninit_write_slice_cloned_no_drop"

This fixes rust-lang#80116. I replaced the `Rc` based method I was using with a type that panics when dropped.
  • Loading branch information
Dylan-DPC authored Dec 20, 2020
2 parents 74afda1 + 28e0d2f commit 9fdd80c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions library/core/tests/mem.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::mem::*;

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

#[test]
Expand Down Expand Up @@ -250,14 +251,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 9fdd80c

Please sign in to comment.