Skip to content

Commit 0f9b7bd

Browse files
authored
Rollup merge of #74902 - rust-lang:into_raw_non_null, r=dtolnay
Remove deprecated unstable `{Box,Rc,Arc}::into_raw_non_null` functions FCP: #47336 (comment)
2 parents e6b0376 + 1fb6736 commit 0f9b7bd

File tree

3 files changed

+1
-91
lines changed

3 files changed

+1
-91
lines changed

library/alloc/src/boxed.rs

+1-45
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ use core::ops::{
143143
CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver,
144144
};
145145
use core::pin::Pin;
146-
use core::ptr::{self, NonNull, Unique};
146+
use core::ptr::{self, Unique};
147147
use core::task::{Context, Poll};
148148

149149
use crate::alloc::{self, AllocInit, AllocRef, Global};
@@ -451,50 +451,6 @@ impl<T: ?Sized> Box<T> {
451451
Box::leak(b) as *mut T
452452
}
453453

454-
/// Consumes the `Box`, returning the wrapped pointer as `NonNull<T>`.
455-
///
456-
/// After calling this function, the caller is responsible for the
457-
/// memory previously managed by the `Box`. In particular, the
458-
/// caller should properly destroy `T` and release the memory. The
459-
/// easiest way to do so is to convert the `NonNull<T>` pointer
460-
/// into a raw pointer and back into a `Box` with the [`Box::from_raw`]
461-
/// function.
462-
///
463-
/// Note: this is an associated function, which means that you have
464-
/// to call it as `Box::into_raw_non_null(b)`
465-
/// instead of `b.into_raw_non_null()`. This
466-
/// is so that there is no conflict with a method on the inner type.
467-
///
468-
/// [`Box::from_raw`]: struct.Box.html#method.from_raw
469-
///
470-
/// # Examples
471-
///
472-
/// ```
473-
/// #![feature(box_into_raw_non_null)]
474-
/// #![allow(deprecated)]
475-
///
476-
/// let x = Box::new(5);
477-
/// let ptr = Box::into_raw_non_null(x);
478-
///
479-
/// // Clean up the memory by converting the NonNull pointer back
480-
/// // into a Box and letting the Box be dropped.
481-
/// let x = unsafe { Box::from_raw(ptr.as_ptr()) };
482-
/// ```
483-
#[unstable(feature = "box_into_raw_non_null", issue = "47336")]
484-
#[rustc_deprecated(
485-
since = "1.44.0",
486-
reason = "use `Box::leak(b).into()` or `NonNull::from(Box::leak(b))` instead"
487-
)]
488-
#[inline]
489-
pub fn into_raw_non_null(b: Box<T>) -> NonNull<T> {
490-
// Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
491-
// raw pointer for the type system. Turning it directly into a raw pointer would not be
492-
// recognized as "releasing" the unique pointer to permit aliased raw accesses,
493-
// so all raw pointer methods go through `leak` which creates a (unique)
494-
// mutable reference. Turning *that* to a raw pointer behaves correctly.
495-
Box::leak(b).into()
496-
}
497-
498454
#[unstable(
499455
feature = "ptr_internals",
500456
issue = "none",

library/alloc/src/rc.rs

-23
Original file line numberDiff line numberDiff line change
@@ -645,29 +645,6 @@ impl<T: ?Sized> Rc<T> {
645645
unsafe { Self::from_ptr(rc_ptr) }
646646
}
647647

648-
/// Consumes the `Rc`, returning the wrapped pointer as `NonNull<T>`.
649-
///
650-
/// # Examples
651-
///
652-
/// ```
653-
/// #![feature(rc_into_raw_non_null)]
654-
/// #![allow(deprecated)]
655-
///
656-
/// use std::rc::Rc;
657-
///
658-
/// let x = Rc::new("hello".to_owned());
659-
/// let ptr = Rc::into_raw_non_null(x);
660-
/// let deref = unsafe { ptr.as_ref() };
661-
/// assert_eq!(deref, "hello");
662-
/// ```
663-
#[unstable(feature = "rc_into_raw_non_null", issue = "47336")]
664-
#[rustc_deprecated(since = "1.44.0", reason = "use `Rc::into_raw` instead")]
665-
#[inline]
666-
pub fn into_raw_non_null(this: Self) -> NonNull<T> {
667-
// safe because Rc guarantees its pointer is non-null
668-
unsafe { NonNull::new_unchecked(Rc::into_raw(this) as *mut _) }
669-
}
670-
671648
/// Creates a new [`Weak`][weak] pointer to this allocation.
672649
///
673650
/// [weak]: struct.Weak.html

library/alloc/src/sync.rs

-23
Original file line numberDiff line numberDiff line change
@@ -646,29 +646,6 @@ impl<T: ?Sized> Arc<T> {
646646
}
647647
}
648648

649-
/// Consumes the `Arc`, returning the wrapped pointer as `NonNull<T>`.
650-
///
651-
/// # Examples
652-
///
653-
/// ```
654-
/// #![feature(rc_into_raw_non_null)]
655-
/// #![allow(deprecated)]
656-
///
657-
/// use std::sync::Arc;
658-
///
659-
/// let x = Arc::new("hello".to_owned());
660-
/// let ptr = Arc::into_raw_non_null(x);
661-
/// let deref = unsafe { ptr.as_ref() };
662-
/// assert_eq!(deref, "hello");
663-
/// ```
664-
#[unstable(feature = "rc_into_raw_non_null", issue = "47336")]
665-
#[rustc_deprecated(since = "1.44.0", reason = "use `Arc::into_raw` instead")]
666-
#[inline]
667-
pub fn into_raw_non_null(this: Self) -> NonNull<T> {
668-
// safe because Arc guarantees its pointer is non-null
669-
unsafe { NonNull::new_unchecked(Arc::into_raw(this) as *mut _) }
670-
}
671-
672649
/// Creates a new [`Weak`][weak] pointer to this allocation.
673650
///
674651
/// [weak]: struct.Weak.html

0 commit comments

Comments
 (0)