Skip to content

Commit 54e57e6

Browse files
committedOct 27, 2023
Auto merge of #116205 - WaffleLapkin:stabilize_pointer_byte_offsets, r=dtolnay
Stabilize `[const_]pointer_byte_offsets` Closes #96283 Awaiting FCP completion: #96283 (comment) r? libs-api
2 parents 707d8c3 + fe97fdf commit 54e57e6

File tree

18 files changed

+69
-77
lines changed

18 files changed

+69
-77
lines changed
 

‎compiler/rustc_arena/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#![feature(new_uninit)]
1919
#![feature(maybe_uninit_slice)]
2020
#![feature(decl_macro)]
21-
#![feature(pointer_byte_offsets)]
2221
#![feature(rustc_attrs)]
2322
#![cfg_attr(test, feature(test))]
2423
#![feature(strict_provenance)]

‎library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
#![feature(maybe_uninit_uninit_array)]
142142
#![feature(maybe_uninit_uninit_array_transpose)]
143143
#![feature(pattern)]
144-
#![feature(pointer_byte_offsets)]
145144
#![feature(ptr_addr_eq)]
146145
#![feature(ptr_internals)]
147146
#![feature(ptr_metadata)]

‎library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
#![feature(const_option)]
149149
#![feature(const_option_ext)]
150150
#![feature(const_pin)]
151-
#![feature(const_pointer_byte_offsets)]
152151
#![feature(const_pointer_is_aligned)]
153152
#![feature(const_ptr_as_ref)]
154153
#![feature(const_ptr_is_null)]

