Skip to content

Commit

Permalink
Fix UB in MutexGuardArc::source (#50)
Browse files Browse the repository at this point in the history
The alternative would be to change the `Sync` impl for  `MutexGuardArc`
to require `T: Send + Sync`.
  • Loading branch information
Jules-Bertholet authored Jul 7, 2023
1 parent d22ee4e commit 0b7252c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,12 @@ impl<T: ?Sized> MutexGuardArc<T> {
/// dbg!(MutexGuardArc::source(&guard));
/// # })
/// ```
pub fn source(guard: &MutexGuardArc<T>) -> &Arc<Mutex<T>> {
pub fn source(guard: &Self) -> &Arc<Mutex<T>>
where
// Required because `MutexGuardArc` implements `Sync` regardless of whether `T` is `Send`,
// but this method allows dropping `T` from a different thead than it was created in.
T: Send,
{
&guard.0
}
}
Expand Down

0 comments on commit 0b7252c

Please sign in to comment.