Skip to content

Commit

Permalink
Auto merge of rust-lang#116205 - WaffleLapkin:stabilize_pointer_byte_…
Browse files Browse the repository at this point in the history
…offsets, r=dtolnay

Stabilize `[const_]pointer_byte_offsets`

Closes rust-lang#96283
Awaiting FCP completion: rust-lang#96283 (comment)

r? libs-api
  • Loading branch information
bors committed Oct 27, 2023
2 parents 707d8c3 + fe97fdf commit 54e57e6
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 77 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 @@ -18,7 +18,6 @@
#![feature(new_uninit)]
#![feature(maybe_uninit_slice)]
#![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 @@ -141,7 +141,6 @@
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_uninit_array_transpose)]
#![feature(pattern)]
#![feature(pointer_byte_offsets)]
#![feature(ptr_addr_eq)]
#![feature(ptr_internals)]
#![feature(ptr_metadata)]
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
#![feature(const_option)]
#![feature(const_option_ext)]
#![feature(const_pin)]
#![feature(const_pointer_byte_offsets)]
#![feature(const_pointer_is_aligned)]
#![feature(const_ptr_as_ref)]
#![feature(const_ptr_is_null)]
Expand Down
37 changes: 21 additions & 16 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(set_ptr_value)]
#[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(set_ptr_value)]
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -726,8 +728,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(set_ptr_value)]
#[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 @@ -952,8 +955,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(set_ptr_value)]
#[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 @@ -1045,8 +1049,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(set_ptr_value)]
#[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 @@ -1125,8 +1130,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(set_ptr_value)]
pub const fn wrapping_byte_add(self, count: usize) -> Self {
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -1203,8 +1209,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(set_ptr_value)]
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -1372,7 +1379,6 @@ impl<T: ?Sized> *const T {
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(pointer_byte_offsets)]
///
/// // On some platforms, the alignment of i32 is less than 4.
/// #[repr(align(4))]
Expand Down Expand Up @@ -1494,7 +1500,6 @@ impl<T: ?Sized> *const T {
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(pointer_byte_offsets)]
///
/// // On some platforms, the alignment of i32 is less than 4.
/// #[repr(align(4))]
Expand Down
37 changes: 21 additions & 16 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(set_ptr_value)]
#[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(set_ptr_value)]
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -898,8 +900,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(set_ptr_value)]
#[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 @@ -1053,8 +1056,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(set_ptr_value)]
#[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 @@ -1146,8 +1150,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(set_ptr_value)]
#[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 @@ -1226,8 +1231,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(set_ptr_value)]
pub const fn wrapping_byte_add(self, count: usize) -> Self {
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -1304,8 +1310,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(set_ptr_value)]
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
}
Expand Down Expand Up @@ -1639,7 +1646,6 @@ impl<T: ?Sized> *mut T {
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(pointer_byte_offsets)]
///
/// // On some platforms, the alignment of i32 is less than 4.
/// #[repr(align(4))]
Expand Down Expand Up @@ -1763,7 +1769,6 @@ impl<T: ?Sized> *mut T {
///
/// ```
/// #![feature(pointer_is_aligned)]
/// #![feature(pointer_byte_offsets)]
///
/// // On some platforms, the alignment of i32 is less than 4.
/// #[repr(align(4))]
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 @@ -16,7 +16,6 @@
#![feature(const_heap)]
#![feature(const_maybe_uninit_as_mut_ptr)]
#![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 @@ -87,7 +86,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 @@ -331,7 +331,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
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(pointer_byte_offsets)]

fn main() {
let v: Vec<u16> = vec![1, 2];
// This read is also misaligned. We make sure that the OOB message has priority.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(pointer_byte_offsets)]

fn main() {
let mut v: Vec<u16> = vec![1, 2];
// This read is also misaligned. We make sure that the OOB message has priority.
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/tests/pass/provenance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
#![feature(strict_provenance)]
#![feature(pointer_byte_offsets)]
use std::{mem, ptr};

const PTR_SIZE: usize = mem::size_of::<&i32>();
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 @@ -5,8 +5,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
Loading

0 comments on commit 54e57e6

Please sign in to comment.