@@ -7,7 +7,7 @@ use super::thread::Thread;
77use super :: { Result , spawnhook} ;
88use crate :: cell:: UnsafeCell ;
99use crate :: marker:: PhantomData ;
10- use crate :: mem:: { ManuallyDrop , MaybeUninit } ;
10+ use crate :: mem:: MaybeDangling ;
1111use crate :: sync:: Arc ;
1212use crate :: sync:: atomic:: { Atomic , AtomicUsize , Ordering } ;
1313use crate :: sys:: thread as imp;
5858 Arc :: new ( Packet { scope : scope_data, result : UnsafeCell :: new ( None ) , _marker : PhantomData } ) ;
5959 let their_packet = my_packet. clone ( ) ;
6060
61- // Pass `f` in `MaybeUninit ` because actually that closure might *run longer than the lifetime of `F`*.
61+ // Pass `f` in `MaybeDangling ` because actually that closure might *run longer than the lifetime of `F`*.
6262 // See <https://github.com/rust-lang/rust/issues/101983> for more details.
63- // To prevent leaks we use a wrapper that drops its contents.
64- #[ repr( transparent) ]
65- struct MaybeDangling < T > ( MaybeUninit < T > ) ;
66- impl < T > MaybeDangling < T > {
67- fn new ( x : T ) -> Self {
68- MaybeDangling ( MaybeUninit :: new ( x) )
69- }
70- fn into_inner ( self ) -> T {
71- // Make sure we don't drop.
72- let this = ManuallyDrop :: new ( self ) ;
73- // SAFETY: we are always initialized.
74- unsafe { this. 0 . assume_init_read ( ) }
75- }
76- }
77- impl < T > Drop for MaybeDangling < T > {
78- fn drop ( & mut self ) {
79- // SAFETY: we are always initialized.
80- unsafe { self . 0 . assume_init_drop ( ) } ;
81- }
82- }
83-
8463 let f = MaybeDangling :: new ( f) ;
8564
8665 // The entrypoint of the Rust thread, after platform-specific thread
0 commit comments