From 5515bbad98413205af44c3e8e0efcd885c5aa0ca Mon Sep 17 00:00:00 2001 From: Zachary S Date: Sat, 6 Jul 2024 22:53:51 -0500 Subject: [PATCH] Mitigate focused memory leaks in `core` doctests for Miri. If/when `-Zmiri-disable-leak-check` is able to be used at test-granularity, it should applied to these tests instead of unleaking. --- core/src/mem/manually_drop.rs | 3 +++ core/src/mem/maybe_uninit.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/src/mem/manually_drop.rs b/core/src/mem/manually_drop.rs index e0c3b9f3b51da..997f088c6d687 100644 --- a/core/src/mem/manually_drop.rs +++ b/core/src/mem/manually_drop.rs @@ -62,6 +62,9 @@ impl ManuallyDrop { /// x.truncate(5); // You can still safely operate on the value /// assert_eq!(*x, "Hello"); /// // But `Drop` will not be run here + /// # // FIXME(/~https://github.com/rust-lang/miri/issues/3670): + /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak. + /// # let _ = ManuallyDrop::into_inner(x); /// ``` #[must_use = "if you don't need the wrapper, you can use `mem::forget` instead"] #[stable(feature = "manually_drop", since = "1.20.0")] diff --git a/core/src/mem/maybe_uninit.rs b/core/src/mem/maybe_uninit.rs index a8d03ef2611a4..dd40f57dc8707 100644 --- a/core/src/mem/maybe_uninit.rs +++ b/core/src/mem/maybe_uninit.rs @@ -448,6 +448,9 @@ impl MaybeUninit { /// let mut x = MaybeUninit::::uninit(); /// /// x.write("Hello".to_string()); + /// # // FIXME(/~https://github.com/rust-lang/miri/issues/3670): + /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak. + /// # unsafe { MaybeUninit::assume_init_drop(&mut x); } /// // This leaks the contained string: /// x.write("hello".to_string()); /// // x is initialized now: