mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 05:51:58 +00:00
Rollup merge of #130966 - RalfJung:ptr-metadata-const-stable, r=scottmcm
make ptr metadata functions callable from stable const fn So far this was done with a bunch of `rustc_allow_const_fn_unstable`. But those should be the exception, not the norm. If we are confident we can expose the ptr metadata APIs *indirectly* in stable const fn, we should just mark them as `rustc_const_stable`. And we better be confident we can do that since it's already been done a while ago. ;) In particular this marks two intrinsics as const-stable: `aggregate_raw_ptr`, `ptr_metadata`. This should be uncontroversial, they are trivial to implement in the interpreter. Cc `@rust-lang/wg-const-eval` `@rust-lang/lang`
This commit is contained in:
commit
a0637597b4
@ -3165,7 +3165,7 @@ pub const fn type_id<T: ?Sized + 'static>() -> u128 {
|
|||||||
/// change the possible layouts of pointers.
|
/// change the possible layouts of pointers.
|
||||||
#[rustc_nounwind]
|
#[rustc_nounwind]
|
||||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||||
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
|
#[rustc_const_stable(feature = "ptr_metadata_const", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[rustc_intrinsic]
|
#[rustc_intrinsic]
|
||||||
#[rustc_intrinsic_must_be_overridden]
|
#[rustc_intrinsic_must_be_overridden]
|
||||||
pub const fn aggregate_raw_ptr<P: AggregateRawPtr<D, Metadata = M>, D, M>(_data: D, _meta: M) -> P {
|
pub const fn aggregate_raw_ptr<P: AggregateRawPtr<D, Metadata = M>, D, M>(_data: D, _meta: M) -> P {
|
||||||
@ -3190,7 +3190,7 @@ impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*mut T> for *mut P {
|
|||||||
/// This is used to implement functions like `ptr::metadata`.
|
/// This is used to implement functions like `ptr::metadata`.
|
||||||
#[rustc_nounwind]
|
#[rustc_nounwind]
|
||||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||||
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
|
#[rustc_const_stable(feature = "ptr_metadata_const", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[rustc_intrinsic]
|
#[rustc_intrinsic]
|
||||||
#[rustc_intrinsic_must_be_overridden]
|
#[rustc_intrinsic_must_be_overridden]
|
||||||
pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(_ptr: *const P) -> M {
|
pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(_ptr: *const P) -> M {
|
||||||
|
@ -92,7 +92,7 @@ impl<T: ?Sized> *const T {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "set_ptr_value", issue = "75091")]
|
#[unstable(feature = "set_ptr_value", issue = "75091")]
|
||||||
#[rustc_const_unstable(feature = "set_ptr_value", issue = "75091")]
|
#[rustc_const_stable(feature = "ptr_metadata_const", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[must_use = "returns a new pointer rather than modifying its argument"]
|
#[must_use = "returns a new pointer rather than modifying its argument"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn with_metadata_of<U>(self, meta: *const U) -> *const U
|
pub const fn with_metadata_of<U>(self, meta: *const U) -> *const U
|
||||||
@ -412,7 +412,6 @@ impl<T: ?Sized> *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn byte_offset(self, count: isize) -> Self {
|
pub const unsafe fn byte_offset(self, count: isize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `offset`.
|
// SAFETY: the caller must uphold the safety contract for `offset`.
|
||||||
@ -495,7 +494,6 @@ impl<T: ?Sized> *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
|
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
|
||||||
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
|
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
|
||||||
}
|
}
|
||||||
@ -645,7 +643,6 @@ impl<T: ?Sized> *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize {
|
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize {
|
||||||
// SAFETY: the caller must uphold the safety contract for `offset_from`.
|
// SAFETY: the caller must uphold the safety contract for `offset_from`.
|
||||||
@ -873,7 +870,6 @@ impl<T: ?Sized> *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn byte_add(self, count: usize) -> Self {
|
pub const unsafe fn byte_add(self, count: usize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `add`.
|
// SAFETY: the caller must uphold the safety contract for `add`.
|
||||||
@ -956,7 +952,6 @@ impl<T: ?Sized> *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn byte_sub(self, count: usize) -> Self {
|
pub const unsafe fn byte_sub(self, count: usize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `sub`.
|
// SAFETY: the caller must uphold the safety contract for `sub`.
|
||||||
@ -1039,7 +1034,6 @@ impl<T: ?Sized> *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
pub const fn wrapping_byte_add(self, count: usize) -> Self {
|
pub const fn wrapping_byte_add(self, count: usize) -> Self {
|
||||||
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
|
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
|
||||||
}
|
}
|
||||||
@ -1120,7 +1114,6 @@ impl<T: ?Sized> *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
|
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
|
||||||
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
|
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
|
||||||
}
|
}
|
||||||
@ -1554,7 +1547,6 @@ impl<T> *const [T] {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "slice_ptr_len", since = "1.79.0")]
|
#[stable(feature = "slice_ptr_len", since = "1.79.0")]
|
||||||
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "1.79.0")]
|
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "1.79.0")]
|
||||||
#[rustc_allow_const_fn_unstable(ptr_metadata)]
|
|
||||||
pub const fn len(self) -> usize {
|
pub const fn len(self) -> usize {
|
||||||
metadata(self)
|
metadata(self)
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ pub trait Thin = Pointee<Metadata = ()>;
|
|||||||
///
|
///
|
||||||
/// assert_eq!(std::ptr::metadata("foo"), 3_usize);
|
/// assert_eq!(std::ptr::metadata("foo"), 3_usize);
|
||||||
/// ```
|
/// ```
|
||||||
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
|
#[rustc_const_stable(feature = "ptr_metadata_const", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {
|
pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {
|
||||||
ptr_metadata(ptr)
|
ptr_metadata(ptr)
|
||||||
@ -106,7 +106,7 @@ pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {
|
|||||||
///
|
///
|
||||||
/// [`slice::from_raw_parts`]: crate::slice::from_raw_parts
|
/// [`slice::from_raw_parts`]: crate::slice::from_raw_parts
|
||||||
#[unstable(feature = "ptr_metadata", issue = "81513")]
|
#[unstable(feature = "ptr_metadata", issue = "81513")]
|
||||||
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
|
#[rustc_const_stable(feature = "ptr_metadata_const", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_raw_parts<T: ?Sized>(
|
pub const fn from_raw_parts<T: ?Sized>(
|
||||||
data_pointer: *const impl Thin,
|
data_pointer: *const impl Thin,
|
||||||
@ -120,7 +120,7 @@ pub const fn from_raw_parts<T: ?Sized>(
|
|||||||
///
|
///
|
||||||
/// See the documentation of [`from_raw_parts`] for more details.
|
/// See the documentation of [`from_raw_parts`] for more details.
|
||||||
#[unstable(feature = "ptr_metadata", issue = "81513")]
|
#[unstable(feature = "ptr_metadata", issue = "81513")]
|
||||||
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
|
#[rustc_const_stable(feature = "ptr_metadata_const", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_raw_parts_mut<T: ?Sized>(
|
pub const fn from_raw_parts_mut<T: ?Sized>(
|
||||||
data_pointer: *mut impl Thin,
|
data_pointer: *mut impl Thin,
|
||||||
|
@ -599,7 +599,6 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_promotable]
|
#[rustc_promotable]
|
||||||
#[rustc_const_stable(feature = "const_ptr_null", since = "1.24.0")]
|
#[rustc_const_stable(feature = "const_ptr_null", since = "1.24.0")]
|
||||||
#[rustc_allow_const_fn_unstable(ptr_metadata)]
|
|
||||||
#[rustc_diagnostic_item = "ptr_null"]
|
#[rustc_diagnostic_item = "ptr_null"]
|
||||||
pub const fn null<T: ?Sized + Thin>() -> *const T {
|
pub const fn null<T: ?Sized + Thin>() -> *const T {
|
||||||
from_raw_parts(without_provenance::<()>(0), ())
|
from_raw_parts(without_provenance::<()>(0), ())
|
||||||
@ -625,7 +624,6 @@ pub const fn null<T: ?Sized + Thin>() -> *const T {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_promotable]
|
#[rustc_promotable]
|
||||||
#[rustc_const_stable(feature = "const_ptr_null", since = "1.24.0")]
|
#[rustc_const_stable(feature = "const_ptr_null", since = "1.24.0")]
|
||||||
#[rustc_allow_const_fn_unstable(ptr_metadata)]
|
|
||||||
#[rustc_diagnostic_item = "ptr_null_mut"]
|
#[rustc_diagnostic_item = "ptr_null_mut"]
|
||||||
pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
|
pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
|
||||||
from_raw_parts_mut(without_provenance_mut::<()>(0), ())
|
from_raw_parts_mut(without_provenance_mut::<()>(0), ())
|
||||||
@ -949,7 +947,6 @@ pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "slice_from_raw_parts", since = "1.42.0")]
|
#[stable(feature = "slice_from_raw_parts", since = "1.42.0")]
|
||||||
#[rustc_const_stable(feature = "const_slice_from_raw_parts", since = "1.64.0")]
|
#[rustc_const_stable(feature = "const_slice_from_raw_parts", since = "1.64.0")]
|
||||||
#[rustc_allow_const_fn_unstable(ptr_metadata)]
|
|
||||||
#[rustc_diagnostic_item = "ptr_slice_from_raw_parts"]
|
#[rustc_diagnostic_item = "ptr_slice_from_raw_parts"]
|
||||||
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
|
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
|
||||||
from_raw_parts(data, len)
|
from_raw_parts(data, len)
|
||||||
|
@ -74,7 +74,7 @@ impl<T: ?Sized> *mut T {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "set_ptr_value", issue = "75091")]
|
#[unstable(feature = "set_ptr_value", issue = "75091")]
|
||||||
#[rustc_const_unstable(feature = "set_ptr_value", issue = "75091")]
|
#[rustc_const_stable(feature = "ptr_metadata_const", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[must_use = "returns a new pointer rather than modifying its argument"]
|
#[must_use = "returns a new pointer rather than modifying its argument"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn with_metadata_of<U>(self, meta: *const U) -> *mut U
|
pub const fn with_metadata_of<U>(self, meta: *const U) -> *mut U
|
||||||
@ -412,7 +412,6 @@ impl<T: ?Sized> *mut T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn byte_offset(self, count: isize) -> Self {
|
pub const unsafe fn byte_offset(self, count: isize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `offset`.
|
// SAFETY: the caller must uphold the safety contract for `offset`.
|
||||||
@ -492,7 +491,6 @@ impl<T: ?Sized> *mut T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
|
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
|
||||||
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
|
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
|
||||||
}
|
}
|
||||||
@ -808,7 +806,6 @@ impl<T: ?Sized> *mut T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize {
|
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize {
|
||||||
// SAFETY: the caller must uphold the safety contract for `offset_from`.
|
// SAFETY: the caller must uphold the safety contract for `offset_from`.
|
||||||
@ -954,7 +951,6 @@ impl<T: ?Sized> *mut T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn byte_add(self, count: usize) -> Self {
|
pub const unsafe fn byte_add(self, count: usize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `add`.
|
// SAFETY: the caller must uphold the safety contract for `add`.
|
||||||
@ -1037,7 +1033,6 @@ impl<T: ?Sized> *mut T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn byte_sub(self, count: usize) -> Self {
|
pub const unsafe fn byte_sub(self, count: usize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `sub`.
|
// SAFETY: the caller must uphold the safety contract for `sub`.
|
||||||
@ -1118,7 +1113,6 @@ impl<T: ?Sized> *mut T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
pub const fn wrapping_byte_add(self, count: usize) -> Self {
|
pub const fn wrapping_byte_add(self, count: usize) -> Self {
|
||||||
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
|
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
|
||||||
}
|
}
|
||||||
@ -1197,7 +1191,6 @@ impl<T: ?Sized> *mut T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
#[stable(feature = "pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "1.75.0")]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
|
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
|
||||||
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
|
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
|
||||||
}
|
}
|
||||||
@ -1804,7 +1797,6 @@ impl<T> *mut [T] {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "slice_ptr_len", since = "1.79.0")]
|
#[stable(feature = "slice_ptr_len", since = "1.79.0")]
|
||||||
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "1.79.0")]
|
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "1.79.0")]
|
||||||
#[rustc_allow_const_fn_unstable(ptr_metadata)]
|
|
||||||
pub const fn len(self) -> usize {
|
pub const fn len(self) -> usize {
|
||||||
metadata(self)
|
metadata(self)
|
||||||
}
|
}
|
||||||
|
@ -567,7 +567,6 @@ impl<T: ?Sized> NonNull<T> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[stable(feature = "non_null_convenience", since = "1.80.0")]
|
#[stable(feature = "non_null_convenience", since = "1.80.0")]
|
||||||
#[rustc_const_stable(feature = "non_null_convenience", since = "1.80.0")]
|
#[rustc_const_stable(feature = "non_null_convenience", since = "1.80.0")]
|
||||||
pub const unsafe fn byte_add(self, count: usize) -> Self {
|
pub const unsafe fn byte_add(self, count: usize) -> Self {
|
||||||
@ -651,7 +650,6 @@ impl<T: ?Sized> NonNull<T> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[stable(feature = "non_null_convenience", since = "1.80.0")]
|
#[stable(feature = "non_null_convenience", since = "1.80.0")]
|
||||||
#[rustc_const_stable(feature = "non_null_convenience", since = "1.80.0")]
|
#[rustc_const_stable(feature = "non_null_convenience", since = "1.80.0")]
|
||||||
pub const unsafe fn byte_sub(self, count: usize) -> Self {
|
pub const unsafe fn byte_sub(self, count: usize) -> Self {
|
||||||
|
@ -111,7 +111,6 @@ impl<T> [T] {
|
|||||||
#[lang = "slice_len_fn"]
|
#[lang = "slice_len_fn"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
|
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
|
||||||
#[rustc_allow_const_fn_unstable(ptr_metadata)]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn len(&self) -> usize {
|
pub const fn len(&self) -> usize {
|
||||||
|
13
tests/ui/consts/auxiliary/unstable_but_const_stable.rs
Normal file
13
tests/ui/consts/auxiliary/unstable_but_const_stable.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#![feature(staged_api, rustc_attrs, intrinsics)]
|
||||||
|
#![stable(since="1.0.0", feature = "stable")]
|
||||||
|
|
||||||
|
extern "rust-intrinsic" {
|
||||||
|
#[unstable(feature = "unstable", issue = "42")]
|
||||||
|
#[rustc_const_stable(feature = "stable", since = "1.0.0")]
|
||||||
|
#[rustc_nounwind]
|
||||||
|
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "unstable", issue = "42")]
|
||||||
|
#[rustc_const_stable(feature = "stable", since = "1.0.0")]
|
||||||
|
pub const fn some_unstable_fn() {}
|
14
tests/ui/consts/unstable-const-stable.rs
Normal file
14
tests/ui/consts/unstable-const-stable.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//@ aux-build:unstable_but_const_stable.rs
|
||||||
|
|
||||||
|
extern crate unstable_but_const_stable;
|
||||||
|
use unstable_but_const_stable::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
some_unstable_fn(); //~ERROR use of unstable library feature
|
||||||
|
unsafe { write_bytes(4 as *mut u8, 0, 0) }; //~ERROR use of unstable library feature
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn const_main() {
|
||||||
|
some_unstable_fn(); //~ERROR use of unstable library feature
|
||||||
|
unsafe { write_bytes(4 as *mut u8, 0, 0) }; //~ERROR use of unstable library feature
|
||||||
|
}
|
43
tests/ui/consts/unstable-const-stable.stderr
Normal file
43
tests/ui/consts/unstable-const-stable.stderr
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
error[E0658]: use of unstable library feature 'unstable'
|
||||||
|
--> $DIR/unstable-const-stable.rs:7:5
|
||||||
|
|
|
||||||
|
LL | some_unstable_fn();
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
|
||||||
|
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error[E0658]: use of unstable library feature 'unstable'
|
||||||
|
--> $DIR/unstable-const-stable.rs:8:14
|
||||||
|
|
|
||||||
|
LL | unsafe { write_bytes(4 as *mut u8, 0, 0) };
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
|
||||||
|
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error[E0658]: use of unstable library feature 'unstable'
|
||||||
|
--> $DIR/unstable-const-stable.rs:12:5
|
||||||
|
|
|
||||||
|
LL | some_unstable_fn();
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
|
||||||
|
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error[E0658]: use of unstable library feature 'unstable'
|
||||||
|
--> $DIR/unstable-const-stable.rs:13:14
|
||||||
|
|
|
||||||
|
LL | unsafe { write_bytes(4 as *mut u8, 0, 0) };
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
|
||||||
|
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0658`.
|
Loading…
Reference in New Issue
Block a user