From 003b954a43a7f1f9058f25e8f9b6ddfd4a3dced9 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 10 Apr 2022 16:02:52 -0700 Subject: [PATCH] Apply CR suggestions; add real tracking issue --- compiler/rustc_const_eval/src/interpret/intrinsics.rs | 2 ++ library/alloc/src/lib.rs | 2 +- library/core/src/lib.rs | 1 + library/core/src/ptr/const_ptr.rs | 8 ++++---- library/core/src/ptr/mut_ptr.rs | 8 ++++---- src/test/ui/consts/offset_from.rs | 3 ++- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 3bb3b3d539323..59ea40dc2f94e 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -377,6 +377,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } let pointee_layout = self.layout_of(substs.type_at(0))?; + // This re-interprets an isize at ret_layout, but we already checked + // that if ret_layout is usize, then the result must be non-negative. let val = ImmTy::from_scalar(val, ret_layout); let size = ImmTy::from_int(pointee_layout.size.bytes(), ret_layout); self.exact_div(&val, &size, dest)?; diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 1c569e156077b..fd21b3671182b 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -127,7 +127,7 @@ #![feature(pattern)] #![feature(ptr_internals)] #![feature(ptr_metadata)] -#![feature(ptr_unsigned_offset_from)] +#![feature(ptr_sub_ptr)] #![feature(receiver_trait)] #![feature(set_ptr_value)] #![feature(slice_group_by)] diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 1612aa582ad17..d1936b6b566c1 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -126,6 +126,7 @@ #![feature(const_option)] #![feature(const_option_ext)] #![feature(const_pin)] +#![feature(const_ptr_sub_ptr)] #![feature(const_replace)] #![feature(const_ptr_as_ref)] #![feature(const_ptr_is_null)] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 7fcdf21b03cde..028adc796e526 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -627,7 +627,7 @@ impl *const T { /// to [`sub`](#method.sub)). The following are all equivalent, assuming /// that their safety preconditions are met: /// ```rust - /// # #![feature(ptr_unsigned_offset_from)] + /// # #![feature(ptr_sub_ptr)] /// # unsafe fn blah(ptr: *const i32, origin: *const i32, count: usize) -> bool { /// ptr.sub_ptr(origin) == count /// # && @@ -656,7 +656,7 @@ impl *const T { /// # Examples /// /// ``` - /// #![feature(ptr_unsigned_offset_from)] + /// #![feature(ptr_sub_ptr)] /// /// let a = [0; 5]; /// let ptr1: *const i32 = &a[1]; @@ -671,8 +671,8 @@ impl *const T { /// // This would be incorrect, as the pointers are not correctly ordered: /// // ptr1.offset_from(ptr2) /// ``` - #[unstable(feature = "ptr_unsigned_offset_from", issue = "88888888")] - #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")] + #[unstable(feature = "ptr_sub_ptr", issue = "95892")] + #[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")] #[inline] pub const unsafe fn sub_ptr(self, origin: *const T) -> usize where diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index c7f297f426bdb..1a32dd62dfd55 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -803,7 +803,7 @@ impl *mut T { /// to [`sub`](#method.sub)). The following are all equivalent, assuming /// that their safety preconditions are met: /// ```rust - /// # #![feature(ptr_unsigned_offset_from)] + /// # #![feature(ptr_sub_ptr)] /// # unsafe fn blah(ptr: *mut i32, origin: *mut i32, count: usize) -> bool { /// ptr.sub_ptr(origin) == count /// # && @@ -832,7 +832,7 @@ impl *mut T { /// # Examples /// /// ``` - /// #![feature(ptr_unsigned_offset_from)] + /// #![feature(ptr_sub_ptr)] /// /// let mut a = [0; 5]; /// let p: *mut i32 = a.as_mut_ptr(); @@ -848,8 +848,8 @@ impl *mut T { /// /// // This would be incorrect, as the pointers are not correctly ordered: /// // ptr1.offset_from(ptr2) - #[unstable(feature = "ptr_unsigned_offset_from", issue = "88888888")] - #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")] + #[unstable(feature = "ptr_sub_ptr", issue = "95892")] + #[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")] #[inline] pub const unsafe fn sub_ptr(self, origin: *const T) -> usize where diff --git a/src/test/ui/consts/offset_from.rs b/src/test/ui/consts/offset_from.rs index ad834e885a51c..b53718316f3b5 100644 --- a/src/test/ui/consts/offset_from.rs +++ b/src/test/ui/consts/offset_from.rs @@ -1,7 +1,8 @@ // run-pass #![feature(const_ptr_offset_from)] -#![feature(ptr_unsigned_offset_from)] +#![feature(const_ptr_sub_ptr)] +#![feature(ptr_sub_ptr)] struct Struct { field: (),