-
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 Vec example soundness in mem::transmute docs #64436
Conversation
9a607fd
to
6f5c261
Compare
6f5c261
to
15a353b
Compare
Nice! Yes However, the code is still somewhat confusing, with its three examples in one doctest and the {
let v = v_orig.clone();
// Here comes the "way" do do stuff with `v`.
} That would make it more clear that the clone is part of the "environment" here, not part of what is really going on. However, we can also land this PR without that change as it is a definite improvement. |
15a353b
to
9d6c4f2
Compare
9d6c4f2
to
51d3168
Compare
src/libcore/intrinsics.rs
Outdated
@@ -847,19 +847,24 @@ extern "rust-intrinsic" { | |||
/// let store = [0, 1, 2, 3]; | |||
/// let mut v_orig = store.iter().collect::<Vec<&i32>>(); | |||
/// | |||
/// // clone the references as we will reuse them later |
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.
Why not "clone the vector"?
src/libcore/intrinsics.rs
Outdated
/// v_orig.len(), | ||
/// v_orig.capacity()) | ||
/// // Ensure the original vector is not dropped. | ||
/// let v_clone: &mut Vec<_> = &mut *std::mem::ManuallyDrop::new(v_clone); |
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.
/// let v_clone: &mut Vec<_> = &mut *std::mem::ManuallyDrop::new(v_clone); | |
/// let v_clone = std::mem::ManuallyDrop::new(v_clone); |
This should work due to the Deref
, right? And I think it is more readable.
51d3168
to
14bb755
Compare
@RalfJung thanks for the review! |
LGTM, thanks! @bors r+ rollup |
📌 Commit 14bb7550cd65a90f38ae3f17c2e46a7bb17b47aa has been approved by |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors r- delegate+ |
✌️ @llogiq can now approve this pull request |
14bb755
to
ab6e108
Compare
@bors r=RalfJung |
📌 Commit ab6e108 has been approved by |
improve Vec example soundness in mem::transmute docs The previous version of the `Vec` example had a case of questionable soundness, because at one point `v_orig` was aliased. r? @RalfJung
improve Vec example soundness in mem::transmute docs The previous version of the `Vec` example had a case of questionable soundness, because at one point `v_orig` was aliased. r? @RalfJung
Rollup of 10 pull requests Successful merges: - #61626 (Get rid of special const intrinsic query in favour of `const_eval`) - #64283 (Updated RELEASES.md for 1.38.0) - #64394 (Shrink `SubregionOrigin`.) - #64429 (Fix failure note `to_str` implementation) - #64436 (improve Vec example soundness in mem::transmute docs) - #64502 (avoid duplicate issues for Miri build failures) - #64505 (Fix inconsistent link formatting) - #64529 (Add an example to Pin::as_mut) - #64541 (document Miri error categories) - #64544 (build-manifest: re-add some comments) Failed merges: r? @ghost
The previous version of the
Vec
example had a case of questionable soundness, because at one pointv_orig
was aliased.r? @RalfJung