Skip to content

Commit 7265130

Browse files
authored
Rollup merge of #121287 - zachs18:rc-into-raw-must-use, r=cuviper
Clarify/add `must_use` message for Rc/Arc/Weak::into_raw. The current `#[must_use]` messages for `{sync,rc}::Weak::into_raw` ("`self` will be dropped if the result is not used") are misleading, as `self` is consumed and will *not* be dropped. This PR changes their `#[must_use]` message to the same as `Arc::into_raw`'s[ current `#[must_use]` message](https://github.com/rust-lang/rust/blob/d5735645753e990a72446094f703df9b5e421555/library/alloc/src/sync.rs#L1482) ("losing the pointer will leak memory"), and also adds it to `Rc::into_raw`, which is not currently `#[must_use]`.
2 parents 22827fd + 261da5f commit 7265130

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

library/alloc/src/rc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
13441344
/// let x_ptr = Rc::into_raw(x);
13451345
/// assert_eq!(unsafe { &*x_ptr }, "hello");
13461346
/// ```
1347+
#[must_use = "losing the pointer will leak memory"]
13471348
#[stable(feature = "rc_raw", since = "1.17.0")]
13481349
#[rustc_never_returns_null_ptr]
13491350
pub fn into_raw(this: Self) -> *const T {
@@ -2985,7 +2986,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
29852986
///
29862987
/// [`from_raw`]: Weak::from_raw
29872988
/// [`as_ptr`]: Weak::as_ptr
2988-
#[must_use = "`self` will be dropped if the result is not used"]
2989+
#[must_use = "losing the pointer will leak memory"]
29892990
#[stable(feature = "weak_into_raw", since = "1.45.0")]
29902991
pub fn into_raw(self) -> *const T {
29912992
let result = self.as_ptr();

library/alloc/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
27192719
///
27202720
/// [`from_raw`]: Weak::from_raw
27212721
/// [`as_ptr`]: Weak::as_ptr
2722-
#[must_use = "`self` will be dropped if the result is not used"]
2722+
#[must_use = "losing the pointer will leak memory"]
27232723
#[stable(feature = "weak_into_raw", since = "1.45.0")]
27242724
pub fn into_raw(self) -> *const T {
27252725
let result = self.as_ptr();

0 commit comments

Comments
 (0)