Skip to content

Commit 14fac9b

Browse files
authored
Rollup merge of rust-lang#137121 - bend-n:master, r=Noratrieb
stabilize `(const_)ptr_sub_ptr` Tracking issue: rust-lang#95892 Closes rust-lang#95892 FCP Completed: rust-lang#95892 (comment) r? `@Noratrieb`
2 parents 760aaf7 + 92fd960 commit 14fac9b

File tree

11 files changed

+27
-43
lines changed

11 files changed

+27
-43
lines changed

compiler/rustc_serialize/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![feature(core_intrinsics)]
1414
#![feature(min_specialization)]
1515
#![feature(never_type)]
16-
#![feature(ptr_sub_ptr)]
1716
#![feature(rustdoc_internals)]
1817
#![warn(unreachable_pub)]
1918
// tidy-alphabetical-end

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
#![feature(pointer_like_trait)]
138138
#![feature(ptr_internals)]
139139
#![feature(ptr_metadata)]
140-
#![feature(ptr_sub_ptr)]
141140
#![feature(set_ptr_value)]
142141
#![feature(sized_type_properties)]
143142
#![feature(slice_from_ptr_range)]

library/core/src/intrinsics/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,7 @@ pub const unsafe fn ptr_offset_from<T>(_ptr: *const T, _base: *const T) -> isize
36363636
#[rustc_nounwind]
36373637
#[rustc_intrinsic]
36383638
#[rustc_intrinsic_must_be_overridden]
3639+
#[rustc_intrinsic_const_stable_indirect]
36393640
pub const unsafe fn ptr_offset_from_unsigned<T>(_ptr: *const T, _base: *const T) -> usize {
36403641
unimplemented!()
36413642
}

