Skip to content

Commit

Permalink
Stabilize [const_]pointer_byte_offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Sep 27, 2023
1 parent d4589a4 commit b812c12
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 37 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#![feature(maybe_uninit_slice)]
#![feature(min_specialization)]
#![feature(decl_macro)]
#![feature(pointer_byte_offsets)]
#![feature(rustc_attrs)]
#![cfg_attr(test, feature(test))]
#![feature(strict_provenance)]
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_uninit_array_transpose)]
#![feature(pattern)]
#![feature(pointer_byte_offsets)]
#![feature(ptr_internals)]
#![feature(ptr_metadata)]
#![feature(ptr_sub_ptr)]
Expand Down
35 changes: 21 additions & 14 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,9 @@ impl<T: ?Sized> *const T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_offset(self, count: isize) -> Self {
// SAFETY: the caller must uphold the safety contract for `offset`.
Expand Down Expand Up @@ -560,8 +561,9 @@ impl<T: ?Sized> *const T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -709,8 +711,9 @@ impl<T: ?Sized> *const T {
/// For non-`Sized` pointees this operation considers only the data pointers,
/// ignoring the metadata.
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[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 {
// SAFETY: the caller must uphold the safety contract for `offset_from`.
Expand Down Expand Up @@ -935,8 +938,9 @@ impl<T: ?Sized> *const T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_add(self, count: usize) -> Self {
// SAFETY: the caller must uphold the safety contract for `add`.
Expand Down Expand Up @@ -1028,8 +1032,9 @@ impl<T: ?Sized> *const T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_sub(self, count: usize) -> Self {
// SAFETY: the caller must uphold the safety contract for `sub`.
Expand Down Expand Up @@ -1108,8 +1113,9 @@ impl<T: ?Sized> *const T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
pub const fn wrapping_byte_add(self, count: usize) -> Self {
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -1186,8 +1192,9 @@ impl<T: ?Sized> *const T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
}
Expand Down
35 changes: 21 additions & 14 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,9 @@ impl<T: ?Sized> *mut T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_offset(self, count: isize) -> Self {
// SAFETY: the caller must uphold the safety contract for `offset`.
Expand Down Expand Up @@ -574,8 +575,9 @@ impl<T: ?Sized> *mut T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -881,8 +883,9 @@ impl<T: ?Sized> *mut T {
/// For non-`Sized` pointees this operation considers only the data pointers,
/// ignoring the metadata.
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[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 {
// SAFETY: the caller must uphold the safety contract for `offset_from`.
Expand Down Expand Up @@ -1036,8 +1039,9 @@ impl<T: ?Sized> *mut T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_add(self, count: usize) -> Self {
// SAFETY: the caller must uphold the safety contract for `add`.
Expand Down Expand Up @@ -1129,8 +1133,9 @@ impl<T: ?Sized> *mut T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_sub(self, count: usize) -> Self {
// SAFETY: the caller must uphold the safety contract for `sub`.
Expand Down Expand Up @@ -1209,8 +1214,9 @@ impl<T: ?Sized> *mut T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
pub const fn wrapping_byte_add(self, count: usize) -> Self {
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -1287,8 +1293,9 @@ impl<T: ?Sized> *mut T {
/// leaving the metadata untouched.
#[must_use]
#[inline(always)]
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(ptr_metadata)]
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
}
Expand Down
2 changes: 0 additions & 2 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_maybe_uninit_assume_init_read)]
#![feature(const_nonnull_new)]
#![feature(const_pointer_byte_offsets)]
#![feature(const_pointer_is_aligned)]
#![feature(const_ptr_as_ref)]
#![feature(const_ptr_write)]
Expand Down Expand Up @@ -86,7 +85,6 @@
#![feature(const_waker)]
#![feature(never_type)]
#![feature(unwrap_infallible)]
#![feature(pointer_byte_offsets)]
#![feature(pointer_is_aligned)]
#![feature(portable_simd)]
#![feature(ptr_metadata)]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@
#![feature(panic_can_unwind)]
#![feature(panic_info_message)]
#![feature(panic_internals)]
#![feature(pointer_byte_offsets)]
#![feature(pointer_is_aligned)]
#![feature(portable_simd)]
#![feature(prelude_2024)]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/const-ptr/allowed_slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#![feature(
slice_from_ptr_range,
const_slice_from_ptr_range,
pointer_byte_offsets,
const_pointer_byte_offsets
)]
use std::{
mem::MaybeUninit,
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/const-ptr/forbidden_slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#![feature(
slice_from_ptr_range,
const_slice_from_ptr_range,
pointer_byte_offsets,
const_pointer_byte_offsets
)]
use std::{
mem::{size_of, MaybeUninit},
Expand Down

0 comments on commit b812c12

Please sign in to comment.