]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #82751 - RalfJung:offset_from, r=dtolnay
authorYuki Okushi <huyuumi.dev@gmail.com>
Sun, 7 Mar 2021 01:41:16 +0000 (10:41 +0900)
committerGitHub <noreply@github.com>
Sun, 7 Mar 2021 01:41:16 +0000 (10:41 +0900)
commit05a2366e82165a20dd352a62873fab84cd8d97cd
tree3fbf3b429579e533d99c2c342d22ebfa3a09bfa9
parenta5a825e6a33456836a18576aada23d52f757078f
parentebe0407dbf1e0e2135ca75c47d525f6217959eba
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`