diff options
| author | Benoît du Garreau <bdgdlm@outlook.com> | 2021-04-28 13:56:23 +0200 |
|---|---|---|
| committer | Benoît du Garreau <bdgdlm@outlook.com> | 2021-04-28 13:56:23 +0200 |
| commit | 0b7b121c29a3849460e72f04efaf667ca3414065 (patch) | |
| tree | dd9a9c744434e97458e294d37722f04ecbc399d2 /library/std/src/sync | |
| parent | 855c2d130fb70da1643cf8f696c7aad7537aef34 (diff) | |
| download | rust-0b7b121c29a3849460e72f04efaf667ca3414065.tar.gz rust-0b7b121c29a3849460e72f04efaf667ca3414065.zip | |
Simplify `Mutex::into_inner`
Diffstat (limited to 'library/std/src/sync')
| -rw-r--r-- | library/std/src/sync/mutex.rs | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/library/std/src/sync/mutex.rs b/library/std/src/sync/mutex.rs index 2615bea6592..773ab18b2ce 100644 --- a/library/std/src/sync/mutex.rs +++ b/library/std/src/sync/mutex.rs @@ -3,9 +3,7 @@ mod tests; use crate::cell::UnsafeCell; use crate::fmt; -use crate::mem; use crate::ops::{Deref, DerefMut}; -use crate::ptr; use crate::sync::{poison, LockResult, TryLockError, TryLockResult}; use crate::sys_common::mutex as sys; @@ -376,23 +374,8 @@ impl<T: ?Sized> Mutex<T> { where T: Sized, { - // We know statically that there are no outstanding references to - // `self` so there's no need to lock the inner mutex. - // - // To get the inner value, we'd like to call `data.into_inner()`, - // but because `Mutex` impl-s `Drop`, we can't move out of it, so - // we'll have to destructure it manually instead. - unsafe { - // Like `let Mutex { inner, poison, data } = self`. - let (inner, poison, data) = { - let Mutex { ref inner, ref poison, ref data } = self; - (ptr::read(inner), ptr::read(poison), ptr::read(data)) - }; - mem::forget(self); - drop(inner); - - poison::map_result(poison.borrow(), |_| data.into_inner()) - } + let data = self.data.into_inner(); + poison::map_result(self.poison.borrow(), |_| data) } /// Returns a mutable reference to the underlying data. |
