File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -110,8 +110,10 @@ impl<T> Mutex<T> {
110
110
/// Unwraps the contained value, consuming the mutex.
111
111
#[ inline]
112
112
pub fn into_inner ( self ) -> T {
113
- // Safety: inner is always initialized
114
- unsafe { self . inner . assume_init ( ) }
113
+ // Safety:
114
+ // - inner is always initialized
115
+ // - self will be dropped at the end of the function, _not_ dropping the contents of MaybeUninit
116
+ unsafe { self . inner . as_ptr ( ) . read ( ) }
115
117
}
116
118
117
119
/// Borrows the data for the duration of the critical section.
@@ -199,6 +201,15 @@ impl<T: Default> Mutex<RefCell<T>> {
199
201
}
200
202
}
201
203
204
+ impl < T > Drop for Mutex < T > {
205
+ fn drop ( & mut self ) {
206
+ // Safety:
207
+ // - inner is always initialized
208
+ // - self will be dropped at the end of the function, _not_ dropping the contents of MaybeUninit
209
+ core:: mem:: drop ( unsafe { self . inner . as_ptr ( ) . read ( ) } ) ;
210
+ }
211
+ }
212
+
202
213
// NOTE A `Mutex` can be used as a channel so the protected data must be `Send`
203
214
// to prevent sending non-Sendable stuff (e.g. access tokens) across different
204
215
// threads.
You can’t perform that action at this time.
0 commit comments