@@ -1120,7 +1120,8 @@ impl<T: ?Sized> *const T {
1120
1120
/// Behavior:
1121
1121
///
1122
1122
/// * Both the starting and resulting pointer must be either in bounds or one
1123
- /// byte past the end of the same allocated object.
1123
+ /// byte past the end of the same allocated object. Note that in Rust,
1124
+ /// every (stack-allocated) variable is considered a separate allocated object.
1124
1125
///
1125
1126
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
1126
1127
///
@@ -1140,10 +1141,12 @@ impl<T: ?Sized> *const T {
1140
1141
/// Extension. As such, memory acquired directly from allocators or memory
1141
1142
/// mapped files *may* be too large to handle with this function.
1142
1143
///
1143
- /// Consider using `wrapping_offset` instead if these constraints are
1144
+ /// Consider using [ `wrapping_offset`] instead if these constraints are
1144
1145
/// difficult to satisfy. The only advantage of this method is that it
1145
1146
/// enables more aggressive compiler optimizations.
1146
1147
///
1148
+ /// [`wrapping_offset`]: #method.wrapping_offset
1149
+ ///
1147
1150
/// # Examples
1148
1151
///
1149
1152
/// Basic usage:
@@ -1172,15 +1175,26 @@ impl<T: ?Sized> *const T {
1172
1175
///
1173
1176
/// The resulting pointer does not need to be in bounds, but it is
1174
1177
/// potentially hazardous to dereference (which requires `unsafe`).
1175
- /// In particular, the resulting pointer may *not* be used to access a
1176
- /// different allocated object than the one `self` points to. In other
1177
- /// words, `x.wrapping_offset(y.wrapping_offset_from(x))` is
1178
+ ///
1179
+ /// In particular, the resulting pointer remains attached to the same allocated
1180
+ /// object that `self` points to. It may *not* be used to access a
1181
+ /// different allocated object. Note that in Rust,
1182
+ /// every (stack-allocated) variable is considered a separate allocated object.
1183
+ ///
1184
+ /// In other words, `x.wrapping_offset(y.wrapping_offset_from(x))` is
1178
1185
/// *not* the same as `y`, and dereferencing it is undefined behavior
1179
1186
/// unless `x` and `y` point into the same allocated object.
1180
1187
///
1181
- /// Always use `.offset(count)` instead when possible, because `offset`
1182
- /// allows the compiler to optimize better. If you need to cross object
1183
- /// boundaries, cast the pointer to an integer and do the arithmetic there.
1188
+ /// Compared to [`offset`], this method basically delays the requirement of staying
1189
+ /// within the same allocated object: [`offset`] is immediate Undefined Behavior when
1190
+ /// crossing object boundaries; `wrapping_offset` produces a pointer but still leads
1191
+ /// to Undefined Behavior if that pointer is dereferenced. [`offset`] can be optimized
1192
+ /// better and is thus preferrable in performance-sensitive code.
1193
+ ///
1194
+ /// If you need to cross object boundaries, cast the pointer to an integer and
1195
+ /// do the arithmetic there.
1196
+ ///
1197
+ /// [`offset`]: #method.offset
1184
1198
///
1185
1199
/// # Examples
1186
1200
///
@@ -1223,7 +1237,8 @@ impl<T: ?Sized> *const T {
1223
1237
/// Behavior:
1224
1238
///
1225
1239
/// * Both the starting and other pointer must be either in bounds or one
1226
- /// byte past the end of the same allocated object.
1240
+ /// byte past the end of the same allocated object. Note that in Rust,
1241
+ /// every (stack-allocated) variable is considered a separate allocated object.
1227
1242
///
1228
1243
/// * The distance between the pointers, **in bytes**, cannot overflow an `isize`.
1229
1244
///
@@ -1338,7 +1353,8 @@ impl<T: ?Sized> *const T {
1338
1353
/// Behavior:
1339
1354
///
1340
1355
/// * Both the starting and resulting pointer must be either in bounds or one
1341
- /// byte past the end of the same allocated object.
1356
+ /// byte past the end of the same allocated object. Note that in Rust,
1357
+ /// every (stack-allocated) variable is considered a separate allocated object.
1342
1358
///
1343
1359
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
1344
1360
///
@@ -1358,10 +1374,12 @@ impl<T: ?Sized> *const T {
1358
1374
/// Extension. As such, memory acquired directly from allocators or memory
1359
1375
/// mapped files *may* be too large to handle with this function.
1360
1376
///
1361
- /// Consider using `wrapping_offset` instead if these constraints are
1377
+ /// Consider using [`wrapping_add`] instead if these constraints are
1362
1378
/// difficult to satisfy. The only advantage of this method is that it
1363
1379
/// enables more aggressive compiler optimizations.
1364
1380
///
1381
+ /// [`wrapping_add`]: #method.wrapping_add
1382
+ ///
1365
1383
/// # Examples
1366
1384
///
1367
1385
/// Basic usage:
@@ -1395,7 +1413,8 @@ impl<T: ?Sized> *const T {
1395
1413
/// Behavior:
1396
1414
///
1397
1415
/// * Both the starting and resulting pointer must be either in bounds or one
1398
- /// byte past the end of the same allocated object.
1416
+ /// byte past the end of the same allocated object. Note that in Rust,
1417
+ /// every (stack-allocated) variable is considered a separate allocated object.
1399
1418
///
1400
1419
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
1401
1420
///
@@ -1415,10 +1434,12 @@ impl<T: ?Sized> *const T {
1415
1434
/// Extension. As such, memory acquired directly from allocators or memory
1416
1435
/// mapped files *may* be too large to handle with this function.
1417
1436
///
1418
- /// Consider using `wrapping_offset` instead if these constraints are
1437
+ /// Consider using [`wrapping_sub`] instead if these constraints are
1419
1438
/// difficult to satisfy. The only advantage of this method is that it
1420
1439
/// enables more aggressive compiler optimizations.
1421
1440
///
1441
+ /// [`wrapping_sub`]: #method.wrapping_sub
1442
+ ///
1422
1443
/// # Examples
1423
1444
///
1424
1445
/// Basic usage:
@@ -1451,8 +1472,21 @@ impl<T: ?Sized> *const T {
1451
1472
/// The resulting pointer does not need to be in bounds, but it is
1452
1473
/// potentially hazardous to dereference (which requires `unsafe`).
1453
1474
///
1454
- /// Always use `.add(count)` instead when possible, because `add`
1455
- /// allows the compiler to optimize better.
1475
+ /// In particular, the resulting pointer remains attached to the same allocated
1476
+ /// object that `self` points to. It may *not* be used to access a
1477
+ /// different allocated object. Note that in Rust,
1478
+ /// every (stack-allocated) variable is considered a separate allocated object.
1479
+ ///
1480
+ /// Compared to [`add`], this method basically delays the requirement of staying
1481
+ /// within the same allocated object: [`add`] is immediate Undefined Behavior when
1482
+ /// crossing object boundaries; `wrapping_add` produces a pointer but still leads
1483
+ /// to Undefined Behavior if that pointer is dereferenced. [`add`] can be optimized
1484
+ /// better and is thus preferrable in performance-sensitive code.
1485
+ ///
1486
+ /// If you need to cross object boundaries, cast the pointer to an integer and
1487
+ /// do the arithmetic there.
1488
+ ///
1489
+ /// [`add`]: #method.add
1456
1490
///
1457
1491
/// # Examples
1458
1492
///
@@ -1492,8 +1526,21 @@ impl<T: ?Sized> *const T {
1492
1526
/// The resulting pointer does not need to be in bounds, but it is
1493
1527
/// potentially hazardous to dereference (which requires `unsafe`).
1494
1528
///
1495
- /// Always use `.sub(count)` instead when possible, because `sub`
1496
- /// allows the compiler to optimize better.
1529
+ /// In particular, the resulting pointer remains attached to the same allocated
1530
+ /// object that `self` points to. It may *not* be used to access a
1531
+ /// different allocated object. Note that in Rust,
1532
+ /// every (stack-allocated) variable is considered a separate allocated object.
1533
+ ///
1534
+ /// Compared to [`sub`], this method basically delays the requirement of staying
1535
+ /// within the same allocated object: [`sub`] is immediate Undefined Behavior when
1536
+ /// crossing object boundaries; `wrapping_sub` produces a pointer but still leads
1537
+ /// to Undefined Behavior if that pointer is dereferenced. [`sub`] can be optimized
1538
+ /// better and is thus preferrable in performance-sensitive code.
1539
+ ///
1540
+ /// If you need to cross object boundaries, cast the pointer to an integer and
1541
+ /// do the arithmetic there.
1542
+ ///
1543
+ /// [`sub`]: #method.sub
1497
1544
///
1498
1545
/// # Examples
1499
1546
///
@@ -1757,7 +1804,8 @@ impl<T: ?Sized> *mut T {
1757
1804
/// Behavior:
1758
1805
///
1759
1806
/// * Both the starting and resulting pointer must be either in bounds or one
1760
- /// byte past the end of the same allocated object.
1807
+ /// byte past the end of the same allocated object. Note that in Rust,
1808
+ /// every (stack-allocated) variable is considered a separate allocated object.
1761
1809
///
1762
1810
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
1763
1811
///
@@ -1777,10 +1825,12 @@ impl<T: ?Sized> *mut T {
1777
1825
/// Extension. As such, memory acquired directly from allocators or memory
1778
1826
/// mapped files *may* be too large to handle with this function.
1779
1827
///
1780
- /// Consider using `wrapping_offset` instead if these constraints are
1828
+ /// Consider using [ `wrapping_offset`] instead if these constraints are
1781
1829
/// difficult to satisfy. The only advantage of this method is that it
1782
1830
/// enables more aggressive compiler optimizations.
1783
1831
///
1832
+ /// [`wrapping_offset`]: #method.wrapping_offset
1833
+ ///
1784
1834
/// # Examples
1785
1835
///
1786
1836
/// Basic usage:
@@ -1808,15 +1858,26 @@ impl<T: ?Sized> *mut T {
1808
1858
///
1809
1859
/// The resulting pointer does not need to be in bounds, but it is
1810
1860
/// potentially hazardous to dereference (which requires `unsafe`).
1811
- /// In particular, the resulting pointer may *not* be used to access a
1812
- /// different allocated object than the one `self` points to. In other
1813
- /// words, `x.wrapping_offset(y.wrapping_offset_from(x))` is
1861
+ ///
1862
+ /// In particular, the resulting pointer remains attached to the same allocated
1863
+ /// object that `self` points to. It may *not* be used to access a
1864
+ /// different allocated object. Note that in Rust,
1865
+ /// every (stack-allocated) variable is considered a separate allocated object.
1866
+ ///
1867
+ /// In other words, `x.wrapping_offset(y.wrapping_offset_from(x))` is
1814
1868
/// *not* the same as `y`, and dereferencing it is undefined behavior
1815
1869
/// unless `x` and `y` point into the same allocated object.
1816
1870
///
1817
- /// Always use `.offset(count)` instead when possible, because `offset`
1818
- /// allows the compiler to optimize better. If you need to cross object
1819
- /// boundaries, cast the pointer to an integer and do the arithmetic there.
1871
+ /// Compared to [`offset`], this method basically delays the requirement of staying
1872
+ /// within the same allocated object: [`offset`] is immediate Undefined Behavior when
1873
+ /// crossing object boundaries; `wrapping_offset` produces a pointer but still leads
1874
+ /// to Undefined Behavior if that pointer is dereferenced. [`offset`] can be optimized
1875
+ /// better and is thus preferrable in performance-sensitive code.
1876
+ ///
1877
+ /// If you need to cross object boundaries, cast the pointer to an integer and
1878
+ /// do the arithmetic there.
1879
+ ///
1880
+ /// [`offset`]: #method.offset
1820
1881
///
1821
1882
/// # Examples
1822
1883
///
@@ -1903,7 +1964,8 @@ impl<T: ?Sized> *mut T {
1903
1964
/// Behavior:
1904
1965
///
1905
1966
/// * Both the starting and other pointer must be either in bounds or one
1906
- /// byte past the end of the same allocated object.
1967
+ /// byte past the end of the same allocated object. Note that in Rust,
1968
+ /// every (stack-allocated) variable is considered a separate allocated object.
1907
1969
///
1908
1970
/// * The distance between the pointers, **in bytes**, cannot overflow an `isize`.
1909
1971
///
@@ -2007,7 +2069,8 @@ impl<T: ?Sized> *mut T {
2007
2069
/// Behavior:
2008
2070
///
2009
2071
/// * Both the starting and resulting pointer must be either in bounds or one
2010
- /// byte past the end of the same allocated object.
2072
+ /// byte past the end of the same allocated object. Note that in Rust,
2073
+ /// every (stack-allocated) variable is considered a separate allocated object.
2011
2074
///
2012
2075
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
2013
2076
///
@@ -2027,10 +2090,12 @@ impl<T: ?Sized> *mut T {
2027
2090
/// Extension. As such, memory acquired directly from allocators or memory
2028
2091
/// mapped files *may* be too large to handle with this function.
2029
2092
///
2030
- /// Consider using `wrapping_offset` instead if these constraints are
2093
+ /// Consider using [`wrapping_add`] instead if these constraints are
2031
2094
/// difficult to satisfy. The only advantage of this method is that it
2032
2095
/// enables more aggressive compiler optimizations.
2033
2096
///
2097
+ /// [`wrapping_add`]: #method.wrapping_add
2098
+ ///
2034
2099
/// # Examples
2035
2100
///
2036
2101
/// Basic usage:
@@ -2064,7 +2129,8 @@ impl<T: ?Sized> *mut T {
2064
2129
/// Behavior:
2065
2130
///
2066
2131
/// * Both the starting and resulting pointer must be either in bounds or one
2067
- /// byte past the end of the same allocated object.
2132
+ /// byte past the end of the same allocated object. Note that in Rust,
2133
+ /// every (stack-allocated) variable is considered a separate allocated object.
2068
2134
///
2069
2135
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
2070
2136
///
@@ -2084,10 +2150,12 @@ impl<T: ?Sized> *mut T {
2084
2150
/// Extension. As such, memory acquired directly from allocators or memory
2085
2151
/// mapped files *may* be too large to handle with this function.
2086
2152
///
2087
- /// Consider using `wrapping_offset` instead if these constraints are
2153
+ /// Consider using [`wrapping_sub`] instead if these constraints are
2088
2154
/// difficult to satisfy. The only advantage of this method is that it
2089
2155
/// enables more aggressive compiler optimizations.
2090
2156
///
2157
+ /// [`wrapping_sub`]: #method.wrapping_sub
2158
+ ///
2091
2159
/// # Examples
2092
2160
///
2093
2161
/// Basic usage:
@@ -2120,8 +2188,21 @@ impl<T: ?Sized> *mut T {
2120
2188
/// The resulting pointer does not need to be in bounds, but it is
2121
2189
/// potentially hazardous to dereference (which requires `unsafe`).
2122
2190
///
2123
- /// Always use `.add(count)` instead when possible, because `add`
2124
- /// allows the compiler to optimize better.
2191
+ /// In particular, the resulting pointer remains attached to the same allocated
2192
+ /// object that `self` points to. It may *not* be used to access a
2193
+ /// different allocated object. Note that in Rust,
2194
+ /// every (stack-allocated) variable is considered a separate allocated object.
2195
+ ///
2196
+ /// Compared to [`add`], this method basically delays the requirement of staying
2197
+ /// within the same allocated object: [`add`] is immediate Undefined Behavior when
2198
+ /// crossing object boundaries; `wrapping_add` produces a pointer but still leads
2199
+ /// to Undefined Behavior if that pointer is dereferenced. [`add`] can be optimized
2200
+ /// better and is thus preferrable in performance-sensitive code.
2201
+ ///
2202
+ /// If you need to cross object boundaries, cast the pointer to an integer and
2203
+ /// do the arithmetic there.
2204
+ ///
2205
+ /// [`add`]: #method.add
2125
2206
///
2126
2207
/// # Examples
2127
2208
///
@@ -2161,8 +2242,21 @@ impl<T: ?Sized> *mut T {
2161
2242
/// The resulting pointer does not need to be in bounds, but it is
2162
2243
/// potentially hazardous to dereference (which requires `unsafe`).
2163
2244
///
2164
- /// Always use `.sub(count)` instead when possible, because `sub`
2165
- /// allows the compiler to optimize better.
2245
+ /// In particular, the resulting pointer remains attached to the same allocated
2246
+ /// object that `self` points to. It may *not* be used to access a
2247
+ /// different allocated object. Note that in Rust,
2248
+ /// every (stack-allocated) variable is considered a separate allocated object.
2249
+ ///
2250
+ /// Compared to [`sub`], this method basically delays the requirement of staying
2251
+ /// within the same allocated object: [`sub`] is immediate Undefined Behavior when
2252
+ /// crossing object boundaries; `wrapping_sub` produces a pointer but still leads
2253
+ /// to Undefined Behavior if that pointer is dereferenced. [`sub`] can be optimized
2254
+ /// better and is thus preferrable in performance-sensitive code.
2255
+ ///
2256
+ /// If you need to cross object boundaries, cast the pointer to an integer and
2257
+ /// do the arithmetic there.
2258
+ ///
2259
+ /// [`sub`]: #method.sub
2166
2260
///
2167
2261
/// # Examples
2168
2262
///
0 commit comments