Skip to content

Commit

Permalink
Apply CR suggestions; add real tracking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed May 12, 2022
1 parent 4bb15b3 commit 003b954
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ impl<T: ?Sized> *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
/// # &&
Expand Down Expand Up @@ -656,7 +656,7 @@ impl<T: ?Sized> *const T {
/// # Examples
///
/// ```
/// #![feature(ptr_unsigned_offset_from)]
/// #![feature(ptr_sub_ptr)]
///
/// let a = [0; 5];
/// let ptr1: *const i32 = &a[1];
Expand All @@ -671,8 +671,8 @@ impl<T: ?Sized> *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
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ impl<T: ?Sized> *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
/// # &&
Expand Down Expand Up @@ -832,7 +832,7 @@ impl<T: ?Sized> *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();
Expand All @@ -848,8 +848,8 @@ impl<T: ?Sized> *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
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/consts/offset_from.rs
Original file line number Diff line number Diff line change
@@ -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: (),
Expand Down

0 comments on commit 003b954

Please sign in to comment.