@@ -7,7 +7,7 @@ use crate::marker::PhantomData;
7
7
use crate :: mem:: { forget, ManuallyDrop } ;
8
8
use crate :: ops:: { Deref , DerefMut } ;
9
9
use crate :: ptr:: NonNull ;
10
- use crate :: sync:: { poison, LockResult , TryLockError , TryLockResult } ;
10
+ use crate :: sync:: { poison, LockResult , PoisonError , TryLockError , TryLockResult } ;
11
11
use crate :: sys:: sync as sys;
12
12
13
13
/// A reader-writer lock
@@ -966,23 +966,20 @@ impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
966
966
///
967
967
/// Atomically changes the state of the [`RwLock`] from exclusive mode into shared mode.
968
968
///
969
- /// MORE DOCS COMING SOON.
969
+ /// FIXME MORE DOCS COMING SOON.
970
970
#[ unstable( feature = "rwlock_downgrade" , issue = "128203" ) ]
971
971
pub fn downgrade ( s : Self ) -> RwLockReadGuard < ' a , T > {
972
972
let lock = s. lock ;
973
973
974
+ // We don't want to call the destructor since that calls `write_unlock`.
975
+ forget ( s) ;
976
+
974
977
// SAFETY: We take ownership of a write guard, so we must already have the `RwLock` in write
975
978
// mode, satisfying the `downgrade` contract.
976
979
unsafe { lock. inner . downgrade ( ) } ;
977
980
978
- // We don't want to call the destructor since that calls `write_unlock`.
979
- forget ( s) ;
980
-
981
981
// SAFETY: We have just successfully called `downgrade`, so we fulfill the safety contract.
982
- unsafe {
983
- RwLockReadGuard :: new ( lock)
984
- . expect ( "We had the exclusive lock so we can't have panicked while holding it" )
985
- }
982
+ unsafe { RwLockReadGuard :: new ( lock) . unwrap_or_else ( PoisonError :: into_inner) }
986
983
}
987
984
}
988
985
0 commit comments