From 01f36c51c2b6fd3a95b6cdfacff92725cd81d5b0 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Thu, 17 Dec 2020 09:18:06 -0800 Subject: [PATCH 1/2] fix memory leak in test --- library/core/tests/mem.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs index 5e24fa690ef52..86990fa0945a7 100644 --- a/library/core/tests/mem.rs +++ b/library/core/tests/mem.rs @@ -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); } From 28e0d2f234973059bc0dce2aa4da140b2fae1fca Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Fri, 18 Dec 2020 14:53:55 -0800 Subject: [PATCH 2/2] Fix unused import error on wasm --- library/core/tests/mem.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs index 86990fa0945a7..5d0fedd4d9ccc 100644 --- a/library/core/tests/mem.rs +++ b/library/core/tests/mem.rs @@ -1,5 +1,6 @@ use core::mem::*; +#[cfg(panic = "unwind")] use std::rc::Rc; #[test]