From 45bc74612155a4878285d401d6fa28b64859c280 Mon Sep 17 00:00:00 2001 From: SaltyKitkat <954537646@qq.com> Date: Sun, 13 Feb 2022 15:26:14 +0800 Subject: [PATCH 1/4] stabilize const_ptr_offset --- library/alloc/tests/lib.rs | 1 - library/core/src/intrinsics.rs | 4 ++-- library/core/src/lib.rs | 1 - library/core/src/ptr/const_ptr.rs | 12 ++++++------ library/core/src/ptr/mut_ptr.rs | 12 ++++++------ library/core/src/slice/mod.rs | 6 +++--- library/core/tests/lib.rs | 1 - src/test/ui/const-ptr/out_of_bounds_read.rs | 1 - src/test/ui/consts/copy-intrinsic.rs | 2 +- src/test/ui/consts/invalid-union.rs | 1 - src/test/ui/consts/issue-miri-1910.rs | 1 - src/test/ui/consts/offset.rs | 1 - src/test/ui/consts/offset_ub.rs | 1 - src/test/ui/consts/ptr_comparisons.rs | 1 - 14 files changed, 18 insertions(+), 27 deletions(-) diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index cbb86265233b0..abce47e5afe1a 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -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)] diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index b5228397f0a99..c59f5371d1f01 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -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.60.0")] pub fn offset(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.60.0")] pub fn arith_offset(dst: *const T, offset: isize) -> *const T; /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 72d8e1b39030a..39afe3d2737ad 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -125,7 +125,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)] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 485a5965f4cf7..fd0b3916d1809 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -285,7 +285,7 @@ impl *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.60.0")] #[inline(always)] pub const unsafe fn offset(self, count: isize) -> *const T where @@ -347,7 +347,7 @@ impl *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.60.0")] #[inline(always)] pub const fn wrapping_offset(self, count: isize) -> *const T where @@ -566,7 +566,7 @@ impl *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.60.0")] #[inline(always)] pub const unsafe fn add(self, count: usize) -> Self where @@ -630,7 +630,7 @@ impl *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.60.0")] #[inline] pub const unsafe fn sub(self, count: usize) -> Self where @@ -693,7 +693,7 @@ impl *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.60.0")] #[inline(always)] pub const fn wrapping_add(self, count: usize) -> Self where @@ -755,7 +755,7 @@ impl *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.60.0")] #[inline] pub const fn wrapping_sub(self, count: usize) -> Self where diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 1412e836ebfc2..9425616f7a71d 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -295,7 +295,7 @@ impl *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.60.0")] #[inline(always)] pub const unsafe fn offset(self, count: isize) -> *mut T where @@ -358,7 +358,7 @@ impl *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.60.0")] #[inline(always)] pub const fn wrapping_offset(self, count: isize) -> *mut T where @@ -680,7 +680,7 @@ impl *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.60.0")] #[inline(always)] pub const unsafe fn add(self, count: usize) -> Self where @@ -744,7 +744,7 @@ impl *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.60.0")] #[inline] pub const unsafe fn sub(self, count: usize) -> Self where @@ -807,7 +807,7 @@ impl *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.60.0")] #[inline(always)] pub const fn wrapping_add(self, count: usize) -> Self where @@ -869,7 +869,7 @@ impl *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.60.0")] #[inline] pub const fn wrapping_sub(self, count: usize) -> Self where diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 4e22c1d8c6d94..cca1913837817 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -478,7 +478,7 @@ impl [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.60.0")] #[inline] pub const fn as_mut_ptr(&mut self) -> *mut T { self as *mut [T] as *mut T @@ -513,7 +513,7 @@ impl [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.60.0")] #[inline] pub const fn as_ptr_range(&self) -> Range<*const T> { let start = self.as_ptr(); @@ -555,7 +555,7 @@ impl [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.60.0")] #[inline] pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> { let start = self.as_mut_ptr(); diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 1c512471c95cb..bb38357d33b67 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -22,7 +22,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_intrinsics)] diff --git a/src/test/ui/const-ptr/out_of_bounds_read.rs b/src/test/ui/const-ptr/out_of_bounds_read.rs index c45198cc39b08..9dd669180da0a 100644 --- a/src/test/ui/const-ptr/out_of_bounds_read.rs +++ b/src/test/ui/const-ptr/out_of_bounds_read.rs @@ -1,7 +1,6 @@ // error-pattern: evaluation of constant value failed #![feature(const_ptr_read)] -#![feature(const_ptr_offset)] fn main() { use std::ptr; diff --git a/src/test/ui/consts/copy-intrinsic.rs b/src/test/ui/consts/copy-intrinsic.rs index 124e16e2b2c0f..5ab90324b8f86 100644 --- a/src/test/ui/consts/copy-intrinsic.rs +++ b/src/test/ui/consts/copy-intrinsic.rs @@ -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" { diff --git a/src/test/ui/consts/invalid-union.rs b/src/test/ui/consts/invalid-union.rs index 1d5cc978a9e6b..f3f1af89b2c41 100644 --- a/src/test/ui/consts/invalid-union.rs +++ b/src/test/ui/consts/invalid-union.rs @@ -9,7 +9,6 @@ // build-fail // stderr-per-bitwidth #![feature(const_mut_refs)] -#![feature(const_ptr_offset)] #![feature(untagged_unions)] use std::cell::Cell; diff --git a/src/test/ui/consts/issue-miri-1910.rs b/src/test/ui/consts/issue-miri-1910.rs index 20efa145dbe1e..2b23626e3d709 100644 --- a/src/test/ui/consts/issue-miri-1910.rs +++ b/src/test/ui/consts/issue-miri-1910.rs @@ -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); diff --git a/src/test/ui/consts/offset.rs b/src/test/ui/consts/offset.rs index a491f1c92d3e1..f9ddda554fcf0 100644 --- a/src/test/ui/consts/offset.rs +++ b/src/test/ui/consts/offset.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(const_ptr_offset)] #![feature(const_ptr_offset_from)] use std::ptr; diff --git a/src/test/ui/consts/offset_ub.rs b/src/test/ui/consts/offset_ub.rs index 42a285a6eab49..1b01e4fd14731 100644 --- a/src/test/ui/consts/offset_ub.rs +++ b/src/test/ui/consts/offset_ub.rs @@ -1,4 +1,3 @@ -#![feature(const_ptr_offset)] use std::ptr; // normalize-stderr-test "alloc\d+" -> "allocN" diff --git a/src/test/ui/consts/ptr_comparisons.rs b/src/test/ui/consts/ptr_comparisons.rs index 8161c7af968bf..20233db09c90b 100644 --- a/src/test/ui/consts/ptr_comparisons.rs +++ b/src/test/ui/consts/ptr_comparisons.rs @@ -7,7 +7,6 @@ #![feature( core_intrinsics, const_raw_ptr_comparison, - const_ptr_offset, )] const FOO: &usize = &42; From 8f9ba1269ab29780026ca25af9ee8977101c5dba Mon Sep 17 00:00:00 2001 From: SaltyKitkat <954537646@qq.com> Date: Sun, 13 Feb 2022 16:16:41 +0800 Subject: [PATCH 2/4] allow const_mut_refs --- library/core/src/slice/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index cca1913837817..94f2805a9d636 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -479,6 +479,7 @@ impl [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_allow_const_fn_unstable(const_mut_refs)] #[inline] pub const fn as_mut_ptr(&mut self) -> *mut T { self as *mut [T] as *mut T @@ -556,6 +557,7 @@ impl [T] { /// [`as_mut_ptr`]: slice::as_mut_ptr #[stable(feature = "slice_ptr_range", since = "1.48.0")] #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_allow_const_fn_unstable(const_mut_refs)] #[inline] pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> { let start = self.as_mut_ptr(); From 6d0e5f2e297e7d26ce4fd18a88fdb1300787cd57 Mon Sep 17 00:00:00 2001 From: SaltyKitkat <954537646@qq.com> Date: Sun, 13 Feb 2022 17:30:10 +0800 Subject: [PATCH 3/4] update stderr messages --- .../ui/const-ptr/out_of_bounds_read.stderr | 12 ++--- src/test/ui/consts/invalid-union.32bit.stderr | 4 +- src/test/ui/consts/invalid-union.64bit.stderr | 4 +- src/test/ui/consts/issue-miri-1910.stderr | 4 +- src/test/ui/consts/offset_ub.stderr | 48 +++++++++---------- src/test/ui/consts/ptr_comparisons.stderr | 10 ++-- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/test/ui/const-ptr/out_of_bounds_read.stderr b/src/test/ui/const-ptr/out_of_bounds_read.stderr index 62af6a6adb644..678714d0e055a 100644 --- a/src/test/ui/const-ptr/out_of_bounds_read.stderr +++ b/src/test/ui/const-ptr/out_of_bounds_read.stderr @@ -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::` 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::::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::::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 diff --git a/src/test/ui/consts/invalid-union.32bit.stderr b/src/test/ui/consts/invalid-union.32bit.stderr index c8f9e5704671e..38c38d1ae6732 100644 --- a/src/test/ui/consts/invalid-union.32bit.stderr +++ b/src/test/ui/consts/invalid-union.32bit.stderr @@ -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 ..y..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 diff --git a/src/test/ui/consts/invalid-union.64bit.stderr b/src/test/ui/consts/invalid-union.64bit.stderr index 2ca54ccf9a09e..6bfa97a2fded7 100644 --- a/src/test/ui/consts/invalid-union.64bit.stderr +++ b/src/test/ui/consts/invalid-union.64bit.stderr @@ -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 ..y..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 diff --git a/src/test/ui/consts/issue-miri-1910.stderr b/src/test/ui/consts/issue-miri-1910.stderr index e2f4ef635887c..87882449c7342 100644 --- a/src/test/ui/consts/issue-miri-1910.stderr +++ b/src/test/ui/consts/issue-miri-1910.stderr @@ -7,9 +7,9 @@ LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1); | unable to turn pointer into raw bytes | inside `std::ptr::read::` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL | inside `ptr::const_ptr::::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); diff --git a/src/test/ui/consts/offset_ub.stderr b/src/test/ui/consts/offset_ub.stderr index 4c3f373e0801c..bb0511d9d12c4 100644 --- a/src/test/ui/consts/offset_ub.stderr +++ b/src/test/ui/consts/offset_ub.stderr @@ -7,10 +7,10 @@ LL | unsafe { intrinsics::offset(self, count) } | overflowing in-bounds pointer arithmetic | inside `ptr::const_ptr::::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::::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::::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::::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::::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::::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::::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::::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::::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 } | 0x1 is not a valid pointer | inside `ptr::mut_ptr::::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::::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: 0x0 is not a valid pointer | inside `ptr::const_ptr::::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::().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) } | 0x7f..f is not a valid pointer | inside `ptr::const_ptr::::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 diff --git a/src/test/ui/consts/ptr_comparisons.stderr b/src/test/ui/consts/ptr_comparisons.stderr index cfec25a7194cb..678ce5d3a35c8 100644 --- a/src/test/ui/consts/ptr_comparisons.stderr +++ b/src/test/ui/consts/ptr_comparisons.stderr @@ -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::::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 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 }; | --------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--- From e5d1d979289e322fb60b0e315472ad249f1d4256 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 26 Mar 2022 14:19:41 -0700 Subject: [PATCH 4/4] Bump const_ptr_offset stabilization to 1.61 --- library/core/src/intrinsics.rs | 4 ++-- library/core/src/ptr/const_ptr.rs | 12 ++++++------ library/core/src/ptr/mut_ptr.rs | 12 ++++++------ library/core/src/slice/mod.rs | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index c59f5371d1f01..27f6991024a3e 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -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_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] pub fn offset(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_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] pub fn arith_offset(dst: *const T, offset: isize) -> *const T; /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index fd0b3916d1809..2dcc651d2eb6a 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -285,7 +285,7 @@ impl *const T { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *const T { /// ``` #[stable(feature = "ptr_wrapping_offset", since = "1.16.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *const T { /// ``` #[stable(feature = "pointer_methods", since = "1.26.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *const T { /// ``` #[stable(feature = "pointer_methods", since = "1.26.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *const T { /// ``` #[stable(feature = "pointer_methods", since = "1.26.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *const T { /// ``` #[stable(feature = "pointer_methods", since = "1.26.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] #[inline] pub const fn wrapping_sub(self, count: usize) -> Self where diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 9425616f7a71d..7bdd0685f8dc4 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -295,7 +295,7 @@ impl *mut T { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *mut T { /// ``` #[stable(feature = "ptr_wrapping_offset", since = "1.16.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *mut T { /// ``` #[stable(feature = "pointer_methods", since = "1.26.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *mut T { /// ``` #[stable(feature = "pointer_methods", since = "1.26.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *mut T { /// ``` #[stable(feature = "pointer_methods", since = "1.26.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[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 *mut T { /// ``` #[stable(feature = "pointer_methods", since = "1.26.0")] #[must_use = "returns a new pointer rather than modifying its argument"] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] #[inline] pub const fn wrapping_sub(self, count: usize) -> Self where diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 94f2805a9d636..abccd4a3bf74b 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -478,7 +478,7 @@ impl [T] { /// assert_eq!(x, &[3, 4, 6]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] #[rustc_allow_const_fn_unstable(const_mut_refs)] #[inline] pub const fn as_mut_ptr(&mut self) -> *mut T { @@ -514,7 +514,7 @@ impl [T] { /// /// [`as_ptr`]: slice::as_ptr #[stable(feature = "slice_ptr_range", since = "1.48.0")] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] #[inline] pub const fn as_ptr_range(&self) -> Range<*const T> { let start = self.as_ptr(); @@ -556,7 +556,7 @@ impl [T] { /// /// [`as_mut_ptr`]: slice::as_mut_ptr #[stable(feature = "slice_ptr_range", since = "1.48.0")] - #[rustc_const_stable(feature = "const_ptr_offset", since = "1.60.0")] + #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] #[rustc_allow_const_fn_unstable(const_mut_refs)] #[inline] pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> {