about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-12-20 10:08:56 +0000
committerbors <bors@rust-lang.org>2020-12-20 10:08:56 +0000
commit59aaa2a04bbcc17c5c9495e9d995e1be73c1b969 (patch)
tree265e63410836c4b2025aa9ae0c4c40e2759a0da3
parentb1964e60b72c2d10e9fd4e801990f8af3f306ac0 (diff)
parent28e0d2f234973059bc0dce2aa4da140b2fae1fca (diff)
downloadrust-59aaa2a04bbcc17c5c9495e9d995e1be73c1b969.tar.gz
rust-59aaa2a04bbcc17c5c9495e9d995e1be73c1b969.zip
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.
-rw-r--r--library/core/tests/mem.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs
index 5e24fa690ef..5d0fedd4d9c 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]
@@ -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);
 }