@@ -417,8 +417,9 @@ impl<T: ?Sized> *const T {
417417 /// If any of the following conditions are violated, the result is Undefined
418418 /// Behavior:
419419 ///
420- /// * Both the starting and resulting pointer must be either in bounds or one
421- /// byte past the end of the same [allocated object].
420+ /// * If the computed offset is non-zero, then both the starting and resulting pointer must be
421+ /// either in bounds or one byte past the end of the same [allocated object].
422+ /// (If it is zero, then the function is allays well-defined.)
422423 ///
423424 /// * The computed offset, **in bytes**, cannot overflow an `isize`.
424425 ///
@@ -628,11 +629,11 @@ impl<T: ?Sized> *const T {
628629 /// If any of the following conditions are violated, the result is Undefined
629630 /// Behavior:
630631 ///
631- /// * Both `self` and `origin` must be either in bounds or one
632- /// byte past the end of the same [allocated object].
632+ /// * `self` and `origin` must either
633633 ///
634- /// * Both pointers must be *derived from* a pointer to the same object.
635- /// (See below for an example.)
634+ /// * both be *derived from* a pointer to the same [allocated object], and they must be either
635+ /// in bounds or one byte past the end of that object. (See below for an example.)
636+ /// * or both be derived from an integer literal/constant, and point to the same address.
636637 ///
637638 /// * The distance between the pointers, in bytes, must be an exact multiple
638639 /// of the size of `T`.
@@ -695,14 +696,14 @@ impl<T: ?Sized> *const T {
695696 /// let ptr1 = Box::into_raw(Box::new(0u8)) as *const u8;
696697 /// let ptr2 = Box::into_raw(Box::new(1u8)) as *const u8;
697698 /// let diff = (ptr2 as isize).wrapping_sub(ptr1 as isize);
698- /// // Make ptr2_other an "alias" of ptr2, but derived from ptr1.
699- /// let ptr2_other = (ptr1 as *const u8).wrapping_offset(diff);
699+ /// // Make ptr2_other an "alias" of ptr2.add(1) , but derived from ptr1.
700+ /// let ptr2_other = (ptr1 as *const u8).wrapping_offset(diff).wrapping_offset(1) ;
700701 /// assert_eq!(ptr2 as usize, ptr2_other as usize);
701702 /// // Since ptr2_other and ptr2 are derived from pointers to different objects,
702703 /// // computing their offset is undefined behavior, even though
703- /// // they point to the same address !
704+ /// // they point to addresses that are in-bounds of the same object !
704705 /// unsafe {
705- /// let zero = ptr2_other.offset_from(ptr2); // Undefined Behavior
706+ /// let one = ptr2_other.offset_from(ptr2); // Undefined Behavior
706707 /// }
707708 /// ```
708709 #[ stable( feature = "ptr_offset_from" , since = "1.47.0" ) ]
@@ -894,8 +895,9 @@ impl<T: ?Sized> *const T {
894895 /// If any of the following conditions are violated, the result is Undefined
895896 /// Behavior:
896897 ///
897- /// * Both the starting and resulting pointer must be either in bounds or one
898- /// byte past the end of the same [allocated object].
898+ /// * If the computed offset is non-zero, then both the starting and resulting pointer must be
899+ /// either in bounds or one byte past the end of the same [allocated object].
900+ /// (If it is zero, then the function is allays well-defined.)
899901 ///
900902 /// * The computed offset, **in bytes**, cannot overflow an `isize`.
901903 ///
@@ -978,8 +980,9 @@ impl<T: ?Sized> *const T {
978980 /// If any of the following conditions are violated, the result is Undefined
979981 /// Behavior:
980982 ///
981- /// * Both the starting and resulting pointer must be either in bounds or one
982- /// byte past the end of the same [allocated object].
983+ /// * If the computed offset is non-zero, then both the starting and resulting pointer must be
984+ /// either in bounds or one byte past the end of the same [allocated object].
985+ /// (If it is zero, then the function is allays well-defined.)
983986 ///
984987 /// * The computed offset cannot exceed `isize::MAX` **bytes**.
985988 ///
0 commit comments