mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 14:31:55 +00:00
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](d573564575/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]`.
This commit is contained in:
commit
72651306b3
@ -1344,6 +1344,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
|
||||
/// 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 {
|
||||
@ -2985,7 +2986,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
|
||||
///
|
||||
/// [`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();
|
||||
|
@ -2719,7 +2719,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
|
||||
///
|
||||
/// [`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();
|
||||
|
Loading…
Reference in New Issue
Block a user