-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 MaybeUninit::get_{ref,mut} documentation #65948
Improve MaybeUninit::get_{ref,mut} documentation #65948
Conversation
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
r? @RalfJung cc @SimonSapin @Centril |
71f8620
to
07522fa
Compare
07522fa
to
6067126
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
e4e5790
to
7d5e5ef
Compare
This comment has been minimized.
This comment has been minimized.
7d5e5ef
to
d9087cb
Compare
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.
Great work! These are very good examples. I just found some nits.
@Centril do you also want to take a look?
@RalfJung Thanks for the ping. I trust your review. :) |
24d1f30
to
3198ef5
Compare
Okay, I have fixed "the nits", so I think that regarding |
I prefer smaller PRs, that's much easier to review. @bors delegate+ r=me with the last nit fixed (this means you can do |
✌️ @danielhenrymantilla can now approve this pull request |
Co-Authored-By: Ralf Jung <[email protected]>
3198ef5
to
67f2200
Compare
@bors r=RalfJung |
📌 Commit 67f2200 has been approved by |
…t_ref_mut, r=RalfJung Improve MaybeUninit::get_{ref,mut} documentation As mentioned in rust-lang#63568 (comment), `MaybeUninit`'s `get_{ref,mut}` documentation is lacking, so this PR attempts to fix that. That being said, and as @RalfJung mentions in that thread, > In particular, we should clarify that all the UB rules for these methods equally apply when calling the raw ptr methods and creating a reference manually. these other docs also need to be improved, which I can do in this PR ~~(hence the `[WIP]`)~~. Finally, since all these documentations are related to clearly establishing when dealing with uninitialized memory which patterns are known to be sound and which patterns are currently UB (that is, until, if ever, the rules around references to unintialized integers get relaxed, this documentation will treat them as UB, and advise against such patterns (_e.g._, it is not possible to use uninitialized buffers with the `Read` API)), I think that adding even more examples to the main documentation of `MaybeUninit` inherent definition wouldn't hurt either. ___ - [Rendered](http://dreamy-ritchie-99d637.netlify.com/core/mem/union.maybeuninit#method.get_ref)
Rollup of 8 pull requests Successful merges: - #65948 (Improve MaybeUninit::get_{ref,mut} documentation) - #65953 (Allow specifying LLVM's MCTargetOptions::ABIName in target specification files) - #66012 (De-querify `trivial_dropck_outlives`.) - #66025 (`Span` cannot represent `span.hi < span.lo`) - #66047 (Don't double-count `simd_shuffle` promotion candidates) - #66053 (when Miri tests are not passing, do not add Miri component) - #66082 (clean highlightSourceLines code) - #66091 (Implemented the home_dir for VxWorks) Failed merges: r? @ghost
I'm sorry if this is inappropriate time or place to write this, but this is such a minor thing I hope it's better than filing an issue? The code snippet in assert!(
buf.chunks(2).all(|chunk| chunk[0] <= chunk[1]),
"buffer is sorted",
); It should use the |
Suggested by @ametisf in rust-lang#65948 (comment) Co-Authored-By: Frantisek Fladung <[email protected]>
…cs_replace_chunk_with_windows, r=Dylan-DPC Fix minor error in `MaybeUninit::get_mut()` doc example In the `MaybeUninit::get_mut()` example I wanted to assert that the slice was sorted and mistakenly used `.chunks(2)` rather than `.windows(2)` to assert it, as @ametisf pointed out in rust-lang#65948 (comment) . This fixes it.
…cs_replace_chunk_with_windows, r=Dylan-DPC Fix minor error in `MaybeUninit::get_mut()` doc example In the `MaybeUninit::get_mut()` example I wanted to assert that the slice was sorted and mistakenly used `.chunks(2)` rather than `.windows(2)` to assert it, as @ametisf pointed out in rust-lang#65948 (comment) . This fixes it.
…cs_replace_chunk_with_windows, r=Dylan-DPC Fix minor error in `MaybeUninit::get_mut()` doc example In the `MaybeUninit::get_mut()` example I wanted to assert that the slice was sorted and mistakenly used `.chunks(2)` rather than `.windows(2)` to assert it, as @ametisf pointed out in rust-lang#65948 (comment) . This fixes it.
As mentioned in #63568 (comment),
MaybeUninit
'sget_{ref,mut}
documentation is lacking, so this PR attempts to fix that.That being said, and as @RalfJung mentions in that thread,
these other docs also need to be improved, which I can do in this PR
(hence the.[WIP]
)Finally, since all these documentations are related to clearly establishing when dealing with uninitialized memory which patterns are known to be sound and which patterns are currently UB (that is, until, if ever, the rules around references to unintialized integers get relaxed, this documentation will treat them as UB, and advise against such patterns (e.g., it is not possible to use uninitialized buffers with the
Read
API)), I think that adding even more examples to the main documentation ofMaybeUninit
inherent definition wouldn't hurt either.