Rollup merge of #130164 - RalfJung:const_ptr_as_ref, r=dtolnay
move some const fn out of the const_ptr_as_ref feature When a `const fn` is still `#[unstable]`, it should generally use the same feature to track its regular stability and const-stability. Then when that feature moves towards stabilization we can decide whether the const-ness can be stabilized as well, or whether it should be moved into a new feature. Also, functions like `ptr::as_ref` (which returns an `Option<&mut T>`) require `is_null`, which is tricky and blocked on some design concerns (see #74939). So move those to the is_null feature gate, as they should be stabilized together with `ptr.is_null()`. Affects #91822, #122034, #75402, https://github.com/rust-lang/rust/issues/74939
This commit is contained in:
commit
9749a9801c
@ -270,7 +270,7 @@ pub const fn to_raw_parts(self) -> (*const (), <T as super::Pointee>::Metadata)
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_is_null", issue = "74939")]
|
||||
#[inline]
|
||||
pub const unsafe fn as_ref<'a>(self) -> Option<&'a T> {
|
||||
// SAFETY: the caller must guarantee that `self` is valid
|
||||
@ -302,7 +302,7 @@ pub const fn to_raw_parts(self) -> (*const (), <T as super::Pointee>::Metadata)
|
||||
/// ```
|
||||
// FIXME: mention it in the docs for `as_ref` and `as_uninit_ref` once stabilized.
|
||||
#[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const unsafe fn as_ref_unchecked<'a>(self) -> &'a T {
|
||||
@ -336,7 +336,7 @@ pub const fn to_raw_parts(self) -> (*const (), <T as super::Pointee>::Metadata)
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_ref<'a>(self) -> Option<&'a MaybeUninit<T>>
|
||||
where
|
||||
T: Sized,
|
||||
@ -1664,7 +1664,7 @@ pub unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output
|
||||
/// [allocated object]: crate::ptr#allocated-object
|
||||
#[inline]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]> {
|
||||
if self.is_null() {
|
||||
None
|
||||
|
@ -261,7 +261,7 @@ pub const fn to_raw_parts(self) -> (*mut (), <T as super::Pointee>::Metadata) {
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_is_null", issue = "74939")]
|
||||
#[inline]
|
||||
pub const unsafe fn as_ref<'a>(self) -> Option<&'a T> {
|
||||
// SAFETY: the caller must guarantee that `self` is valid for a
|
||||
@ -295,7 +295,7 @@ pub const fn to_raw_parts(self) -> (*mut (), <T as super::Pointee>::Metadata) {
|
||||
/// ```
|
||||
// FIXME: mention it in the docs for `as_ref` and `as_uninit_ref` once stabilized.
|
||||
#[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const unsafe fn as_ref_unchecked<'a>(self) -> &'a T {
|
||||
@ -334,7 +334,7 @@ pub const fn to_raw_parts(self) -> (*mut (), <T as super::Pointee>::Metadata) {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_ref<'a>(self) -> Option<&'a MaybeUninit<T>>
|
||||
where
|
||||
T: Sized,
|
||||
@ -580,7 +580,7 @@ pub fn mask(self, mask: usize) -> *mut T {
|
||||
/// println!("{s:?}"); // It'll print: "[4, 2, 3]".
|
||||
/// ```
|
||||
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_is_null", issue = "74939")]
|
||||
#[inline]
|
||||
pub const unsafe fn as_mut<'a>(self) -> Option<&'a mut T> {
|
||||
// SAFETY: the caller must guarantee that `self` is be valid for
|
||||
@ -616,7 +616,7 @@ pub fn mask(self, mask: usize) -> *mut T {
|
||||
/// ```
|
||||
// FIXME: mention it in the docs for `as_mut` and `as_uninit_mut` once stabilized.
|
||||
#[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const unsafe fn as_mut_unchecked<'a>(self) -> &'a mut T {
|
||||
@ -639,7 +639,7 @@ pub fn mask(self, mask: usize) -> *mut T {
|
||||
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
|
||||
#[inline]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_mut<'a>(self) -> Option<&'a mut MaybeUninit<T>>
|
||||
where
|
||||
T: Sized,
|
||||
@ -2016,7 +2016,7 @@ pub unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
|
||||
/// [allocated object]: crate::ptr#allocated-object
|
||||
#[inline]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]> {
|
||||
if self.is_null() {
|
||||
None
|
||||
@ -2068,7 +2068,7 @@ pub unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
|
||||
/// [allocated object]: crate::ptr#allocated-object
|
||||
#[inline]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_slice_mut<'a>(self) -> Option<&'a mut [MaybeUninit<T>]> {
|
||||
if self.is_null() {
|
||||
None
|
||||
|
@ -133,7 +133,7 @@ pub const fn dangling() -> Self {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_ref<'a>(self) -> &'a MaybeUninit<T> {
|
||||
// SAFETY: the caller must guarantee that `self` meets all the
|
||||
// requirements for a reference.
|
||||
@ -157,7 +157,7 @@ pub const fn dangling() -> Self {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_mut<'a>(self) -> &'a mut MaybeUninit<T> {
|
||||
// SAFETY: the caller must guarantee that `self` meets all the
|
||||
// requirements for a reference.
|
||||
@ -1563,7 +1563,7 @@ pub const fn as_mut_ptr(self) -> *mut T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_slice<'a>(self) -> &'a [MaybeUninit<T>] {
|
||||
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice`.
|
||||
unsafe { slice::from_raw_parts(self.cast().as_ptr(), self.len()) }
|
||||
@ -1628,7 +1628,7 @@ pub const fn as_mut_ptr(self) -> *mut T {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
|
||||
pub const unsafe fn as_uninit_slice_mut<'a>(self) -> &'a mut [MaybeUninit<T>] {
|
||||
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`.
|
||||
unsafe { slice::from_raw_parts_mut(self.cast().as_ptr(), self.len()) }
|
||||
|
Loading…
Reference in New Issue
Block a user