Skip to content

Commit 0b7252c

Browse files
Fix UB in MutexGuardArc::source (#50)
The alternative would be to change the `Sync` impl for `MutexGuardArc` to require `T: Send + Sync`.
1 parent d22ee4e commit 0b7252c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/mutex.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,12 @@ impl<T: ?Sized> MutexGuardArc<T> {
638638
/// dbg!(MutexGuardArc::source(&guard));
639639
/// # })
640640
/// ```
641-
pub fn source(guard: &MutexGuardArc<T>) -> &Arc<Mutex<T>> {
641+
pub fn source(guard: &Self) -> &Arc<Mutex<T>>
642+
where
643+
// Required because `MutexGuardArc` implements `Sync` regardless of whether `T` is `Send`,
644+
// but this method allows dropping `T` from a different thead than it was created in.
645+
T: Send,
646+
{
642647
&guard.0
643648
}
644649
}

0 commit comments

Comments
 (0)