@@ -189,8 +189,7 @@ impl<T: ?Sized> *mut T {
189
189
/// Behavior:
190
190
///
191
191
/// * Both the starting and resulting pointer must be either in bounds or one
192
- /// byte past the end of the same allocated object. Note that in Rust,
193
- /// every (stack-allocated) variable is considered a separate allocated object.
192
+ /// byte past the end of the same [allocated object].
194
193
///
195
194
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
196
195
///
@@ -215,6 +214,7 @@ impl<T: ?Sized> *mut T {
215
214
/// enables more aggressive compiler optimizations.
216
215
///
217
216
/// [`wrapping_offset`]: #method.wrapping_offset
217
+ /// [allocated object]: crate::ptr#allocated-object
218
218
///
219
219
/// # Examples
220
220
///
@@ -251,9 +251,8 @@ impl<T: ?Sized> *mut T {
251
251
///
252
252
/// This operation itself is always safe, but using the resulting pointer is not.
253
253
///
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. Note that in Rust, every
256
- /// (stack-allocated) variable is considered a separate 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.
257
256
///
258
257
/// In other words, `let z = x.wrapping_offset((y as isize) - (x as isize))` does *not* make `z`
259
258
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -271,10 +270,8 @@ impl<T: ?Sized> *mut T {
271
270
/// `x.wrapping_offset(o).wrapping_offset(o.wrapping_neg())` is always the same as `x`. In other
272
271
/// words, leaving the allocated object and then re-entering it later is permitted.
273
272
///
274
- /// If you need to cross object boundaries, cast the pointer to an integer and
275
- /// do the arithmetic there.
276
- ///
277
273
/// [`offset`]: #method.offset
274
+ /// [allocated object]: crate::ptr#allocated-object
278
275
///
279
276
/// # Examples
280
277
///
@@ -485,8 +482,7 @@ impl<T: ?Sized> *mut T {
485
482
/// Behavior:
486
483
///
487
484
/// * Both the starting and other pointer must be either in bounds or one
488
- /// byte past the end of the same allocated object. Note that in Rust,
489
- /// every (stack-allocated) variable is considered a separate allocated object.
485
+ /// byte past the end of the same [allocated object].
490
486
///
491
487
/// * Both pointers must be *derived from* a pointer to the same object.
492
488
/// (See below for an example.)
@@ -516,6 +512,7 @@ impl<T: ?Sized> *mut T {
516
512
/// such large allocations either.)
517
513
///
518
514
/// [`add`]: #method.add
515
+ /// [allocated object]: crate::ptr#allocated-object
519
516
///
520
517
/// # Panics
521
518
///
@@ -575,8 +572,7 @@ impl<T: ?Sized> *mut T {
575
572
/// Behavior:
576
573
///
577
574
/// * Both the starting and resulting pointer must be either in bounds or one
578
- /// byte past the end of the same allocated object. Note that in Rust,
579
- /// every (stack-allocated) variable is considered a separate allocated object.
575
+ /// byte past the end of the same [allocated object].
580
576
///
581
577
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
582
578
///
@@ -639,8 +635,7 @@ impl<T: ?Sized> *mut T {
639
635
/// Behavior:
640
636
///
641
637
/// * Both the starting and resulting pointer must be either in bounds or one
642
- /// byte past the end of the same allocated object. Note that in Rust,
643
- /// every (stack-allocated) variable is considered a separate allocated object.
638
+ /// byte past the end of the same [allocated object].
644
639
///
645
640
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
646
641
///
@@ -665,6 +660,7 @@ impl<T: ?Sized> *mut T {
665
660
/// enables more aggressive compiler optimizations.
666
661
///
667
662
/// [`wrapping_sub`]: #method.wrapping_sub
663
+ /// [allocated object]: crate::ptr#allocated-object
668
664
///
669
665
/// # Examples
670
666
///
@@ -701,9 +697,8 @@ impl<T: ?Sized> *mut T {
701
697
///
702
698
/// This operation itself is always safe, but using the resulting pointer is not.
703
699
///
704
- /// The resulting pointer remains attached to the same allocated object that `self` points to.
705
- /// It may *not* be used to access a different allocated object. Note that in Rust, every
706
- /// (stack-allocated) variable is considered a separate 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.
707
702
///
708
703
/// In other words, `let z = x.wrapping_add((y as usize) - (x as usize))` does *not* make `z`
709
704
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -721,10 +716,8 @@ impl<T: ?Sized> *mut T {
721
716
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
722
717
/// allocated object and then re-entering it later is permitted.
723
718
///
724
- /// If you need to cross object boundaries, cast the pointer to an integer and
725
- /// do the arithmetic there.
726
- ///
727
719
/// [`add`]: #method.add
720
+ /// [allocated object]: crate::ptr#allocated-object
728
721
///
729
722
/// # Examples
730
723
///
@@ -766,9 +759,8 @@ impl<T: ?Sized> *mut T {
766
759
///
767
760
/// This operation itself is always safe, but using the resulting pointer is not.
768
761
///
769
- /// The resulting pointer remains attached to the same allocated object that `self` points to.
770
- /// It may *not* be used to access a different allocated object. Note that in Rust, every
771
- /// (stack-allocated) variable is considered a separate 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.
772
764
///
773
765
/// In other words, `let z = x.wrapping_sub((x as usize) - (y as usize))` does *not* make `z`
774
766
/// the same as `y` even if we assume `T` has size `1` and there is no overflow: `z` is still
@@ -786,10 +778,8 @@ impl<T: ?Sized> *mut T {
786
778
/// `x.wrapping_add(o).wrapping_sub(o)` is always the same as `x`. In other words, leaving the
787
779
/// allocated object and then re-entering it later is permitted.
788
780
///
789
- /// If you need to cross object boundaries, cast the pointer to an integer and
790
- /// do the arithmetic there.
791
- ///
792
781
/// [`sub`]: #method.sub
782
+ /// [allocated object]: crate::ptr#allocated-object
793
783
///
794
784
/// # Examples
795
785
///
@@ -1261,7 +1251,7 @@ impl<T> *mut [T] {
1261
1251
/// * The pointer must be [valid] for reads for `ptr.len() * mem::size_of::<T>()` many bytes,
1262
1252
/// and it must be properly aligned. This means in particular:
1263
1253
///
1264
- /// * The entire memory range of this slice must be contained within a single allocated object!
1254
+ /// * The entire memory range of this slice must be contained within a single [ allocated object] !
1265
1255
/// Slices can never span across multiple allocated objects.
1266
1256
///
1267
1257
/// * The pointer must be aligned even for zero-length slices. One
@@ -1283,6 +1273,7 @@ impl<T> *mut [T] {
1283
1273
/// See also [`slice::from_raw_parts`][].
1284
1274
///
1285
1275
/// [valid]: crate::ptr#safety
1276
+ /// [allocated object]: crate::ptr#allocated-object
1286
1277
#[ inline]
1287
1278
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
1288
1279
pub unsafe fn as_uninit_slice < ' a > ( self ) -> Option < & ' a [ MaybeUninit < T > ] > {
@@ -1311,7 +1302,7 @@ impl<T> *mut [T] {
1311
1302
/// * The pointer must be [valid] for reads and writes for `ptr.len() * mem::size_of::<T>()`
1312
1303
/// many bytes, and it must be properly aligned. This means in particular:
1313
1304
///
1314
- /// * The entire memory range of this slice must be contained within a single allocated object!
1305
+ /// * The entire memory range of this slice must be contained within a single [ allocated object] !
1315
1306
/// Slices can never span across multiple allocated objects.
1316
1307
///
1317
1308
/// * The pointer must be aligned even for zero-length slices. One
@@ -1333,6 +1324,7 @@ impl<T> *mut [T] {
1333
1324
/// See also [`slice::from_raw_parts_mut`][].
1334
1325
///
1335
1326
/// [valid]: crate::ptr#safety
1327
+ /// [allocated object]: crate::ptr#allocated-object
1336
1328
#[ inline]
1337
1329
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
1338
1330
pub unsafe fn as_uninit_slice_mut < ' a > ( self ) -> Option < & ' a mut [ MaybeUninit < T > ] > {
0 commit comments