library/core/src/ptr/const_ptr.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ impl<T: ?Sized> *const T {
723723
/// to [`sub`](#method.sub)). The following are all equivalent, assuming
724724
/// that their safety preconditions are met:
725725
/// ```rust
726-
/// # #![feature(ptr_sub_ptr)]
727726
/// # unsafe fn blah(ptr: *const i32, origin: *const i32, count: usize) -> bool { unsafe {
728727
/// ptr.sub_ptr(origin) == count
729728
/// # &&
@@ -752,8 +751,6 @@ impl<T: ?Sized> *const T {
752751
/// # Examples
753752
///
754753
/// ```
755-
/// #![feature(ptr_sub_ptr)]
756-
///
757754
/// let a = [0; 5];
758755
/// let ptr1: *const i32 = &a[1];
759756
/// let ptr2: *const i32 = &a[3];
@@ -767,8 +764,8 @@ impl<T: ?Sized> *const T {
767764
/// // This would be incorrect, as the pointers are not correctly ordered:
768765
/// // ptr1.sub_ptr(ptr2)
769766
/// ```
770-
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
771-
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
767+
#[stable(feature = "ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
768+
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
772769
#[inline]
773770
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
774771
pub const unsafe fn sub_ptr(self, origin: *const T) -> usize
@@ -812,8 +809,8 @@ impl<T: ?Sized> *const T {
812809
///
813810
/// For non-`Sized` pointees this operation considers only the data pointers,
814811
/// ignoring the metadata.
815-
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
816-
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
812+
#[stable(feature = "ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
813+
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
817814
#[inline]
818815
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
819816
pub const unsafe fn byte_sub_ptr<U: ?Sized>(self, origin: *const U) -> usize {

library/core/src/ptr/mut_ptr.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,6 @@ impl<T: ?Sized> *mut T {
895895
/// to [`sub`](#method.sub)). The following are all equivalent, assuming
896896
/// that their safety preconditions are met:
897897
/// ```rust
898-
/// # #![feature(ptr_sub_ptr)]
899898
/// # unsafe fn blah(ptr: *mut i32, origin: *mut i32, count: usize) -> bool { unsafe {
900899
/// ptr.sub_ptr(origin) == count
901900
/// # &&
@@ -924,8 +923,6 @@ impl<T: ?Sized> *mut T {
924923
/// # Examples
925924
///
926925
/// ```
927-
/// #![feature(ptr_sub_ptr)]
928-
///
929926
/// let mut a = [0; 5];
930927
/// let p: *mut i32 = a.as_mut_ptr();
931928
/// unsafe {
@@ -940,8 +937,8 @@ impl<T: ?Sized> *mut T {
940937
///
941938
/// // This would be incorrect, as the pointers are not correctly ordered:
942939
/// // ptr1.offset_from(ptr2)
943-
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
944-
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
940+
#[stable(feature = "ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
941+
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
945942
#[inline]
946943
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
947944
pub const unsafe fn sub_ptr(self, origin: *const T) -> usize
@@ -962,8 +959,8 @@ impl<T: ?Sized> *mut T {
962959
///
963960
/// For non-`Sized` pointees this operation considers only the data pointers,
964961
/// ignoring the metadata.
965-
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
966-
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
962+
#[stable(feature = "ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
963+
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
967964
#[inline]
968965
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
969966
pub const unsafe fn byte_sub_ptr<U: ?Sized>(self, origin: *mut U) -> usize {

library/core/src/ptr/non_null.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ impl<T: ?Sized> NonNull<T> {
856856
/// to [`sub`](#method.sub)). The following are all equivalent, assuming
857857
/// that their safety preconditions are met:
858858
/// ```rust
859-
/// # #![feature(ptr_sub_ptr)]
860859
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool { unsafe {
861860
/// ptr.sub_ptr(origin) == count
862861
/// # &&
@@ -885,7 +884,6 @@ impl<T: ?Sized> NonNull<T> {
885884
/// # Examples
886885
///
887886
/// ```
888-
/// #![feature(ptr_sub_ptr)]
889887
/// use std::ptr::NonNull;
890888
///
891889
/// let a = [0; 5];
@@ -903,8 +901,8 @@ impl<T: ?Sized> NonNull<T> {
903901
/// ```
904902
#[inline]
905903
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
906-
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
907-
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
904+
#[stable(feature = "ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
905+
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
908906
pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize
909907
where
910908
T: Sized,
@@ -925,8 +923,8 @@ impl<T: ?Sized> NonNull<T> {
925923
/// ignoring the metadata.
926924
#[inline(always)]
927925
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
928-
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
929-
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
926+
#[stable(feature = "ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
927+
#[rustc_const_stable(feature = "const_ptr_sub_ptr", since = "CURRENT_RUSTC_VERSION")]
930928
pub const unsafe fn byte_sub_ptr<U: ?Sized>(self, origin: NonNull<U>) -> usize {
931929
// SAFETY: the caller must uphold the safety contract for `byte_sub_ptr`.
932930
unsafe { self.as_ptr().byte_sub_ptr(origin.as_ptr()) }

src/tools/miri/tests/fail/intrinsics/ptr_offset_from_unsigned_neg.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@normalize-stderr-test: "\d+ < \d+" -> "$$ADDR < $$ADDR"
2-
#![feature(ptr_sub_ptr)]
3-
42
fn main() {
53
let arr = [0u8; 8];
64
let ptr1 = arr.as_ptr();

src/tools/miri/tests/pass/ptr_offset.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@compile-flags: -Zmiri-permissive-provenance
2-
#![feature(ptr_sub_ptr)]
32
use std::{mem, ptr};
43

54
fn main() {

tests/ui/consts/offset_from.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//@ run-pass
22

3-
#![feature(const_ptr_sub_ptr)]
4-
#![feature(ptr_sub_ptr)]
5-
63
struct Struct {
74
field: (),
85
}

tests/ui/consts/offset_from_ub.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ normalize-stderr: "\d+ bytes" -> "$$BYTES bytes"
2-
#![feature(const_ptr_sub_ptr)]
32
#![feature(core_intrinsics)]
43

54
use std::intrinsics::{ptr_offset_from, ptr_offset_from_unsigned};

tests/ui/consts/offset_from_ub.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/offset_from_ub.rs:19:27
2+
--> $DIR/offset_from_ub.rs:18:27
33
|
44
LL | let offset = unsafe { ptr_offset_from(field_ptr, base_ptr) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called on two different pointers that are not both derived from the same allocation
@@ -12,67 +12,67 @@ error[E0080]: evaluation of constant value failed
1212
note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from`
1313
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
1414
note: inside `NOT_PTR`
15-
--> $DIR/offset_from_ub.rs:25:14
15+
--> $DIR/offset_from_ub.rs:24:14
1616
|
1717
LL | unsafe { (42 as *const u8).offset_from(&5u8) as usize }
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919

2020
error[E0080]: evaluation of constant value failed
21-
--> $DIR/offset_from_ub.rs:32:14
21+
--> $DIR/offset_from_ub.rs:31:14
2222
|
2323
LL | unsafe { ptr_offset_from(field_ptr, base_ptr as *const u16) }
2424
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ exact_div: 1_isize cannot be divided by 2_isize without remainder
2525

2626
error[E0080]: evaluation of constant value failed
27-
--> $DIR/offset_from_ub.rs:39:14
27+
--> $DIR/offset_from_ub.rs:38:14
2828
|
2929
LL | unsafe { ptr_offset_from(ptr2, ptr1) }
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called on two different pointers that are not both derived from the same allocation
3131

3232
error[E0080]: evaluation of constant value failed
33-
--> $DIR/offset_from_ub.rs:48:14
33+
--> $DIR/offset_from_ub.rs:47:14
3434
|
3535
LL | unsafe { ptr_offset_from(end_ptr, start_ptr) }
3636
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called on two different pointers where the memory range between them is not in-bounds of an allocation
3737

3838
error[E0080]: evaluation of constant value failed
39-
--> $DIR/offset_from_ub.rs:57:14
39+
--> $DIR/offset_from_ub.rs:56:14
4040
|
4141
LL | unsafe { ptr_offset_from(start_ptr, end_ptr) }
4242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called on two different pointers where the memory range between them is not in-bounds of an allocation
4343

4444
error[E0080]: evaluation of constant value failed
45-
--> $DIR/offset_from_ub.rs:66:14
45+
--> $DIR/offset_from_ub.rs:65:14
4646
|
4747
LL | unsafe { ptr_offset_from_unsigned(field_ptr, base_ptr) }
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called on two different pointers that are not both derived from the same allocation
4949

5050
error[E0080]: evaluation of constant value failed
51-
--> $DIR/offset_from_ub.rs:73:14
51+
--> $DIR/offset_from_ub.rs:72:14
5252
|
5353
LL | unsafe { ptr_offset_from(ptr2, ptr1) }
5454
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called when first pointer is too far ahead of second
5555

5656
error[E0080]: evaluation of constant value failed
57-
--> $DIR/offset_from_ub.rs:79:14
57+
--> $DIR/offset_from_ub.rs:78:14
5858
|
5959
LL | unsafe { ptr_offset_from(ptr1, ptr2) }
6060
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called when first pointer is too far before second
6161

6262
error[E0080]: evaluation of constant value failed
63-
--> $DIR/offset_from_ub.rs:87:14
63+
--> $DIR/offset_from_ub.rs:86:14
6464
|
6565
LL | unsafe { ptr_offset_from(ptr1, ptr2) }
6666
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called when first pointer is too far before second
6767

6868
error[E0080]: evaluation of constant value failed
69-
--> $DIR/offset_from_ub.rs:94:14
69+
--> $DIR/offset_from_ub.rs:93:14
7070
|
7171
LL | unsafe { ptr_offset_from_unsigned(p, p.add(2) ) }
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called when first pointer has smaller offset than second: 0 < 8
7373

7474
error[E0080]: evaluation of constant value failed
75-
--> $DIR/offset_from_ub.rs:101:14
75+
--> $DIR/offset_from_ub.rs:100:14
7676
|
7777
LL | unsafe { ptr_offset_from_unsigned(ptr2, ptr1) }
7878
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from_unsigned` called when first pointer is too far ahead of second
@@ -85,7 +85,7 @@ error[E0080]: evaluation of constant value failed
8585
note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from`
8686
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
8787
note: inside `OFFSET_VERY_FAR1`
88-
--> $DIR/offset_from_ub.rs:110:14
88+
--> $DIR/offset_from_ub.rs:109:14
8989
|
9090
LL | unsafe { ptr2.offset_from(ptr1) }
9191
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -98,7 +98,7 @@ error[E0080]: evaluation of constant value failed
9898
note: inside `std::ptr::const_ptr::<impl *const u8>::offset_from`
9999
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
100100
note: inside `OFFSET_VERY_FAR2`
101-
--> $DIR/offset_from_ub.rs:116:14
101+
--> $DIR/offset_from_ub.rs:115:14
102102
|
103103
LL | unsafe { ptr1.offset_from(ptr2.wrapping_offset(1)) }
104104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)