Skip to content

Commit ae5d378

Browse files
committed
clarify 'remains attached', and remove recommendation to use integer arithmetic
1 parent 06d8c1d commit ae5d378

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

core/src/ptr/const_ptr.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ impl<T: ?Sized> *const T {
245245
///
246246
/// This operation itself is always safe, but using the resulting pointer is not.
247247
///
248-
/// The resulting pointer remains attached to the same [allocated object] that `self` points to.
249-
/// It may *not* be used to access a different allocated object.
248+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
249+
/// be used to read or write other allocated objects.
250250
///
251251
/// In other words, `let z = x.wrapping_offset((y as isize) - (x as isize))` does *not* make `z`
252252
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -264,9 +264,6 @@ impl<T: ?Sized> *const T {
264264
/// `x.wrapping_offset(o).wrapping_offset(o.wrapping_neg())` is always the same as `x`. In other
265265
/// words, leaving the allocated object and then re-entering it later is permitted.
266266
///
267-
/// If you need to cross object boundaries, cast the pointer to an integer and
268-
/// do the arithmetic there.
269-
///
270267
/// [`offset`]: #method.offset
271268
/// [allocated object]: crate::ptr#allocated-object
272269
///
@@ -594,8 +591,8 @@ impl<T: ?Sized> *const T {
594591
///
595592
/// This operation itself is always safe, but using the resulting pointer is not.
596593
///
597-
/// The resulting pointer remains attached to the same [allocated object] that `self` points to.
598-
/// It may *not* be used to access a different allocated object.
594+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
595+
/// be used to read or write other allocated objects.
599596
///
600597
/// In other words, `let z = x.wrapping_add((y as usize) - (x as usize))` does *not* make `z`
601598
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -613,9 +610,6 @@ impl<T: ?Sized> *const T {
613610
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
614611
/// allocated object and then re-entering it later is permitted.
615612
///
616-
/// If you need to cross object boundaries, cast the pointer to an integer and
617-
/// do the arithmetic there.
618-
///
619613
/// [`add`]: #method.add
620614
/// [allocated object]: crate::ptr#allocated-object
621615
///
@@ -659,8 +653,8 @@ impl<T: ?Sized> *const T {
659653
///
660654
/// This operation itself is always safe, but using the resulting pointer is not.
661655
///
662-
/// The resulting pointer remains attached to the same [allocated object] that `self` points to.
663-
/// It may *not* be used to access a different allocated object.
656+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
657+
/// be used to read or write other allocated objects.
664658
///
665659
/// In other words, `let z = x.wrapping_sub((x as usize) - (y as usize))` does *not* make `z`
666660
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -678,9 +672,6 @@ impl<T: ?Sized> *const T {
678672
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
679673
/// allocated object and then re-entering it later is permitted.
680674
///
681-
/// If you need to cross object boundaries, cast the pointer to an integer and
682-
/// do the arithmetic there.
683-
///
684675
/// [`sub`]: #method.sub
685676
/// [allocated object]: crate::ptr#allocated-object
686677
///

core/src/ptr/mut_ptr.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ impl<T: ?Sized> *mut T {
251251
///
252252
/// This operation itself is always safe, but using the resulting pointer is not.
253253
///
254-
/// The resulting pointer remains attached to the same [allocated object] that `self` points to.
255-
/// It may *not* be used to access a different allocated object.
254+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
255+
/// be used to read or write other allocated objects.
256256
///
257257
/// In other words, `let z = x.wrapping_offset((y as isize) - (x as isize))` does *not* make `z`
258258
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -270,9 +270,6 @@ impl<T: ?Sized> *mut T {
270270
/// `x.wrapping_offset(o).wrapping_offset(o.wrapping_neg())` is always the same as `x`. In other
271271
/// words, leaving the allocated object and then re-entering it later is permitted.
272272
///
273-
/// If you need to cross object boundaries, cast the pointer to an integer and
274-
/// do the arithmetic there.
275-
///
276273
/// [`offset`]: #method.offset
277274
/// [allocated object]: crate::ptr#allocated-object
278275
///
@@ -700,8 +697,8 @@ impl<T: ?Sized> *mut T {
700697
///
701698
/// This operation itself is always safe, but using the resulting pointer is not.
702699
///
703-
/// The resulting pointer remains attached to the same [allocated object] that `self` points to.
704-
/// It may *not* be used to access a different allocated object.
700+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
701+
/// be used to read or write other allocated objects.
705702
///
706703
/// In other words, `let z = x.wrapping_add((y as usize) - (x as usize))` does *not* make `z`
707704
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -719,9 +716,6 @@ impl<T: ?Sized> *mut T {
719716
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
720717
/// allocated object and then re-entering it later is permitted.
721718
///
722-
/// If you need to cross object boundaries, cast the pointer to an integer and
723-
/// do the arithmetic there.
724-
///
725719
/// [`add`]: #method.add
726720
/// [allocated object]: crate::ptr#allocated-object
727721
///
@@ -765,8 +759,8 @@ impl<T: ?Sized> *mut T {
765759
///
766760
/// This operation itself is always safe, but using the resulting pointer is not.
767761
///
768-
/// The resulting pointer remains attached to the same [allocated object] that `self` points to.
769-
/// It may *not* be used to access a different allocated object.
762+
/// The resulting pointer "remembers" the [allocated object] that `self` points to; it may not
763+
/// be used to read or write other allocated objects.
770764
///
771765
/// In other words, `let z = x.wrapping_sub((x as usize) - (y as usize))` does *not* make `z`
772766
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -784,9 +778,6 @@ impl<T: ?Sized> *mut T {
784778
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
785779
/// allocated object and then re-entering it later is permitted.
786780
///
787-
/// If you need to cross object boundaries, cast the pointer to an integer and
788-
/// do the arithmetic there.
789-
///
790781
/// [`sub`]: #method.sub
791782
/// [allocated object]: crate::ptr#allocated-object
792783
///

0 commit comments

Comments
 (0)