-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
adds [*mut|*const] ptr::set_ptr_value #74774
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.
These should go further down in the documentation. Near the offsetting methods would make sense. Maybe in between wrapping_sub
and read
.
Done. Although I always thought documentation was generated alphabetically, so in-file function order did not matter? |
☔ The latest upstream changes (presumably #73265) made this pull request unmergeable. Please resolve the merge conflicts. |
made a complete mess trying to merge the recent directory structure changes, but everything should be ok again |
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. Could you open a tracking issue and update the issue number in the unstable
attributes in the PR?
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.
Thanks!
@bors r+ |
📌 Commit 6c81556 has been approved by |
⌛ Testing commit 6c81556 with merge 24265c7b79dcb81fb22b9d4c8e14acb89cb7a736... |
💥 Test timed out |
What's the significance of the test time out and what can I do about it? |
@bors retry |
I think there is some code in |
Mild concern: this is The version of this in the |
Mild concern: a main usecase of this is to implement the [ Offsetting a pointer to sized type by a byte offset is At the least, I think it'd be better for the "pointer to data" pointer for these methods to be |
adds [*mut|*const] ptr::set_ptr_value I propose the addition of these two functions to `*mut T` and `*const T`, respectively. The motivation for this is primarily byte-wise pointer arithmetic on (potentially) fat pointers, i.e. for types with a `T: ?Sized` bound. A concrete use-case has been discussed in [this](https://internals.rust-lang.org/t/byte-wise-fat-pointer-arithmetic/12739) thread. TL;DR: Currently, byte-wise pointer arithmetic with potentially fat pointers in not possible in either stable or nightly Rust without making assumptions about the layout of fat pointers, which is currently still an implementation detail and not formally stabilized. This PR adds one function to `*mut T` and `*const T` each, allowing to circumvent this restriction without exposing any internal implementation details. One possible alternative would be to add specific byte-wise pointer arithmetic functions to the two pointer types in addition to the already existing count-wise functions. However, I feel this fairly niche use case does not warrant adding a whole set of new functions like `add_bytes`, `offset_bytes`, `wrapping_offset_bytes`, etc. (times two, one for each pointer type) to `libcore`.
…arth Rollup of 4 pull requests Successful merges: - rust-lang#74774 (adds [*mut|*const] ptr::set_ptr_value) - rust-lang#75079 (Disallow linking to items with a mismatched disambiguator) - rust-lang#75203 (Make `IntoIterator` lifetime bounds of `&BTreeMap` match with `&HashMap` ) - rust-lang#75227 (Fix ICE when using asm! on an unsupported architecture) Failed merges: r? @ghost
Ok, I am a bit confused by the merge process. So the initial changes have been merged as part of a roll-up, but not that latest commit I've made addressing the latest change requests and neither has the PR itself been merged. |
@oliver-giersch looks like you pushed something after approval -- in fact even after rollup, so it was not considered. Can you make a new PR with just those remaining changes? |
Got it, I wasn't aware that I wasn't supposed to make changes after approval, will keep that in mind for further contributions. The rollup also occurred only a few minutes before I made the final commit. Should I close this PR now? |
Yeah it's better to wait for someone to Yes please close this PR and make a new one for what got missed. Great that you noticed this. :) |
…fJung Requested changes to [*mut T|*const T]::set_ptr_value This is a follow-up to PR rust-lang#74774 (tracking issue rust-lang#75091), acting on some change requests made after approval: - adds `#[must_use]` attribute - changes type of `val` pointer argument from `()` to `u8` - adjusts documentation mentioning pointer provenance
I propose the addition of these two functions to
*mut T
and*const T
, respectively. The motivation for this is primarily byte-wise pointer arithmetic on (potentially) fat pointers, i.e. for types with aT: ?Sized
bound. A concrete use-case has been discussed in this thread.TL;DR: Currently, byte-wise pointer arithmetic with potentially fat pointers in not possible in either stable or nightly Rust without making assumptions about the layout of fat pointers, which is currently still an implementation detail and not formally stabilized. This PR adds one function to
*mut T
and*const T
each, allowing to circumvent this restriction without exposing any internal implementation details.One possible alternative would be to add specific byte-wise pointer arithmetic functions to the two pointer types in addition to the already existing count-wise functions. However, I feel this fairly niche use case does not warrant adding a whole set of new functions like
add_bytes
,offset_bytes
,wrapping_offset_bytes
, etc. (times two, one for each pointer type) tolibcore
.