Uh oh!
There was an error while loading. Please reload this page.
Unstably constify ptr::drop_in_place and related methods - #146187
Conversation
rustbot
commented
Sep 4, 2025
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
This comment has been minimized.
This comment has been minimized.
clarfonthey
commented
Sep 4, 2025
Was hoping just the destruct bound was the issue, but apparently not. Will have to dig deeper into this. Until then, @rustbot author |
rustbot
commented
Sep 4, 2025
Reminder, once the PR becomes ready for a review, use |
a03d08a to
4b9d7b6Comparerustbot
commented
Sep 4, 2025
The Miri subtree was changed cc @rust-lang/miri |
clarfonthey
commented
Sep 4, 2025
Oh, the scary-looking errors were extremely simple to fix now that I actually investigated them. They were just copying the function signature in the error, which had obviously changed. Hopefully that's all. |
clarfonthey
commented
Sep 5, 2025
That was all, it turns out. @rustbot ready |
RalfJung
commented
Sep 5, 2025
Please add a test that actually invokes |
4b9d7b6 to
db531fbCompareThank you not only for reminding me to write that test, but also for helping me notice that I somehow missed Destructor tests are weird to write, but what I have should be reasonable, I think. |
db531fb to
07d3e92Comparerustbot
commented
Sep 5, 2025
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This code compiles with this PR. Is this intended? #![feature(const_trait_impl, const_destruct, const_drop_in_place)]use std::ptr::drop_in_place;structThing(i32);implconstDropforThing{fndrop(&mutself){}}staticmutX:Thing = {unsafe{drop_in_place(&rawmutX);}Thing(1)};This also compiles: #![feature(const_trait_impl, const_destruct, const_drop_in_place)]use std::ptr::drop_in_place;structThing(i32);implconstDropforThing{fndrop(&mutself){}}staticmutY:Thing = Thing(2);constX:i32 = {unsafe{drop_in_place(&rawmutY);}1};This also compiles: #![feature(const_trait_impl, const_destruct, const_drop_in_place)]use std::ptr::drop_in_place;structThing(i32);implconstDropforThing{fndrop(&mutself){}}staticY:Thing = Thing(2);constX:i32 = {unsafe{drop_in_place(&rawconstYas*mutThing);}1}; |
theemathas
commented
Sep 6, 2025
This has... interesting interaction with packed structs. The following code compiles: #![feature(const_trait_impl, const_destruct, const_drop_in_place)]use std::ptr::drop_in_place;structThing(i32);implconstDropforThing{fndrop(&mutself){self.0 = 2;}}#[repr(packed)]structPacked(Thing);staticY:Packed = Packed(Thing(1));constX:() = {unsafe{drop_in_place((&rawconstY).cast_mut());}};See also #143411 |
I mean, you've certainly pointed out a lot of compelling reasons why we shouldn't stabilise this feature right now, but also, we can't really test that all those cases aren't occurring without having the unstable constness in the first place. It's working, just… well, we now have new cases of UB to track and prevent. This is also why we explicitly track which unstable const features are used in stable items, to ensure that we don't accidentally stabilise something unsound. It would, for example, prevent us from properly stabilising const |
oli-obk
commented
Sep 10, 2025
I think that's a question for opsem to answer. I don't see why this is a new issue considering you can also do all the same at runtime right now (and it would error at compile-time if any mutation would actually happen in the drop impl, at least I think it would?). Or am I missing the point of your code examples entirely? 😅 |
RalfJung
commented
Sep 10, 2025
You can't really do this at runtime? Recursive static initializers are a magic special case. |
theemathas
commented
Sep 10, 2025
Turns out that Miri also behaves strangely around |
oli-obk
commented
Sep 10, 2025
Ah that's what I was missing. But even then, only the first case uses that to get references to uninit memory in the drop impl. The others I don't see a difference to runtime. |
rustbot
commented
Oct 14, 2025
|
oli-obk
commented
Oct 14, 2025
@bors r+ rollup |
bors
commented
Oct 14, 2025
…=oli-obk Unstably constify `ptr::drop_in_place` and related methods Tracking: rust-lang#109342 Supercedes: rust-lang#145725 Makes methods const: * `core::ptr::drop_in_place` * `core::mem::ManuallyDrop::drop` * `core::mem::MaybeUninit::assume_init_drop` * `<[core::mem::MaybeUninit<_>]>::assume_init_drop` * `<*mut _>::drop_in_place` * `core::ptr::NonNull::drop_in_place`
Rollup of 7 pull requests Successful merges: - #146187 (Unstably constify `ptr::drop_in_place` and related methods) - #146503 (std: improve handling of timed condition variable waits on macOS) - #147421 (Add check if span is from macro expansion) - #147630 (Bitset cleanups) - #147666 (Replace manual implementation with `carrying_mul_add`) - #147669 (fix missing link to `std::char` in `std` docs) - #147673 (pretty print u128 with display) r? `@ghost` `@rustbot` modify labels: rollup
…=oli-obk Unstably constify `ptr::drop_in_place` and related methods Tracking: rust-lang#109342 Supercedes: rust-lang#145725 Makes methods const: * `core::ptr::drop_in_place` * `core::mem::ManuallyDrop::drop` * `core::mem::MaybeUninit::assume_init_drop` * `<[core::mem::MaybeUninit<_>]>::assume_init_drop` * `<*mut _>::drop_in_place` * `core::ptr::NonNull::drop_in_place`
Rollup of 7 pull requests Successful merges: - #146187 (Unstably constify `ptr::drop_in_place` and related methods) - #146503 (std: improve handling of timed condition variable waits on macOS) - #147421 (Add check if span is from macro expansion) - #147630 (Bitset cleanups) - #147666 (Replace manual implementation with `carrying_mul_add`) - #147669 (fix missing link to `std::char` in `std` docs) - #147673 (pretty print u128 with display) r? `@ghost` `@rustbot` modify labels: rollup
…=oli-obk Unstably constify `ptr::drop_in_place` and related methods Tracking: rust-lang#109342 Supercedes: rust-lang#145725 Makes methods const: * `core::ptr::drop_in_place` * `core::mem::ManuallyDrop::drop` * `core::mem::MaybeUninit::assume_init_drop` * `<[core::mem::MaybeUninit<_>]>::assume_init_drop` * `<*mut _>::drop_in_place` * `core::ptr::NonNull::drop_in_place`
Rollup of 12 pull requests Successful merges: - #146187 (Unstably constify `ptr::drop_in_place` and related methods) - #146503 (std: improve handling of timed condition variable waits on macOS) - #147526 (Move computation of allocator shim contents to cg_ssa) - #147630 (Bitset cleanups) - #147638 (bpf: return results larger than one register indirectly) - #147666 (Replace manual implementation with `carrying_mul_add`) - #147669 (fix missing link to `std::char` in `std` docs) - #147673 (pretty print u128 with display) - #147677 (Fewer exceptions in `span()` on parsed attributes) - #147680 (Fix ICE caused by associated_item_def_ids on wrong type in resolve diag) - #147682 (convert `rustc_main` to the new attribute parsing infrastructure) - #147683 (only check duplicates on old/unparsed attributes) r? `@ghost` `@rustbot` modify labels: rollup
Uh oh!
There was an error while loading. Please reload this page.
Rollup merge of #146187 - clarfonthey:const-drop-in-place, r=oli-obk Unstably constify `ptr::drop_in_place` and related methods Tracking: #109342 Supercedes: #145725 Makes methods const: * `core::ptr::drop_in_place` * `core::mem::ManuallyDrop::drop` * `core::mem::MaybeUninit::assume_init_drop` * `<[core::mem::MaybeUninit<_>]>::assume_init_drop` * `<*mut _>::drop_in_place` * `core::ptr::NonNull::drop_in_place`
Rollup of 12 pull requests Successful merges: - rust-lang/rust#146187 (Unstably constify `ptr::drop_in_place` and related methods) - rust-lang/rust#146503 (std: improve handling of timed condition variable waits on macOS) - rust-lang/rust#147526 (Move computation of allocator shim contents to cg_ssa) - rust-lang/rust#147630 (Bitset cleanups) - rust-lang/rust#147638 (bpf: return results larger than one register indirectly) - rust-lang/rust#147666 (Replace manual implementation with `carrying_mul_add`) - rust-lang/rust#147669 (fix missing link to `std::char` in `std` docs) - rust-lang/rust#147673 (pretty print u128 with display) - rust-lang/rust#147677 (Fewer exceptions in `span()` on parsed attributes) - rust-lang/rust#147680 (Fix ICE caused by associated_item_def_ids on wrong type in resolve diag) - rust-lang/rust#147682 (convert `rustc_main` to the new attribute parsing infrastructure) - rust-lang/rust#147683 (only check duplicates on old/unparsed attributes) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 12 pull requests Successful merges: - rust-lang/rust#146187 (Unstably constify `ptr::drop_in_place` and related methods) - rust-lang/rust#146503 (std: improve handling of timed condition variable waits on macOS) - rust-lang/rust#147526 (Move computation of allocator shim contents to cg_ssa) - rust-lang/rust#147630 (Bitset cleanups) - rust-lang/rust#147638 (bpf: return results larger than one register indirectly) - rust-lang/rust#147666 (Replace manual implementation with `carrying_mul_add`) - rust-lang/rust#147669 (fix missing link to `std::char` in `std` docs) - rust-lang/rust#147673 (pretty print u128 with display) - rust-lang/rust#147677 (Fewer exceptions in `span()` on parsed attributes) - rust-lang/rust#147680 (Fix ICE caused by associated_item_def_ids on wrong type in resolve diag) - rust-lang/rust#147682 (convert `rustc_main` to the new attribute parsing infrastructure) - rust-lang/rust#147683 (only check duplicates on old/unparsed attributes) r? `@ghost` `@rustbot` modify labels: rollup
…=oli-obk Unstably constify `ptr::drop_in_place` and related methods Tracking: rust-lang#109342 Supercedes: rust-lang#145725 Makes methods const: * `core::ptr::drop_in_place` * `core::mem::ManuallyDrop::drop` * `core::mem::MaybeUninit::assume_init_drop` * `<[core::mem::MaybeUninit<_>]>::assume_init_drop` * `<*mut _>::drop_in_place` * `core::ptr::NonNull::drop_in_place`
Rollup of 12 pull requests Successful merges: - rust-lang/rust#146187 (Unstably constify `ptr::drop_in_place` and related methods) - rust-lang/rust#146503 (std: improve handling of timed condition variable waits on macOS) - rust-lang/rust#147526 (Move computation of allocator shim contents to cg_ssa) - rust-lang/rust#147630 (Bitset cleanups) - rust-lang/rust#147638 (bpf: return results larger than one register indirectly) - rust-lang/rust#147666 (Replace manual implementation with `carrying_mul_add`) - rust-lang/rust#147669 (fix missing link to `std::char` in `std` docs) - rust-lang/rust#147673 (pretty print u128 with display) - rust-lang/rust#147677 (Fewer exceptions in `span()` on parsed attributes) - rust-lang/rust#147680 (Fix ICE caused by associated_item_def_ids on wrong type in resolve diag) - rust-lang/rust#147682 (convert `rustc_main` to the new attribute parsing infrastructure) - rust-lang/rust#147683 (only check duplicates on old/unparsed attributes) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 12 pull requests Successful merges: - rust-lang/rust#146187 (Unstably constify `ptr::drop_in_place` and related methods) - rust-lang/rust#146503 (std: improve handling of timed condition variable waits on macOS) - rust-lang/rust#147526 (Move computation of allocator shim contents to cg_ssa) - rust-lang/rust#147630 (Bitset cleanups) - rust-lang/rust#147638 (bpf: return results larger than one register indirectly) - rust-lang/rust#147666 (Replace manual implementation with `carrying_mul_add`) - rust-lang/rust#147669 (fix missing link to `std::char` in `std` docs) - rust-lang/rust#147673 (pretty print u128 with display) - rust-lang/rust#147677 (Fewer exceptions in `span()` on parsed attributes) - rust-lang/rust#147680 (Fix ICE caused by associated_item_def_ids on wrong type in resolve diag) - rust-lang/rust#147682 (convert `rustc_main` to the new attribute parsing infrastructure) - rust-lang/rust#147683 (only check duplicates on old/unparsed attributes) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 12 pull requests Successful merges: - rust-lang/rust#146187 (Unstably constify `ptr::drop_in_place` and related methods) - rust-lang/rust#146503 (std: improve handling of timed condition variable waits on macOS) - rust-lang/rust#147526 (Move computation of allocator shim contents to cg_ssa) - rust-lang/rust#147630 (Bitset cleanups) - rust-lang/rust#147638 (bpf: return results larger than one register indirectly) - rust-lang/rust#147666 (Replace manual implementation with `carrying_mul_add`) - rust-lang/rust#147669 (fix missing link to `std::char` in `std` docs) - rust-lang/rust#147673 (pretty print u128 with display) - rust-lang/rust#147677 (Fewer exceptions in `span()` on parsed attributes) - rust-lang/rust#147680 (Fix ICE caused by associated_item_def_ids on wrong type in resolve diag) - rust-lang/rust#147682 (convert `rustc_main` to the new attribute parsing infrastructure) - rust-lang/rust#147683 (only check duplicates on old/unparsed attributes) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 12 pull requests Successful merges: - rust-lang/rust#146187 (Unstably constify `ptr::drop_in_place` and related methods) - rust-lang/rust#146503 (std: improve handling of timed condition variable waits on macOS) - rust-lang/rust#147526 (Move computation of allocator shim contents to cg_ssa) - rust-lang/rust#147630 (Bitset cleanups) - rust-lang/rust#147638 (bpf: return results larger than one register indirectly) - rust-lang/rust#147666 (Replace manual implementation with `carrying_mul_add`) - rust-lang/rust#147669 (fix missing link to `std::char` in `std` docs) - rust-lang/rust#147673 (pretty print u128 with display) - rust-lang/rust#147677 (Fewer exceptions in `span()` on parsed attributes) - rust-lang/rust#147680 (Fix ICE caused by associated_item_def_ids on wrong type in resolve diag) - rust-lang/rust#147682 (convert `rustc_main` to the new attribute parsing infrastructure) - rust-lang/rust#147683 (only check duplicates on old/unparsed attributes) r? `@ghost` `@rustbot` modify labels: rollup
Tracking: #109342
Supercedes: #145725
Makes methods const:
core::ptr::drop_in_placecore::mem::ManuallyDrop::dropcore::mem::MaybeUninit::assume_init_drop<[core::mem::MaybeUninit<_>]>::assume_init_drop<*mut _>::drop_in_placecore::ptr::NonNull::drop_in_place