From a99a3518020e1c7ea6db6f9d2e7e567637a3d7e7 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 4 Sep 2025 11:39:28 -0300 Subject: [PATCH] sync: use `UnsafeCell::get_mut` in `Mutex::get_mut` and `RwLock::get_mut` (#7569) --- tokio/src/sync/mutex.rs | 5 +---- tokio/src/sync/rwlock.rs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tokio/src/sync/mutex.rs b/tokio/src/sync/mutex.rs index 30f0bdece..7feedc8b9 100644 --- a/tokio/src/sync/mutex.rs +++ b/tokio/src/sync/mutex.rs @@ -716,10 +716,7 @@ impl Mutex { /// } /// ``` pub fn get_mut(&mut self) -> &mut T { - unsafe { - // Safety: This is https://github.com/rust-lang/rust/pull/76936 - &mut *self.c.get() - } + self.c.get_mut() } /// Attempts to acquire the lock, and returns [`TryLockError`] if the lock diff --git a/tokio/src/sync/rwlock.rs b/tokio/src/sync/rwlock.rs index d94b65143..087c5b3da 100644 --- a/tokio/src/sync/rwlock.rs +++ b/tokio/src/sync/rwlock.rs @@ -1073,10 +1073,7 @@ impl RwLock { /// } /// ``` pub fn get_mut(&mut self) -> &mut T { - unsafe { - // Safety: This is https://github.com/rust-lang/rust/pull/76936 - &mut *self.c.get() - } + self.c.get_mut() } /// Consumes the lock, returning the underlying data.