-
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
Revert Vec::spare_capacity_mut
impl to prevent pointers invalidation
#82564
Conversation
Thanks! The implementation looks good, but we should also add a testcase in this function. Something like this should do it: // spare_capacity_mut
v.spare_capacity_mut();
assert_eq!(*v0, 13); |
@RalfJung I've tried adding the test, but it fails under miri. Backtrace
I would assume that the unique reference to the same allocation somewhat invalidates the pointer, but I'm not familiar enough with stacked borrows to be sure 😅 |
It still fails even with this PR? Uh... interesting. I might have to check out your branch and test locally, but it could be a few days until I have the time for that. Is line 1696 the new assert one that you added? |
You could run with |
Oh, well. Turns out, it's not. When I run the test with I assume there was a problem with caching, because after I run this:
Test started passing. I've also changed |
Uh, so now I have to understand that function's implementation as well to review this PR.^^ EDIT: Ah, |
Aside from that comment nit, LGTM. Thanks! |
Co-authored-by: Ralf Jung <[email protected]>
Yeah, sorry 😅
It reuses safe method ( EDIT: ooops, I'm a bit slow :p |
@bors r+ rollup |
📌 Commit 950f121 has been approved by |
…lfJung Revert `Vec::spare_capacity_mut` impl to prevent pointers invalidation The implementation was changed in rust-lang#79015. Later it was [pointed out](rust-lang#81944 (comment)) that the implementation invalidates pointers to the buffer (initialized elements) by creating a unique reference to the buffer. This PR reverts the implementation. r? `@RalfJung`
…lfJung Revert `Vec::spare_capacity_mut` impl to prevent pointers invalidation The implementation was changed in rust-lang#79015. Later it was [pointed out](rust-lang#81944 (comment)) that the implementation invalidates pointers to the buffer (initialized elements) by creating a unique reference to the buffer. This PR reverts the implementation. r? ``@RalfJung``
Rollup of 8 pull requests Successful merges: - rust-lang#80527 (Make rustdoc lints a tool lint instead of built-in) - rust-lang#82310 (Load rustdoc's JS search index on-demand.) - rust-lang#82315 (Improve page load performance in rustdoc) - rust-lang#82564 (Revert `Vec::spare_capacity_mut` impl to prevent pointers invalidation) - rust-lang#82697 (Fix stabilization version of move_ref_pattern) - rust-lang#82717 (Account for macros when suggesting adding lifetime) - rust-lang#82740 (Fix commit detected when using `download-rustc`) - rust-lang#82744 (Pass `CrateNum` by value instead of by reference) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The implementation was changed in #79015.
Later it was pointed out that the implementation invalidates pointers to the buffer (initialized elements) by creating a unique reference to the buffer. This PR reverts the implementation.
r? @RalfJung