Skip to content

Conversation

@WaffleLapkin
Copy link
Member

cc #118166

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 3, 2025
@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin WaffleLapkin force-pushed the dangle-maybe branch 2 times, most recently from c428102 to 5bd5888 Compare December 3, 2025 20:47
@rust-log-analyzer

This comment has been minimized.

Comment on lines 187 to 192
#[stable(feature = "manually_drop", since = "1.20.0")]
impl<T: ?Sized + PartialEq> PartialEq for ManuallyDrop<T> {
fn eq(&self, other: &Self) -> bool {
self.value.as_ref().eq(other.value.as_ref())
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to implement StructuralPartialEq, since ManuallyDrop in a const can currently be used in patterns on stable.

@joboet
Copy link
Member

joboet commented Dec 5, 2025

I don't know how much this is still an experiment, but if you're looking for more coverage, you might want to replace the MaybeUninit-based manual MaybeDangling implementation in std:

// Pass `f` in `MaybeUninit` because actually that closure might *run longer than the lifetime of `F`*.
// See <https://github.com/rust-lang/rust/issues/101983> for more details.
// To prevent leaks we use a wrapper that drops its contents.
#[repr(transparent)]
struct MaybeDangling<T>(MaybeUninit<T>);
impl<T> MaybeDangling<T> {
fn new(x: T) -> Self {
MaybeDangling(MaybeUninit::new(x))
}
fn into_inner(self) -> T {
// Make sure we don't drop.
let this = ManuallyDrop::new(self);
// SAFETY: we are always initialized.
unsafe { this.0.assume_init_read() }
}
}
impl<T> Drop for MaybeDangling<T> {
fn drop(&mut self) {
// SAFETY: we are always initialized.
unsafe { self.0.assume_init_drop() };
}
}

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin WaffleLapkin force-pushed the dangle-maybe branch 2 times, most recently from ac4154d to 259187e Compare December 13, 2025 13:16
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 15, 2025
…m, r=jdonszelmann Simplify how inline asm handles `MaybeUninit` This is just better, but this is also allows it to handle changes from rust-lang#149614 (i.e. `ManuallyDrop` containing `MaybeDangle`).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 15, 2025
…m, r=jdonszelmann Simplify how inline asm handles `MaybeUninit` This is just better, but this is also allows it to handle changes from rust-lang#149614 (i.e. `ManuallyDrop` containing `MaybeDangle`).
Zalathar added a commit to Zalathar/rust that referenced this pull request Dec 16, 2025
…m, r=jdonszelmann Simplify how inline asm handles `MaybeUninit` This is just better, but this is also allows it to handle changes from rust-lang#149614 (i.e. `ManuallyDrop` containing `MaybeDangle`).
Zalathar added a commit to Zalathar/rust that referenced this pull request Dec 16, 2025
…m, r=jdonszelmann Simplify how inline asm handles `MaybeUninit` This is just better, but this is also allows it to handle changes from rust-lang#149614 (i.e. `ManuallyDrop` containing `MaybeDangle`).
rust-timer added a commit that referenced this pull request Dec 16, 2025
Rollup merge of #149950 - WaffleLapkin:inlines-ur-mu-into-asm, r=jdonszelmann Simplify how inline asm handles `MaybeUninit` This is just better, but this is also allows it to handle changes from #149614 (i.e. `ManuallyDrop` containing `MaybeDangle`).
@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test library/core/src/mem/drop_guard.rs - mem::drop_guard::DropGuard<T,F>::new (line 50) ... ok test library/core/src/mem/manually_drop.rs - mem::manually_drop::ManuallyDrop (line 54) ... ok test library/core/src/mem/manually_drop.rs - mem::manually_drop::ManuallyDrop (line 35) ... ok test library/core/src/mem/manually_drop.rs - mem::manually_drop::ManuallyDrop (line 87) ... ok test library/core/src/mem/maybe_dangling.rs - mem::maybe_dangling::MaybeDangling (line 14) ... ok test library/core/src/mem/manually_drop.rs - mem::manually_drop::ManuallyDrop<T>::into_inner (line 194) ... ok test library/core/src/mem/manually_drop.rs - mem::manually_drop::ManuallyDrop<T>::new (line 170) ... ok test library/core/src/mem/maybe_dangling.rs - mem::maybe_dangling::MaybeDangling (line 35) ... ok test library/core/src/mem/maybe_uninit.rs - mem::maybe_uninit::MaybeUninit (line 18) ... ok test library/core/src/mem/maybe_uninit.rs - mem::maybe_uninit::MaybeUninit (line 118) ... ok test library/core/src/mem/maybe_uninit.rs - mem::maybe_uninit::MaybeUninit (line 142) ... ok test library/core/src/mem/maybe_uninit.rs - mem::maybe_uninit::MaybeUninit (line 241) ... ok test library/core/src/mem/maybe_uninit.rs - mem::maybe_uninit::MaybeUninit (line 206) ... ok --- ---- [codegen] tests/codegen-llvm/manually_drop_refs.rs stdout ---- ------FileCheck stdout------------------------------ ------FileCheck stderr------------------------------ /checkout/tests/codegen-llvm/manually_drop_refs.rs:6:11: error: CHECK: expected string not found in input // CHECK: define noundef nonnull ptr @f(ptr noundef nonnull readnone returned {{(captures\(ret: address, provenance\) )?}}%x) unnamed_addr ^ /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll:1:1: note: scanning from here ; ModuleID = 'manually_drop_refs.f6bd3c5d90b64e2d-cgu.0' ^ /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll:7:11: note: possible intended match here define dso_local noundef nonnull ptr @f(ptr noundef nonnull readnone returned captures(ret: address, provenance) %x) unnamed_addr #0 { ^ Input file: /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll Check file: /checkout/tests/codegen-llvm/manually_drop_refs.rs -dump-input=help explains the following input dump. Input was: <<<<<< 1: ; ModuleID = 'manually_drop_refs.f6bd3c5d90b64e2d-cgu.0' check:6'0 X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found 2: source_filename = "manually_drop_refs.f6bd3c5d90b64e2d-cgu.0" check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3: target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20" check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4: target triple = "wasm32-unknown-wasip1" check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5: check:6'0 ~ 6: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7: define dso_local noundef nonnull ptr @f(ptr noundef nonnull readnone returned captures(ret: address, provenance) %x) unnamed_addr #0 { check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ check:6'1 ? possible intended match 8: start: check:6'0 ~~~~~~~ 9: ret ptr %x check:6'0 ~~~~~~~~~~~~ 10: } check:6'0 ~~ 11: check:6'0 ~ 12: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13: define dso_local noundef nonnull ptr @g(ptr noundef nonnull readnone returned captures(ret: address, provenance) %x) unnamed_addr #0 { check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 14: start: check:6'0 ~~~~~~~ 15: ret ptr %x check:6'0 ~~~~~~~~~~~~ 16: } check:6'0 ~~ 17: check:6'0 ~ 18: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19: define dso_local noundef nonnull ptr @h(ptr noundef nonnull readnone returned captures(ret: address, provenance) %x) unnamed_addr #0 { check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 20: start: check:6'0 ~~~~~~~ 21: ret ptr %x check:6'0 ~~~~~~~~~~~~ 22: } check:6'0 ~~ 23: check:6'0 ~ 24: attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "target-cpu"="generic" } check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25: check:6'0 ~ 26: !llvm.ident = !{!0} check:6'0 ~~~~~~~~~~~~~~~~~~~~ 27: check:6'0 ~ 28: !0 = !{!"rustc version 1.94.0-nightly (a7a0c6423 2025-12-17)"} check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>>>>> ------------------------------------------ error: verification with 'FileCheck' failed status: exit status: 1 command: "/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll" "/checkout/tests/codegen-llvm/manually_drop_refs.rs" "--check-prefix=CHECK" "--allow-unused-prefixes" "--dump-input-context" "100" stdout: none --- stderr ------------------------------- /checkout/tests/codegen-llvm/manually_drop_refs.rs:6:11: error: CHECK: expected string not found in input // CHECK: define noundef nonnull ptr @f(ptr noundef nonnull readnone returned {{(captures\(ret: address, provenance\) )?}}%x) unnamed_addr ^ /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll:1:1: note: scanning from here ; ModuleID = 'manually_drop_refs.f6bd3c5d90b64e2d-cgu.0' ^ /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll:7:11: note: possible intended match here define dso_local noundef nonnull ptr @f(ptr noundef nonnull readnone returned captures(ret: address, provenance) %x) unnamed_addr #0 { ^ Input file: /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll Check file: /checkout/tests/codegen-llvm/manually_drop_refs.rs -dump-input=help explains the following input dump. Input was: <<<<<< 1: ; ModuleID = 'manually_drop_refs.f6bd3c5d90b64e2d-cgu.0' check:6'0 X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found 2: source_filename = "manually_drop_refs.f6bd3c5d90b64e2d-cgu.0" check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3: target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20" check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4: target triple = "wasm32-unknown-wasip1" check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5: check:6'0 ~ 6: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7: define dso_local noundef nonnull ptr @f(ptr noundef nonnull readnone returned captures(ret: address, provenance) %x) unnamed_addr #0 { check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ check:6'1 ? possible intended match 8: start: check:6'0 ~~~~~~~ 9: ret ptr %x check:6'0 ~~~~~~~~~~~~ 10: } check:6'0 ~~ 11: check:6'0 ~ 12: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13: define dso_local noundef nonnull ptr @g(ptr noundef nonnull readnone returned captures(ret: address, provenance) %x) unnamed_addr #0 { check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 14: start: check:6'0 ~~~~~~~ 15: ret ptr %x check:6'0 ~~~~~~~~~~~~ 16: } check:6'0 ~~ 17: check:6'0 ~ 18: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19: define dso_local noundef nonnull ptr @h(ptr noundef nonnull readnone returned captures(ret: address, provenance) %x) unnamed_addr #0 { check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 20: start: check:6'0 ~~~~~~~ 21: ret ptr %x check:6'0 ~~~~~~~~~~~~ 22: } check:6'0 ~~ 23: check:6'0 ~ 24: attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "target-cpu"="generic" } check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25: check:6'0 ~ 26: !llvm.ident = !{!0} check:6'0 ~~~~~~~~~~~~~~~~~~~~ 27: check:6'0 ~ 28: !0 = !{!"rustc version 1.94.0-nightly (a7a0c6423 2025-12-17)"} check:6'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>>>>> ------------------------------------------ ---- [codegen] tests/codegen-llvm/manually_drop_refs.rs stdout end ---- 
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Dec 18, 2025
…szelmann Simplify how inline asm handles `MaybeUninit` This is just better, but this is also allows it to handle changes from rust-lang/rust#149614 (i.e. `ManuallyDrop` containing `MaybeDangle`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

5 participants