sync: use UnsafeCell::get_mut in Mutex::get_mut and RwLock::get_mut (#7569)

This commit is contained in:
Roman
2025-09-04 22:39:28 +08:00
committed by GitHub
parent d1e06f831e
commit a99a351802
2 changed files with 2 additions and 8 deletions
+1 -4
View File
@@ -716,10 +716,7 @@ impl<T: ?Sized> Mutex<T> {
/// }
/// ```
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
+1 -4
View File
@@ -1073,10 +1073,7 @@ impl<T: ?Sized> RwLock<T> {
/// }
/// ```
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.