@@ -7,7 +7,7 @@ use crate::marker::PhantomData;
77use crate :: mem:: { forget, ManuallyDrop } ;
88use crate :: ops:: { Deref , DerefMut } ;
99use crate :: ptr:: NonNull ;
10- use crate :: sync:: { poison, LockResult , TryLockError , TryLockResult } ;
10+ use crate :: sync:: { poison, LockResult , PoisonError , TryLockError , TryLockResult } ;
1111use crate :: sys:: sync as sys;
1212
1313/// A reader-writer lock
@@ -966,23 +966,20 @@ impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
966966 ///
967967 /// Atomically changes the state of the [`RwLock`] from exclusive mode into shared mode.
968968 ///
969- /// MORE DOCS COMING SOON.
969+ /// FIXME MORE DOCS COMING SOON.
970970 #[ unstable( feature = "rwlock_downgrade" , issue = "128203" ) ]
971971 pub fn downgrade ( s : Self ) -> RwLockReadGuard < ' a , T > {
972972 let lock = s. lock ;
973973
974+ // We don't want to call the destructor since that calls `write_unlock`.
975+ forget ( s) ;
976+
974977 // SAFETY: We take ownership of a write guard, so we must already have the `RwLock` in write
975978 // mode, satisfying the `downgrade` contract.
976979 unsafe { lock. inner . downgrade ( ) } ;
977980
978- // We don't want to call the destructor since that calls `write_unlock`.
979- forget ( s) ;
980-
981981 // 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) }
986983 }
987984}
988985
0 commit comments