@@ -627,11 +627,9 @@ impl<T: ?Sized> *const T {
627
627
/// If any of the following conditions are violated, the result is Undefined
628
628
/// Behavior:
629
629
///
630
- /// * Both `self` and `origin` must be either in bounds or one
631
- /// byte past the end of the same [allocated object].
632
- ///
633
- /// * Both pointers must be *derived from* a pointer to the same object.
634
- /// (See below for an example.)
630
+ /// * If `self` and `origin` point to different addresses, then they must both be *derived from*
631
+ /// a pointer to the same [allocated object], and they must be either in bounds or one byte
632
+ /// past the end of that object. (See below for an example.)
635
633
///
636
634
/// * The distance between the pointers, in bytes, must be an exact multiple
637
635
/// of the size of `T`.
@@ -695,13 +693,13 @@ impl<T: ?Sized> *const T {
695
693
/// let ptr2 = Box::into_raw(Box::new(1u8)) as *const u8;
696
694
/// let diff = (ptr2 as isize).wrapping_sub(ptr1 as isize);
697
695
/// // Make ptr2_other an "alias" of ptr2, but derived from ptr1.
698
- /// let ptr2_other = (ptr1 as *const u8).wrapping_offset(diff);
696
+ /// let ptr2_other = (ptr1 as *const u8).wrapping_offset(diff).wrapping_offset(1) ;
699
697
/// assert_eq!(ptr2 as usize, ptr2_other as usize);
700
698
/// // Since ptr2_other and ptr2 are derived from pointers to different objects,
701
699
/// // computing their offset is undefined behavior, even though
702
- /// // they point to the same address !
700
+ /// // they point to addresses that are in-bounds of the same object !
703
701
/// unsafe {
704
- /// let zero = ptr2_other.offset_from(ptr2); // Undefined Behavior
702
+ /// let one = ptr2_other.offset_from(ptr2); // Undefined Behavior
705
703
/// }
706
704
/// ```
707
705
#[ stable( feature = "ptr_offset_from" , since = "1.47.0" ) ]
0 commit comments