‎library/core/src/ptr/const_ptr.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,9 @@ impl<T: ?Sized> *const T {
480480
/// leaving the metadata untouched.
481481
#[must_use]
482482
#[inline(always)]
483-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
484-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
483+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
484+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
485+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
485486
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
486487
pub const unsafe fn byte_offset(self, count: isize) -> Self {
487488
// SAFETY: the caller must uphold the safety contract for `offset`.
@@ -560,8 +561,9 @@ impl<T: ?Sized> *const T {
560561
/// leaving the metadata untouched.
561562
#[must_use]
562563
#[inline(always)]
563-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
564-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
564+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
565+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
566+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
565567
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
566568
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
567569
}
@@ -726,8 +728,9 @@ impl<T: ?Sized> *const T {
726728
/// For non-`Sized` pointees this operation considers only the data pointers,
727729
/// ignoring the metadata.
728730
#[inline(always)]
729-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
730-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
731+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
732+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
733+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
731734
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
732735
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize {
733736
// SAFETY: the caller must uphold the safety contract for `offset_from`.
@@ -952,8 +955,9 @@ impl<T: ?Sized> *const T {
952955
/// leaving the metadata untouched.
953956
#[must_use]
954957
#[inline(always)]
955-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
956-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
958+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
959+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
960+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
957961
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
958962
pub const unsafe fn byte_add(self, count: usize) -> Self {
959963
// SAFETY: the caller must uphold the safety contract for `add`.
@@ -1045,8 +1049,9 @@ impl<T: ?Sized> *const T {
10451049
/// leaving the metadata untouched.
10461050
#[must_use]
10471051
#[inline(always)]
1048-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
1049-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1052+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1053+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1054+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
10501055
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10511056
pub const unsafe fn byte_sub(self, count: usize) -> Self {
10521057
// SAFETY: the caller must uphold the safety contract for `sub`.
@@ -1125,8 +1130,9 @@ impl<T: ?Sized> *const T {
11251130
/// leaving the metadata untouched.
11261131
#[must_use]
11271132
#[inline(always)]
1128-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
1129-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1133+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1134+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1135+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
11301136
pub const fn wrapping_byte_add(self, count: usize) -> Self {
11311137
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
11321138
}
@@ -1203,8 +1209,9 @@ impl<T: ?Sized> *const T {
12031209
/// leaving the metadata untouched.
12041210
#[must_use]
12051211
#[inline(always)]
1206-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
1207-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1212+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1213+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1214+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
12081215
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
12091216
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
12101217
}
@@ -1372,7 +1379,6 @@ impl<T: ?Sized> *const T {
13721379
///
13731380
/// ```
13741381
/// #![feature(pointer_is_aligned)]
1375-
/// #![feature(pointer_byte_offsets)]
13761382
///
13771383
/// // On some platforms, the alignment of i32 is less than 4.
13781384
/// #[repr(align(4))]
@@ -1494,7 +1500,6 @@ impl<T: ?Sized> *const T {
14941500
///
14951501
/// ```
14961502
/// #![feature(pointer_is_aligned)]
1497-
/// #![feature(pointer_byte_offsets)]
14981503
///
14991504
/// // On some platforms, the alignment of i32 is less than 4.
15001505
/// #[repr(align(4))]

‎library/core/src/ptr/mut_ptr.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,9 @@ impl<T: ?Sized> *mut T {
495495
/// leaving the metadata untouched.
496496
#[must_use]
497497
#[inline(always)]
498-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
499-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
498+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
499+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
500+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
500501
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
501502
pub const unsafe fn byte_offset(self, count: isize) -> Self {
502503
// SAFETY: the caller must uphold the safety contract for `offset`.
@@ -574,8 +575,9 @@ impl<T: ?Sized> *mut T {
574575
/// leaving the metadata untouched.
575576
#[must_use]
576577
#[inline(always)]
577-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
578-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
578+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
579+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
580+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
579581
pub const fn wrapping_byte_offset(self, count: isize) -> Self {
580582
self.cast::<u8>().wrapping_offset(count).with_metadata_of(self)
581583
}
@@ -898,8 +900,9 @@ impl<T: ?Sized> *mut T {
898900
/// For non-`Sized` pointees this operation considers only the data pointers,
899901
/// ignoring the metadata.
900902
#[inline(always)]
901-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
902-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
903+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
904+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
905+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
903906
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
904907
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize {
905908
// SAFETY: the caller must uphold the safety contract for `offset_from`.
@@ -1053,8 +1056,9 @@ impl<T: ?Sized> *mut T {
10531056
/// leaving the metadata untouched.
10541057
#[must_use]
10551058
#[inline(always)]
1056-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
1057-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1059+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1060+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1061+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
10581062
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10591063
pub const unsafe fn byte_add(self, count: usize) -> Self {
10601064
// SAFETY: the caller must uphold the safety contract for `add`.
@@ -1146,8 +1150,9 @@ impl<T: ?Sized> *mut T {
11461150
/// leaving the metadata untouched.
11471151
#[must_use]
11481152
#[inline(always)]
1149-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
1150-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1153+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1154+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1155+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
11511156
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
11521157
pub const unsafe fn byte_sub(self, count: usize) -> Self {
11531158
// SAFETY: the caller must uphold the safety contract for `sub`.
@@ -1226,8 +1231,9 @@ impl<T: ?Sized> *mut T {
12261231
/// leaving the metadata untouched.
12271232
#[must_use]
12281233
#[inline(always)]
1229-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
1230-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1234+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1235+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1236+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
12311237
pub const fn wrapping_byte_add(self, count: usize) -> Self {
12321238
self.cast::<u8>().wrapping_add(count).with_metadata_of(self)
12331239
}
@@ -1304,8 +1310,9 @@ impl<T: ?Sized> *mut T {
13041310
/// leaving the metadata untouched.
13051311
#[must_use]
13061312
#[inline(always)]
1307-
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
1308-
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1313+
#[stable(feature = "pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1314+
#[rustc_const_stable(feature = "const_pointer_byte_offsets", since = "CURRENT_RUSTC_VERSION")]
1315+
#[rustc_allow_const_fn_unstable(set_ptr_value)]
13091316
pub const fn wrapping_byte_sub(self, count: usize) -> Self {
13101317
self.cast::<u8>().wrapping_sub(count).with_metadata_of(self)
13111318
}
@@ -1639,7 +1646,6 @@ impl<T: ?Sized> *mut T {
16391646
///
16401647
/// ```
16411648
/// #![feature(pointer_is_aligned)]
1642-
/// #![feature(pointer_byte_offsets)]
16431649
///
16441650
/// // On some platforms, the alignment of i32 is less than 4.
16451651
/// #[repr(align(4))]
@@ -1763,7 +1769,6 @@ impl<T: ?Sized> *mut T {
17631769
///
17641770
/// ```
17651771
/// #![feature(pointer_is_aligned)]
1766-
/// #![feature(pointer_byte_offsets)]
17671772
///
17681773
/// // On some platforms, the alignment of i32 is less than 4.
17691774
/// #[repr(align(4))]

‎library/core/tests/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#![feature(const_heap)]
1717
#![feature(const_maybe_uninit_as_mut_ptr)]
1818
#![feature(const_nonnull_new)]
19-
#![feature(const_pointer_byte_offsets)]
2019
#![feature(const_pointer_is_aligned)]
2120
#![feature(const_ptr_as_ref)]
2221
#![feature(const_ptr_write)]
@@ -87,7 +86,6 @@
8786
#![feature(const_waker)]
8887
#![feature(never_type)]
8988
#![feature(unwrap_infallible)]
90-
#![feature(pointer_byte_offsets)]
9189
#![feature(pointer_is_aligned)]
9290
#![feature(portable_simd)]
9391
#![feature(ptr_metadata)]

‎library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@
331331
#![feature(panic_can_unwind)]
332332
#![feature(panic_info_message)]
333333
#![feature(panic_internals)]
334-
#![feature(pointer_byte_offsets)]
335334
#![feature(pointer_is_aligned)]
336335
#![feature(portable_simd)]
337336
#![feature(prelude_2024)]

‎src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_read.rs

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

‎src/tools/miri/tests/fail/dangling_pointers/out_of_bounds_write.rs

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

‎src/tools/miri/tests/pass/provenance.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@revisions: stack tree
22
//@[tree]compile-flags: -Zmiri-tree-borrows
33
#![feature(strict_provenance)]
4-
#![feature(pointer_byte_offsets)]
54
use std::{mem, ptr};
65

76
const PTR_SIZE: usize = mem::size_of::<&i32>();

‎tests/ui/const-ptr/allowed_slices.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#![feature(
33
slice_from_ptr_range,
44
const_slice_from_ptr_range,
5-
pointer_byte_offsets,
6-
const_pointer_byte_offsets
75
)]
86
use std::{
97
mem::MaybeUninit,

‎tests/ui/const-ptr/forbidden_slices.rs

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#![feature(
66
slice_from_ptr_range,
77
const_slice_from_ptr_range,
8-
pointer_byte_offsets,
9-
const_pointer_byte_offsets
108
)]
119
use std::{
1210
mem::{size_of, MaybeUninit},

‎tests/ui/const-ptr/forbidden_slices.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/forbidden_slices.rs:18:1
2+
--> $DIR/forbidden_slices.rs:16:1
33
|
44
LL | pub static S0: &[u32] = unsafe { from_raw_parts(ptr::null(), 0) };
55
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference
@@ -10,7 +10,7 @@ LL | pub static S0: &[u32] = unsafe { from_raw_parts(ptr::null(), 0) };
1010
}
1111

1212
error[E0080]: it is undefined behavior to use this value
13-
--> $DIR/forbidden_slices.rs:20:1
13+
--> $DIR/forbidden_slices.rs:18:1
1414
|
1515
LL | pub static S1: &[()] = unsafe { from_raw_parts(ptr::null(), 0) };
1616
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference
@@ -21,7 +21,7 @@ LL | pub static S1: &[()] = unsafe { from_raw_parts(ptr::null(), 0) };
2121
}
2222

2323
error[E0080]: it is undefined behavior to use this value
24-
--> $DIR/forbidden_slices.rs:24:1
24+
--> $DIR/forbidden_slices.rs:22:1
2525
|
2626
LL | pub static S2: &[u32] = unsafe { from_raw_parts(&D0, 2) };
2727
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@@ -32,7 +32,7 @@ LL | pub static S2: &[u32] = unsafe { from_raw_parts(&D0, 2) };
3232
}
3333

3434
error[E0080]: it is undefined behavior to use this value
35-
--> $DIR/forbidden_slices.rs:28:1
35+
--> $DIR/forbidden_slices.rs:26:1
3636
|
3737
LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) };
3838
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer
@@ -43,7 +43,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }
4343
}
4444

4545
error[E0080]: it is undefined behavior to use this value
46-
--> $DIR/forbidden_slices.rs:30:1
46+
--> $DIR/forbidden_slices.rs:28:1
4747
|
4848
LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, size_of::<&u32>()) };
4949
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer
@@ -56,7 +56,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, size
5656
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
5757

5858
error[E0080]: it is undefined behavior to use this value
59-
--> $DIR/forbidden_slices.rs:32:1
59+
--> $DIR/forbidden_slices.rs:30:1
6060
|
6161
LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) };
6262
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean
@@ -67,7 +67,7 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4)
6767
}
6868

6969
error[E0080]: it is undefined behavior to use this value
70-
--> $DIR/forbidden_slices.rs:35:1
70+
--> $DIR/forbidden_slices.rs:33:1
7171
|
7272
LL | pub static S7: &[u16] = unsafe {
7373
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[1]: encountered uninitialized memory, but expected an integer
@@ -78,7 +78,7 @@ LL | pub static S7: &[u16] = unsafe {
7878
}
7979

8080
error[E0080]: it is undefined behavior to use this value
81-
--> $DIR/forbidden_slices.rs:43:1
81+
--> $DIR/forbidden_slices.rs:41:1
8282
|
8383
LL | pub static S8: &[u64] = unsafe {
8484
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@@ -98,7 +98,7 @@ note: inside `ptr::const_ptr::<impl *const u32>::sub_ptr`
9898
note: inside `from_ptr_range::<'_, u32>`
9999
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
100100
note: inside `R0`
101-
--> $DIR/forbidden_slices.rs:50:34
101+
--> $DIR/forbidden_slices.rs:48:34
102102
|
103103
LL | pub static R0: &[u32] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
104104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -113,7 +113,7 @@ note: inside `ptr::const_ptr::<impl *const ()>::sub_ptr`
113113
note: inside `from_ptr_range::<'_, ()>`
114114
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
115115
note: inside `R1`
116-
--> $DIR/forbidden_slices.rs:51:33
116+
--> $DIR/forbidden_slices.rs:49:33
117117
|
118118
LL | pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
119119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -127,13 +127,13 @@ error[E0080]: could not evaluate static initializer
127127
note: inside `ptr::const_ptr::<impl *const u32>::add`
128128
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
129129
note: inside `R2`
130-
--> $DIR/forbidden_slices.rs:54:25
130+
--> $DIR/forbidden_slices.rs:52:25
131131
|
132132
LL | from_ptr_range(ptr..ptr.add(2))
133133
| ^^^^^^^^^^
134134

135135
error[E0080]: it is undefined behavior to use this value
136-
--> $DIR/forbidden_slices.rs:56:1
136+
--> $DIR/forbidden_slices.rs:54:1
137137
|
138138
LL | pub static R4: &[u8] = unsafe {
139139
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer
@@ -144,7 +144,7 @@ LL | pub static R4: &[u8] = unsafe {
144144
}
145145

146146
error[E0080]: it is undefined behavior to use this value
147-
--> $DIR/forbidden_slices.rs:61:1
147+
--> $DIR/forbidden_slices.rs:59:1
148148
|
149149
LL | pub static R5: &[u8] = unsafe {
150150
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered a pointer, but expected an integer
@@ -157,7 +157,7 @@ LL | pub static R5: &[u8] = unsafe {
157157
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
158158

159159
error[E0080]: it is undefined behavior to use this value
160-
--> $DIR/forbidden_slices.rs:66:1
160+
--> $DIR/forbidden_slices.rs:64:1
161161
|
162162
LL | pub static R6: &[bool] = unsafe {
163163
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean
@@ -168,7 +168,7 @@ LL | pub static R6: &[bool] = unsafe {
168168
}
169169

170170
error[E0080]: it is undefined behavior to use this value
171-
--> $DIR/forbidden_slices.rs:71:1
171+
--> $DIR/forbidden_slices.rs:69:1
172172
|
173173
LL | pub static R7: &[u16] = unsafe {
174174
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
@@ -186,7 +186,7 @@ error[E0080]: could not evaluate static initializer
186186
note: inside `ptr::const_ptr::<impl *const u64>::add`
187187
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
188188
note: inside `R8`
189-
--> $DIR/forbidden_slices.rs:78:25
189+
--> $DIR/forbidden_slices.rs:76:25
190190
|
191191
LL | from_ptr_range(ptr..ptr.add(1))
192192
| ^^^^^^^^^^
@@ -201,7 +201,7 @@ note: inside `ptr::const_ptr::<impl *const u32>::sub_ptr`
201201
note: inside `from_ptr_range::<'_, u32>`
202202
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
203203
note: inside `R9`
204-
--> $DIR/forbidden_slices.rs:83:34
204+
--> $DIR/forbidden_slices.rs:81:34
205205
|
206206
LL | pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) };
207207
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -216,7 +216,7 @@ note: inside `ptr::const_ptr::<impl *const u32>::sub_ptr`
216216
note: inside `from_ptr_range::<'_, u32>`
217217
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
218218
note: inside `R10`
219-
--> $DIR/forbidden_slices.rs:84:35
219+
--> $DIR/forbidden_slices.rs:82:35
220220
|
221221
LL | pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) };
222222
| ^^^^^^^^^^^^^^^^^^^^^^^^

‎tests/ui/consts/const-eval/raw-pointer-ub.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(const_pointer_byte_offsets)]
2-
#![feature(pointer_byte_offsets)]
31
#![feature(const_mut_refs)]
42

53

‎tests/ui/consts/const-eval/raw-pointer-ub.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/raw-pointer-ub.rs:9:16
2+
--> $DIR/raw-pointer-ub.rs:7:16
33
|
44
LL | let _val = *ptr;
55
| ^^^^ accessing memory based on pointer with alignment 1, but alignment 4 is required
66

77
error[E0080]: evaluation of constant value failed
8-
--> $DIR/raw-pointer-ub.rs:16:5
8+
--> $DIR/raw-pointer-ub.rs:14:5
99
|
1010
LL | *ptr = 0;
1111
| ^^^^^^^^ accessing memory based on pointer with alignment 1, but alignment 4 is required
@@ -20,19 +20,19 @@ note: inside `copy_nonoverlapping::<u32>`
2020
note: inside `ptr::const_ptr::<impl *const u32>::copy_to_nonoverlapping`
2121
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
2222
note: inside `MISALIGNED_COPY`
23-
--> $DIR/raw-pointer-ub.rs:24:5
23+
--> $DIR/raw-pointer-ub.rs:22:5
2424
|
2525
LL | y.copy_to_nonoverlapping(&mut z, 1);
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727

2828
error[E0080]: evaluation of constant value failed
29-
--> $DIR/raw-pointer-ub.rs:36:16
29+
--> $DIR/raw-pointer-ub.rs:34:16
3030
|
3131
LL | let _val = (*ptr).0;
3232
| ^^^^^^^^ accessing memory based on pointer with alignment 4, but alignment 16 is required
3333

3434
error[E0080]: evaluation of constant value failed
35-
--> $DIR/raw-pointer-ub.rs:43:16
35+
--> $DIR/raw-pointer-ub.rs:41:16
3636
|
3737
LL | let _val = *ptr;
3838
| ^^^^ memory access failed: ALLOC0 has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds

‎tests/ui/consts/extra-const-ub/detect-extra-ub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// revisions: no_flag with_flag
22
// [no_flag] check-pass
33
// [with_flag] compile-flags: -Zextra-const-ub-checks
4-
#![feature(never_type, pointer_byte_offsets)]
4+
#![feature(never_type)]
55

66
use std::mem::transmute;
77
use std::ptr::addr_of;

‎tests/ui/consts/miri_unleashed/ptr_arith.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
2-
#![feature(core_intrinsics, pointer_byte_offsets)]
32

43
// During CTFE, we prevent pointer-to-int casts.
54
// Pointer comparisons are prevented in the trait system.

‎tests/ui/consts/miri_unleashed/ptr_arith.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0080]: could not evaluate static initializer
2-
--> $DIR/ptr_arith.rs:8:13
2+
--> $DIR/ptr_arith.rs:7:13
33
|
44
LL | let x = &0 as *const _ as usize;
55
| ^^^^^^^^^^^^^^^^^^^^^^^ exposing pointers is not possible at compile-time
66

77
error[E0080]: could not evaluate static initializer
8-
--> $DIR/ptr_arith.rs:16:14
8+
--> $DIR/ptr_arith.rs:15:14
99
|
1010
LL | let _v = x + 0;
1111
| ^ unable to turn pointer into integer
@@ -16,7 +16,7 @@ LL | let _v = x + 0;
1616
warning: skipping const checks
1717
|
1818
help: skipping check that does not even have a feature gate
19-
--> $DIR/ptr_arith.rs:8:13
19+
--> $DIR/ptr_arith.rs:7:13
2020
|
2121
LL | let x = &0 as *const _ as usize;
2222
| ^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)
Please sign in to comment.