-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve offset_from docs #82751
improve offset_from docs #82751
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with that fixed.
Cc @rust-lang/lang I think this is already an established guarantee that "two pointers are within some allocated object of Rust type |
/// For instance, no known 64-bit platform can ever serve a request | ||
/// for 2<sup>63</sup> bytes due to page-table limitations or splitting the address space. | ||
/// However, some 32-bit and 16-bit platforms may successfully serve a request for | ||
/// more than `isize::MAX` bytes with things like Physical Address | ||
/// Extension. As such, memory acquired directly from allocators or memory | ||
/// mapped files *may* be too large to handle with this function. | ||
/// (Note that [`offset`] and [`add`] also have a similar limitation and hence cannot be used on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the link for offset
defined somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it already exists and is further up.
@bors r+ rollup |
📌 Commit ebe0407 has been approved by |
Rollup of 13 pull requests Successful merges: - rust-lang#77916 (Change built-in kernel targets to be os = none throughout) - rust-lang#82130 (Make some Option, Result methods unstably const) - rust-lang#82292 (Prevent specialized ZipImpl from calling `__iterator_get_unchecked` twice with the same index) - rust-lang#82402 (Remove RefCell around `module_trait_cache`) - rust-lang#82592 (Improve transmute docs with further clarifications) - rust-lang#82651 (Cleanup rustdoc warnings) - rust-lang#82720 (Fix diagnostic suggests adding type `[type error]`) - rust-lang#82751 (improve offset_from docs) - rust-lang#82793 (Move some tests to more suitable subdirs) - rust-lang#82803 (rustdoc: Add an unstable option to print all unversioned files) - rust-lang#82808 (Sync rustc_codegen_cranelift) - rust-lang#82822 (Fix typo) - rust-lang#82837 (tweak MaybeUninit docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
@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 ofoffset_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 thanisize::MAX
(or rather, Rust heap allocation methods should require that theLayout
is no larger thanisize::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 sinceptr::offset
/ptr::add
do not support offsetting by more thanisize::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