From 261da5fc4b2f015436a206f217300f6616628052 Mon Sep 17 00:00:00 2001 From: Zachary S Date: Sun, 18 Feb 2024 22:43:42 -0600 Subject: [PATCH] Clarify/add `must_use` message for Rc/Arc/Weak::into_raw. --- library/alloc/src/rc.rs | 3 ++- library/alloc/src/sync.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 2cc38d90ffe4d..c6ce42e7aa76c 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1329,6 +1329,7 @@ impl Rc { /// let x_ptr = Rc::into_raw(x); /// assert_eq!(unsafe { &*x_ptr }, "hello"); /// ``` + #[must_use = "losing the pointer will leak memory"] #[stable(feature = "rc_raw", since = "1.17.0")] #[rustc_never_returns_null_ptr] pub fn into_raw(this: Self) -> *const T { @@ -2966,7 +2967,7 @@ impl Weak { /// /// [`from_raw`]: Weak::from_raw /// [`as_ptr`]: Weak::as_ptr - #[must_use = "`self` will be dropped if the result is not used"] + #[must_use = "losing the pointer will leak memory"] #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn into_raw(self) -> *const T { let result = self.as_ptr(); diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index e1211da4c6176..c7c38d9b45e94 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -2715,7 +2715,7 @@ impl Weak { /// /// [`from_raw`]: Weak::from_raw /// [`as_ptr`]: Weak::as_ptr - #[must_use = "`self` will be dropped if the result is not used"] + #[must_use = "losing the pointer will leak memory"] #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn into_raw(self) -> *const T { let result = self.as_ptr();