Auto merge of #127777 - matthiaskrgr:rollup-qp2vkan, r=matthiaskrgr · model-checking/verify-rust-std@a778c83

@@ -735,9 +735,9 @@ impl<T: ?Sized> NonNull<T> {

735735

///

736736

/// * `self` and `origin` must either

737737

///

738+

/// * point to the same address, or

738739

/// * both be *derived from* a pointer to the same [allocated object], and the memory range between

739-

/// the two pointers must be either empty or in bounds of that object. (See below for an example.)

740-

/// * or both be derived from an integer literal/constant, and point to the same address.

740+

/// the two pointers must be in bounds of that object. (See below for an example.)

741741

///

742742

/// * The distance between the pointers, in bytes, must be an exact multiple

743743

/// of the size of `T`.

@@ -789,14 +789,15 @@ impl<T: ?Sized> NonNull<T> {

789789

/// let ptr1 = NonNull::new(Box::into_raw(Box::new(0u8))).unwrap();

790790

/// let ptr2 = NonNull::new(Box::into_raw(Box::new(1u8))).unwrap();

791791

/// let diff = (ptr2.addr().get() as isize).wrapping_sub(ptr1.addr().get() as isize);

792-

/// // Make ptr2_other an "alias" of ptr2, but derived from ptr1.

793-

/// let ptr2_other = NonNull::new(ptr1.as_ptr().wrapping_byte_offset(diff)).unwrap();

792+

/// // Make ptr2_other an "alias" of ptr2.add(1), but derived from ptr1.

793+

/// let diff_plus_1 = diff.wrapping_add(1);

794+

/// let ptr2_other = NonNull::new(ptr1.as_ptr().wrapping_byte_offset(diff_plus_1)).unwrap();

794795

/// assert_eq!(ptr2.addr(), ptr2_other.addr());

795796

/// // Since ptr2_other and ptr2 are derived from pointers to different objects,

796797

/// // computing their offset is undefined behavior, even though

797-

/// // they point to the same address!

798+

/// // they point to addresses that are in-bounds of the same object!

798799

///

799-

/// let zero = unsafe { ptr2_other.offset_from(ptr2) }; // Undefined Behavior

800+

/// let one = unsafe { ptr2_other.offset_from(ptr2) }; // Undefined Behavior! ⚠️

800801

/// ```

801802

#[inline]

802803

#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces