From cac890232edf75f4c187e0c7af9cd52bccd3a411 Mon Sep 17 00:00:00 2001 From: Zachary S Date: Sat, 6 Jul 2024 22:24:00 -0500 Subject: [PATCH] Remove non-focused memory leaks in `alloc` doctests for Miri. --- alloc/src/rc.rs | 6 ++++++ alloc/src/sync.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/alloc/src/rc.rs b/alloc/src/rc.rs index 3745ecb48c18e..9f2bff9844906 100644 --- a/alloc/src/rc.rs +++ b/alloc/src/rc.rs @@ -1287,6 +1287,8 @@ impl Rc { /// /// let five = Rc::from_raw(ptr); /// assert_eq!(2, Rc::strong_count(&five)); + /// # // Prevent leaks for Miri. + /// # Rc::decrement_strong_count(ptr); /// } /// ``` #[inline] @@ -1344,6 +1346,8 @@ impl Rc { /// let x = Rc::new("hello".to_owned()); /// let x_ptr = Rc::into_raw(x); /// assert_eq!(unsafe { &*x_ptr }, "hello"); + /// # // Prevent leaks for Miri. + /// # drop(unsafe { Rc::from_raw(x_ptr) }); /// ``` #[must_use = "losing the pointer will leak memory"] #[stable(feature = "rc_raw", since = "1.17.0")] @@ -1571,6 +1575,8 @@ impl Rc { /// /// let five = Rc::from_raw_in(ptr, System); /// assert_eq!(2, Rc::strong_count(&five)); + /// # // Prevent leaks for Miri. + /// # Rc::decrement_strong_count_in(ptr, System); /// } /// ``` #[inline] diff --git a/alloc/src/sync.rs b/alloc/src/sync.rs index 90672164cb932..6a591d24065c6 100644 --- a/alloc/src/sync.rs +++ b/alloc/src/sync.rs @@ -1428,6 +1428,8 @@ impl Arc { /// // the `Arc` between threads. /// let five = Arc::from_raw(ptr); /// assert_eq!(2, Arc::strong_count(&five)); + /// # // Prevent leaks for Miri. + /// # Arc::decrement_strong_count(ptr); /// } /// ``` #[inline] @@ -1487,6 +1489,8 @@ impl Arc { /// let x = Arc::new("hello".to_owned()); /// let x_ptr = Arc::into_raw(x); /// assert_eq!(unsafe { &*x_ptr }, "hello"); + /// # // Prevent leaks for Miri. + /// # drop(unsafe { Arc::from_raw(x_ptr) }); /// ``` #[must_use = "losing the pointer will leak memory"] #[stable(feature = "rc_raw", since = "1.17.0")] @@ -1769,6 +1773,8 @@ impl Arc { /// // the `Arc` between threads. /// let five = Arc::from_raw_in(ptr, System); /// assert_eq!(2, Arc::strong_count(&five)); + /// # // Prevent leaks for Miri. + /// # Arc::decrement_strong_count_in(ptr, System); /// } /// ``` #[inline]