-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Change {Box,Arc,Rc,Weak}::into_raw
to only work with A = Global
#141219
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
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I don't know why this is failing on Miri... I only moved the methods and didn't change any implementation (except |
This comment has been minimized.
This comment has been minimized.
@RalfJung Do you have any idea why these miri tests would fail? The only relevant change is moving |
Yeah it has to do with this comment. This is part of the general issue that adding allocators to |
Sure, but the implementation of I don't see why changing the bounds on that methods from |
Miri has no choice but use some terrible hacks to work around the poor state that |
I pushed a commit that should hopefully fix CI. |
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.
r=me pending approval from the rest of libs-api
@rustbot label +A-box +A-allocators +A-MIR +A-miri |
☔ The latest upstream changes (presumably #142483) made this pull request unmergeable. Please resolve the merge conflicts. |
Looks good to me as a libs-api member! This affects unstable code only: |
Also applies to `Vec::into_raw_parts`. The expectation is that you can round-trip these methods with `from_raw`, but this is only true when using the global allocator. With custom allocators you should instead be using `into_raw_with_allocator` and `from_raw_in`. The implementation of `Box::leak` is changed to use `Box::into_raw_with_allocator` and explicitly leak the allocator (which was already the existing behavior). This is because, for `leak` to be safe, the allocator must not free its underlying backing store. The `Allocator` trait only guarantees that allocated memory remains valid until the allocator is dropped.
@bors r=joboet |
This comment has been minimized.
This comment has been minimized.
I had pushed a Miri fix into this PR in the past... did that get force-pushed away? |
Yeah, looks like it... @Amanieu I would recommend never using
|
Meanwhile, please cherry-pick 432a1c0, I hope that still fixes the problem. I won't push to this branch again to avoid repeating history. ;) |
@bors r=joboet |
Thanks, I've added that and will try to remember to use it in the future! |
// Avoid `into_raw_with_allocator` as that interacts poorly with Miri's Stacked Borrows. | ||
let mut b = mem::ManuallyDrop::new(b); | ||
// We go through the built-in deref for `Box`, which is crucial for Miri to recognize this | ||
// operation for it's alias tracking. |
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.
Nit: its* 😅
Rollup of 11 pull requests Successful merges: - #131923 (Derive `Copy` and `Hash` for `IntErrorKind`) - #138340 (Remove some unsized tuple impls now that we don't support unsizing tuples anymore) - #141219 (Change `{Box,Arc,Rc,Weak}::into_raw` to only work with `A = Global`) - #142212 (bootstrap: validate `rust.codegen-backends` & `target.<triple>.codegen-backends`) - #142237 (Detect more cases of unused_parens around types) - #142964 (Attribute rework: a parser for single attributes without arguments) - #143070 (Rewrite `macro_rules!` parser to not use the MBE engine itself) - #143235 (Assemble const bounds via normal item bounds in old solver too) - #143261 (Feed `explicit_predicates_of` instead of `predicates_of`) - #143276 (loop match: handle opaque patterns) - #143306 (Add `track_caller` attributes to trace origin of Clippy lints) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl try-job: test-various
Rollup of 11 pull requests Successful merges: - #131923 (Derive `Copy` and `Hash` for `IntErrorKind`) - #138340 (Remove some unsized tuple impls now that we don't support unsizing tuples anymore) - #141219 (Change `{Box,Arc,Rc,Weak}::into_raw` to only work with `A = Global`) - #142212 (bootstrap: validate `rust.codegen-backends` & `target.<triple>.codegen-backends`) - #142237 (Detect more cases of unused_parens around types) - #142964 (Attribute rework: a parser for single attributes without arguments) - #143070 (Rewrite `macro_rules!` parser to not use the MBE engine itself) - #143235 (Assemble const bounds via normal item bounds in old solver too) - #143261 (Feed `explicit_predicates_of` instead of `predicates_of`) - #143276 (loop match: handle opaque patterns) - #143306 (Add `track_caller` attributes to trace origin of Clippy lints) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl try-job: test-various
Rollup merge of #141219 - Amanieu:leak_alloc, r=joboet Change `{Box,Arc,Rc,Weak}::into_raw` to only work with `A = Global` Also applies to `Vec::into_raw_parts`. The expectation is that you can round-trip these methods with `from_raw`, but this is only true when using the global allocator. With custom allocators you should instead be using `into_raw_with_allocator` and `from_raw_in`. The implementation of `Box::leak` is changed to use `Box::into_raw_with_allocator` and explicitly leak the allocator (which was already the existing behavior). This is because, for `leak` to be safe, the allocator must not free its underlying backing store. The `Allocator` trait only guarantees that allocated memory remains valid until the allocator is dropped.
Fix issue introduced by rust-lang/rust#141219 - [x] Changelog updated
Also applies to
Vec::into_raw_parts
.The expectation is that you can round-trip these methods with
from_raw
, but this is only true when using the global allocator. With custom allocators you should instead be usinginto_raw_with_allocator
andfrom_raw_in
.The implementation of
Box::leak
is changed to useBox::into_raw_with_allocator
and explicitly leak the allocator (which was already the existing behavior). This is because, forleak
to be safe, the allocator must not free its underlying backing store. TheAllocator
trait only guarantees that allocated memory remains valid until the allocator is dropped.