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 and others added 6 commits December 13, 2025 14:15
Now that `MaybeUninit` contains `ManuallyDrop` which contains
`MaybeDangling` (tbc this is the addition), we need to unwrap one more
layer
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [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/aarch64-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/aarch64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll:7:1: note: possible intended match here
define noundef nonnull ptr @f(ptr noundef nonnull readnone returned %x) unnamed_addr #0 {
^

Input file: /checkout/obj/build/aarch64-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-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           4: target triple = "aarch64-unknown-linux-gnu" 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5:  
check:6'0     ~
           6: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           7: define noundef nonnull ptr @f(ptr noundef nonnull readnone returned %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) uwtable 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          13: define noundef nonnull ptr @g(ptr noundef nonnull readnone returned %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) uwtable 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          19: define noundef nonnull ptr @h(ptr noundef nonnull readnone returned %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) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          25:  
check:6'0     ~
          26: !llvm.module.flags = !{!0} 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
          27: !llvm.ident = !{!1} 
check:6'0     ~~~~~~~~~~~~~~~~~~~~
          28:  
check:6'0     ~
          29: !0 = !{i32 8, !"PIC Level", i32 2} 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          30: !1 = !{!"rustc version 1.94.0-nightly (e68ce10dd 2025-12-14)"} 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>

------------------------------------------

error: verification with 'FileCheck' failed
status: exit status: 1
command: "/usr/lib/llvm-20/bin/FileCheck" "--input-file" "/checkout/obj/build/aarch64-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/aarch64-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/aarch64-unknown-linux-gnu/test/codegen-llvm/manually_drop_refs/manually_drop_refs.ll:7:1: note: possible intended match here
define noundef nonnull ptr @f(ptr noundef nonnull readnone returned %x) unnamed_addr #0 {
^

Input file: /checkout/obj/build/aarch64-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-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           4: target triple = "aarch64-unknown-linux-gnu" 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5:  
check:6'0     ~
           6: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           7: define noundef nonnull ptr @f(ptr noundef nonnull readnone returned %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) uwtable 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          13: define noundef nonnull ptr @g(ptr noundef nonnull readnone returned %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) uwtable 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          19: define noundef nonnull ptr @h(ptr noundef nonnull readnone returned %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) uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="generic" "target-features"="+v8a,+outline-atomics" } 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          25:  
check:6'0     ~
          26: !llvm.module.flags = !{!0} 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
          27: !llvm.ident = !{!1} 
check:6'0     ~~~~~~~~~~~~~~~~~~~~
          28:  
check:6'0     ~
          29: !0 = !{i32 8, !"PIC Level", i32 2} 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          30: !1 = !{!"rustc version 1.94.0-nightly (e68ce10dd 2025-12-14)"} 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>
------------------------------------------

---- [codegen] tests/codegen-llvm/manually_drop_refs.rs stdout end ----

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants