Auto merge of #93957 - SaltyKitkat:stablize_const_ptr_offset, r=dtolnay

Stabilize const_ptr_offset

Close #71499
This commit is contained in:
bors 2022-03-27 07:01:29 +00:00
commit 223b58e484
21 changed files with 62 additions and 69 deletions

View file

@ -10,7 +10,6 @@
#![feature(const_intrinsic_copy)]
#![feature(const_mut_refs)]
#![feature(const_nonnull_slice_from_raw_parts)]
#![feature(const_ptr_offset)]
#![feature(const_ptr_write)]
#![feature(const_try)]
#![feature(core_intrinsics)]

View file

@ -1168,7 +1168,7 @@ extern "rust-intrinsic" {
///
/// The stabilized version of this intrinsic is [`pointer::offset`].
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
/// Calculates the offset from a pointer, potentially wrapping.
@ -1185,7 +1185,7 @@ extern "rust-intrinsic" {
///
/// The stabilized version of this intrinsic is [`pointer::wrapping_offset`].
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with

View file

@ -126,7 +126,6 @@
#![feature(const_pin)]
#![feature(const_replace)]
#![feature(const_ptr_is_null)]
#![feature(const_ptr_offset)]
#![feature(const_ptr_offset_from)]
#![feature(const_ptr_read)]
#![feature(const_ptr_write)]

View file

@ -285,7 +285,7 @@ impl<T: ?Sized> *const T {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline(always)]
pub const unsafe fn offset(self, count: isize) -> *const T
where
@ -347,7 +347,7 @@ impl<T: ?Sized> *const T {
/// ```
#[stable(feature = "ptr_wrapping_offset", since = "1.16.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline(always)]
pub const fn wrapping_offset(self, count: isize) -> *const T
where
@ -566,7 +566,7 @@ impl<T: ?Sized> *const T {
/// ```
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline(always)]
pub const unsafe fn add(self, count: usize) -> Self
where
@ -630,7 +630,7 @@ impl<T: ?Sized> *const T {
/// ```
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline]
pub const unsafe fn sub(self, count: usize) -> Self
where
@ -693,7 +693,7 @@ impl<T: ?Sized> *const T {
/// ```
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline(always)]
pub const fn wrapping_add(self, count: usize) -> Self
where
@ -755,7 +755,7 @@ impl<T: ?Sized> *const T {
/// ```
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline]
pub const fn wrapping_sub(self, count: usize) -> Self
where

View file

@ -295,7 +295,7 @@ impl<T: ?Sized> *mut T {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline(always)]
pub const unsafe fn offset(self, count: isize) -> *mut T
where
@ -358,7 +358,7 @@ impl<T: ?Sized> *mut T {
/// ```
#[stable(feature = "ptr_wrapping_offset", since = "1.16.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline(always)]
pub const fn wrapping_offset(self, count: isize) -> *mut T
where
@ -680,7 +680,7 @@ impl<T: ?Sized> *mut T {
/// ```
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline(always)]
pub const unsafe fn add(self, count: usize) -> Self
where
@ -744,7 +744,7 @@ impl<T: ?Sized> *mut T {
/// ```
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline]
pub const unsafe fn sub(self, count: usize) -> Self
where
@ -807,7 +807,7 @@ impl<T: ?Sized> *mut T {
/// ```
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline(always)]
pub const fn wrapping_add(self, count: usize) -> Self
where
@ -869,7 +869,7 @@ impl<T: ?Sized> *mut T {
/// ```
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[must_use = "returns a new pointer rather than modifying its argument"]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline]
pub const fn wrapping_sub(self, count: usize) -> Self
where

View file

@ -499,7 +499,8 @@ impl<T> [T] {
/// assert_eq!(x, &[3, 4, 6]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[rustc_allow_const_fn_unstable(const_mut_refs)]
#[inline]
#[must_use]
pub const fn as_mut_ptr(&mut self) -> *mut T {
@ -535,7 +536,7 @@ impl<T> [T] {
///
/// [`as_ptr`]: slice::as_ptr
#[stable(feature = "slice_ptr_range", since = "1.48.0")]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[inline]
#[must_use]
pub const fn as_ptr_range(&self) -> Range<*const T> {
@ -578,7 +579,8 @@ impl<T> [T] {
///
/// [`as_mut_ptr`]: slice::as_mut_ptr
#[stable(feature = "slice_ptr_range", since = "1.48.0")]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
#[rustc_allow_const_fn_unstable(const_mut_refs)]
#[inline]
#[must_use]
pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> {

View file

@ -20,7 +20,6 @@
#![feature(const_ptr_as_ref)]
#![feature(const_ptr_read)]
#![feature(const_ptr_write)]
#![feature(const_ptr_offset)]
#![feature(const_trait_impl)]
#![feature(const_likely)]
#![feature(core_ffi_c)]

View file

@ -1,7 +1,6 @@
// error-pattern: evaluation of constant value failed
#![feature(const_ptr_read)]
#![feature(const_ptr_offset)]
fn main() {
use std::ptr;

View file

@ -7,10 +7,10 @@ LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
| memory access failed: alloc7 has size 4, so pointer to 4 bytes starting at offset 4 is out-of-bounds
| inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
::: $DIR/out_of_bounds_read.rs:13:33
::: $DIR/out_of_bounds_read.rs:12:33
|
LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
| ----------------------- inside `_READ` at $DIR/out_of_bounds_read.rs:13:33
| ----------------------- inside `_READ` at $DIR/out_of_bounds_read.rs:12:33
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
@ -26,10 +26,10 @@ LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
LL | unsafe { read(self) }
| ---------- inside `ptr::const_ptr::<impl *const u32>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/out_of_bounds_read.rs:14:39
::: $DIR/out_of_bounds_read.rs:13:39
|
LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
| ------------------- inside `_CONST_READ` at $DIR/out_of_bounds_read.rs:14:39
| ------------------- inside `_CONST_READ` at $DIR/out_of_bounds_read.rs:13:39
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
@ -45,10 +45,10 @@ LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
LL | unsafe { read(self) }
| ---------- inside `ptr::mut_ptr::<impl *mut u32>::read` at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
|
::: $DIR/out_of_bounds_read.rs:15:37
::: $DIR/out_of_bounds_read.rs:14:37
|
LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
| --------------------------------- inside `_MUT_READ` at $DIR/out_of_bounds_read.rs:15:37
| --------------------------------- inside `_MUT_READ` at $DIR/out_of_bounds_read.rs:14:37
error: aborting due to 3 previous errors

View file

@ -2,7 +2,7 @@
// ignore-tidy-linelength
#![feature(intrinsics, staged_api)]
#![feature(const_mut_refs, const_intrinsic_copy, const_ptr_offset)]
#![feature(const_mut_refs, const_intrinsic_copy)]
use std::mem;
extern "rust-intrinsic" {

View file

@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/invalid-union.rs:41:1
--> $DIR/invalid-union.rs:40:1
|
LL | fn main() {
| ^^^^^^^^^ type validation failed at .<deref>.y.<enum-variant(B)>.0: encountered `UnsafeCell` in a `const`
@ -10,7 +10,7 @@ LL | fn main() {
}
error: erroneous constant used
--> $DIR/invalid-union.rs:42:25
--> $DIR/invalid-union.rs:41:25
|
LL | let _: &'static _ = &C;
| ^^ referenced constant has errors

View file

@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/invalid-union.rs:41:1
--> $DIR/invalid-union.rs:40:1
|
LL | fn main() {
| ^^^^^^^^^ type validation failed at .<deref>.y.<enum-variant(B)>.0: encountered `UnsafeCell` in a `const`
@ -10,7 +10,7 @@ LL | fn main() {
}
error: erroneous constant used
--> $DIR/invalid-union.rs:42:25
--> $DIR/invalid-union.rs:41:25
|
LL | let _: &'static _ = &C;
| ^^ referenced constant has errors

View file

@ -9,7 +9,6 @@
// build-fail
// stderr-per-bitwidth
#![feature(const_mut_refs)]
#![feature(const_ptr_offset)]
#![feature(untagged_unions)]
use std::cell::Cell;

View file

@ -1,6 +1,5 @@
// error-pattern unable to turn pointer into raw bytes
#![feature(const_ptr_read)]
#![feature(const_ptr_offset)]
const C: () = unsafe {
let foo = Some(&42 as *const i32);

View file

@ -7,9 +7,9 @@ LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
| unable to turn pointer into raw bytes
| inside `std::ptr::read::<u8>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
| inside `ptr::const_ptr::<impl *const u8>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
| inside `C` at $DIR/issue-miri-1910.rs:8:5
| inside `C` at $DIR/issue-miri-1910.rs:7:5
|
::: $DIR/issue-miri-1910.rs:5:1
::: $DIR/issue-miri-1910.rs:4:1
|
LL | / const C: () = unsafe {
LL | | let foo = Some(&42 as *const i32);

View file

@ -1,5 +1,4 @@
// run-pass
#![feature(const_ptr_offset)]
#![feature(const_ptr_offset_from)]
use std::ptr;

View file

@ -1,4 +1,4 @@
#![feature(const_ptr_offset_from, const_ptr_offset)]
#![feature(const_ptr_offset_from)]
#![feature(core_intrinsics)]
use std::intrinsics::ptr_offset_from;

View file

@ -1,4 +1,3 @@
#![feature(const_ptr_offset)]
use std::ptr;
// normalize-stderr-test "alloc\d+" -> "allocN"

View file

@ -7,10 +7,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| overflowing in-bounds pointer arithmetic
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:8:46
::: $DIR/offset_ub.rs:7:46
|
LL | pub const BEFORE_START: *const u8 = unsafe { (&0u8 as *const u8).offset(-1) };
| ------------------------------ inside `BEFORE_START` at $DIR/offset_ub.rs:8:46
| ------------------------------ inside `BEFORE_START` at $DIR/offset_ub.rs:7:46
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -21,10 +21,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| pointer arithmetic failed: allocN has size 1, so pointer to 2 bytes starting at offset 0 is out-of-bounds
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:9:43
::: $DIR/offset_ub.rs:8:43
|
LL | pub const AFTER_END: *const u8 = unsafe { (&0u8 as *const u8).offset(2) };
| ----------------------------- inside `AFTER_END` at $DIR/offset_ub.rs:9:43
| ----------------------------- inside `AFTER_END` at $DIR/offset_ub.rs:8:43
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -35,10 +35,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| pointer arithmetic failed: allocN has size 100, so pointer to 101 bytes starting at offset 0 is out-of-bounds
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:10:45
::: $DIR/offset_ub.rs:9:45
|
LL | pub const AFTER_ARRAY: *const u8 = unsafe { [0u8; 100].as_ptr().offset(101) };
| ------------------------------- inside `AFTER_ARRAY` at $DIR/offset_ub.rs:10:45
| ------------------------------- inside `AFTER_ARRAY` at $DIR/offset_ub.rs:9:45
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -49,10 +49,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| overflowing in-bounds pointer arithmetic
| inside `ptr::const_ptr::<impl *const u16>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:12:43
::: $DIR/offset_ub.rs:11:43
|
LL | pub const OVERFLOW: *const u16 = unsafe { [0u16; 1].as_ptr().offset(isize::MAX) };
| ------------------------------------- inside `OVERFLOW` at $DIR/offset_ub.rs:12:43
| ------------------------------------- inside `OVERFLOW` at $DIR/offset_ub.rs:11:43
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -63,10 +63,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| overflowing in-bounds pointer arithmetic
| inside `ptr::const_ptr::<impl *const u16>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:13:44
::: $DIR/offset_ub.rs:12:44
|
LL | pub const UNDERFLOW: *const u16 = unsafe { [0u16; 1].as_ptr().offset(isize::MIN) };
| ------------------------------------- inside `UNDERFLOW` at $DIR/offset_ub.rs:13:44
| ------------------------------------- inside `UNDERFLOW` at $DIR/offset_ub.rs:12:44
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -77,10 +77,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| overflowing in-bounds pointer arithmetic
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:14:56
::: $DIR/offset_ub.rs:13:56
|
LL | pub const OVERFLOW_ADDRESS_SPACE: *const u8 = unsafe { (usize::MAX as *const u8).offset(2) };
| ----------------------------------- inside `OVERFLOW_ADDRESS_SPACE` at $DIR/offset_ub.rs:14:56
| ----------------------------------- inside `OVERFLOW_ADDRESS_SPACE` at $DIR/offset_ub.rs:13:56
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -91,10 +91,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| overflowing in-bounds pointer arithmetic
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:15:57
::: $DIR/offset_ub.rs:14:57
|
LL | pub const UNDERFLOW_ADDRESS_SPACE: *const u8 = unsafe { (1 as *const u8).offset(-2) };
| --------------------------- inside `UNDERFLOW_ADDRESS_SPACE` at $DIR/offset_ub.rs:15:57
| --------------------------- inside `UNDERFLOW_ADDRESS_SPACE` at $DIR/offset_ub.rs:14:57
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -105,10 +105,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| pointer arithmetic failed: allocN has size 1, so pointer to 2 bytes starting at offset -4 is out-of-bounds
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:16:49
::: $DIR/offset_ub.rs:15:49
|
LL | pub const NEGATIVE_OFFSET: *const u8 = unsafe { [0u8; 1].as_ptr().wrapping_offset(-2).offset(-2) };
| ------------------------------------------------ inside `NEGATIVE_OFFSET` at $DIR/offset_ub.rs:16:49
| ------------------------------------------------ inside `NEGATIVE_OFFSET` at $DIR/offset_ub.rs:15:49
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -119,10 +119,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| pointer arithmetic failed: allocN has size 0, so pointer to 1 byte starting at offset 0 is out-of-bounds
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:18:50
::: $DIR/offset_ub.rs:17:50
|
LL | pub const ZERO_SIZED_ALLOC: *const u8 = unsafe { [0u8; 0].as_ptr().offset(1) };
| --------------------------- inside `ZERO_SIZED_ALLOC` at $DIR/offset_ub.rs:18:50
| --------------------------- inside `ZERO_SIZED_ALLOC` at $DIR/offset_ub.rs:17:50
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
@ -133,10 +133,10 @@ LL | unsafe { intrinsics::offset(self, count) as *mut T }
| pointer arithmetic failed: 0x1 is not a valid pointer
| inside `ptr::mut_ptr::<impl *mut u8>::offset` at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:19:42
::: $DIR/offset_ub.rs:18:42
|
LL | pub const DANGLING: *const u8 = unsafe { ptr::NonNull::<u8>::dangling().as_ptr().offset(4) };
| ------------------------------------------------- inside `DANGLING` at $DIR/offset_ub.rs:19:42
| ------------------------------------------------- inside `DANGLING` at $DIR/offset_ub.rs:18:42
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -147,10 +147,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| pointer arithmetic failed: null pointer is not a valid pointer
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:22:50
::: $DIR/offset_ub.rs:21:50
|
LL | pub const NULL_OFFSET_ZERO: *const u8 = unsafe { ptr::null::<u8>().offset(0) };
| --------------------------- inside `NULL_OFFSET_ZERO` at $DIR/offset_ub.rs:22:50
| --------------------------- inside `NULL_OFFSET_ZERO` at $DIR/offset_ub.rs:21:50
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
@ -161,10 +161,10 @@ LL | unsafe { intrinsics::offset(self, count) }
| pointer arithmetic failed: 0x7f..f is not a valid pointer
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/offset_ub.rs:25:47
::: $DIR/offset_ub.rs:24:47
|
LL | pub const UNDERFLOW_ABS: *const u8 = unsafe { (usize::MAX as *const u8).offset(isize::MIN) };
| -------------------------------------------- inside `UNDERFLOW_ABS` at $DIR/offset_ub.rs:25:47
| -------------------------------------------- inside `UNDERFLOW_ABS` at $DIR/offset_ub.rs:24:47
error: aborting due to 12 previous errors

View file

@ -7,7 +7,6 @@
#![feature(
core_intrinsics,
const_raw_ptr_comparison,
const_ptr_offset,
)]
const FOO: &usize = &42;

View file

@ -7,19 +7,19 @@ LL | unsafe { intrinsics::offset(self, count) }
| pointer arithmetic failed: alloc3 has size $WORD, so pointer to $TWO_WORDS bytes starting at offset 0 is out-of-bounds
| inside `ptr::const_ptr::<impl *const usize>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
::: $DIR/ptr_comparisons.rs:59:34
::: $DIR/ptr_comparisons.rs:58:34
|
LL | const _: *const usize = unsafe { (FOO as *const usize).offset(2) };
| ------------------------------- inside `_` at $DIR/ptr_comparisons.rs:59:34
| ------------------------------- inside `_` at $DIR/ptr_comparisons.rs:58:34
error[E0080]: evaluation of constant value failed
--> $DIR/ptr_comparisons.rs:62:33
--> $DIR/ptr_comparisons.rs:61:33
|
LL | unsafe { std::ptr::addr_of!((*(FOO as *const usize as *const [u8; 1000]))[999]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: alloc3 has size $WORD, so pointer to 1000 bytes starting at offset 0 is out-of-bounds
error: any use of this value will cause an error
--> $DIR/ptr_comparisons.rs:66:27
--> $DIR/ptr_comparisons.rs:65:27
|
LL | const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) + 4 };
| --------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
@ -31,7 +31,7 @@ LL | const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) +
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: any use of this value will cause an error
--> $DIR/ptr_comparisons.rs:71:27
--> $DIR/ptr_comparisons.rs:70:27
|
LL | const _: usize = unsafe { *std::mem::transmute::<&&usize, &usize>(&FOO) + 4 };
| --------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---