Commit 05a2366
authored
Rollup merge of #82751 - RalfJung:offset_from, r=dtolnay
improve offset_from docs
`@thomcc` pointed out that the current docs leave it kind of unclear how one can satisfy the "no wrapping around `isize` or the address space" requirement of `offset_from`, so make the docs clearer about that.
FWIW, I don't think I entirely agree with that second paragraph about large objects (that I left mostly unchanged here). LLVM, to my knowledge, fundamentally assumes that all allocations fit into an `isize::MAX`. So in that sense creating a larger allocation is simply UB. I would expect a guarantee that Rust heap allocation methods will never return allocations larger than `isize::MAX` (or rather, Rust heap allocation methods should require that the `Layout` is no larger than `isize::MAX`). However, I cannot find any such requirement documented currently. Large allocations are not mentioned at all in the allocator docs, which is quite surprising -- even if we say that such allocations are not insta-UB (which I think is incompatible with LLVM), they are still extremely footgunny since `ptr::offset`/`ptr::add` do not support offsetting by more than `isize::MAX` bytes.
Furthermore, the allocator docs don't even say anything about allocations wrapping around the address space. But that is certainly something allocators must ensure never happens; we cannot expect clients to defend against this.
Cc `@rust-lang/wg-allocators`2 files changed
+26
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
324 | | - | |
325 | 323 | | |
326 | 324 | | |
327 | 325 | | |
| 326 | + | |
| 327 | + | |
328 | 328 | | |
329 | 329 | | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
334 | 336 | | |
335 | | - | |
| 337 | + | |
336 | 338 | | |
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
340 | 342 | | |
341 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
342 | 348 | | |
343 | 349 | | |
344 | 350 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
491 | 491 | | |
492 | 492 | | |
493 | 493 | | |
494 | | - | |
495 | | - | |
496 | 494 | | |
497 | 495 | | |
498 | 496 | | |
| 497 | + | |
| 498 | + | |
499 | 499 | | |
500 | 500 | | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
505 | 507 | | |
506 | | - | |
| 508 | + | |
507 | 509 | | |
508 | 510 | | |
509 | 511 | | |
510 | 512 | | |
511 | 513 | | |
512 | 514 | | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
513 | 519 | | |
514 | 520 | | |
515 | 521 | | |
| |||
0 commit comments