Skip to content

Commit da43ee8

Browse files
committed
Auto merge of rust-lang#84650 - a1phyr:simplify_mutex_into_inner, r=m-ou-se
Simplify `Mutex::into_inner` Thanks to rust-lang#77147, `Mutex` do not implement `Drop` directly, so the old unsafe implementation of `into_inner` is not relevant anymore.
2 parents c488f15 + 0b7b121 commit da43ee8

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

library/std/src/sync/mutex.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ mod tests;
33

44
use crate::cell::UnsafeCell;
55
use crate::fmt;
6-
use crate::mem;
76
use crate::ops::{Deref, DerefMut};
8-
use crate::ptr;
97
use crate::sync::{poison, LockResult, TryLockError, TryLockResult};
108
use crate::sys_common::mutex as sys;
119

@@ -376,23 +374,8 @@ impl<T: ?Sized> Mutex<T> {
376374
where
377375
T: Sized,
378376
{
379-
// We know statically that there are no outstanding references to
380-
// `self` so there's no need to lock the inner mutex.
381-
//
382-
// To get the inner value, we'd like to call `data.into_inner()`,
383-
// but because `Mutex` impl-s `Drop`, we can't move out of it, so
384-
// we'll have to destructure it manually instead.
385-
unsafe {
386-
// Like `let Mutex { inner, poison, data } = self`.
387-
let (inner, poison, data) = {
388-
let Mutex { ref inner, ref poison, ref data } = self;
389-
(ptr::read(inner), ptr::read(poison), ptr::read(data))
390-
};
391-
mem::forget(self);
392-
drop(inner);
393-
394-
poison::map_result(poison.borrow(), |_| data.into_inner())
395-
}
377+
let data = self.data.into_inner();
378+
poison::map_result(self.poison.borrow(), |_| data)
396379
}
397380

398381
/// Returns a mutable reference to the underlying data.

0 commit comments

Comments
 (0)