This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +7
-16
lines changed Expand file tree Collapse file tree 5 files changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -496,10 +496,7 @@ impl<T: ?Sized> Cell<T> {
496496 #[ inline]
497497 #[ stable( feature = "cell_get_mut" , since = "1.11.0" ) ]
498498 pub fn get_mut ( & mut self ) -> & mut T {
499- // SAFETY: This can cause data races if called from a separate thread,
500- // but `Cell` is `!Sync` so this won't happen, and `&mut` guarantees
501- // unique access.
502- unsafe { & mut * self . value . get ( ) }
499+ self . value . get_mut ( )
503500 }
504501
505502 /// Returns a `&Cell<T>` from a `&mut T`
@@ -945,8 +942,7 @@ impl<T: ?Sized> RefCell<T> {
945942 #[ inline]
946943 #[ stable( feature = "cell_get_mut" , since = "1.11.0" ) ]
947944 pub fn get_mut ( & mut self ) -> & mut T {
948- // SAFETY: `&mut` guarantees unique access.
949- unsafe { & mut * self . value . get ( ) }
945+ self . value . get_mut ( )
950946 }
951947
952948 /// Undo the effect of leaked guards on the borrow state of the `RefCell`.
Original file line number Diff line number Diff line change @@ -838,8 +838,7 @@ impl<T> AtomicPtr<T> {
838838 #[ inline]
839839 #[ stable( feature = "atomic_access" , since = "1.15.0" ) ]
840840 pub fn get_mut ( & mut self ) -> & mut * mut T {
841- // SAFETY: the mutable reference guarantees unique ownership.
842- unsafe { & mut * self . p . get ( ) }
841+ self . p . get_mut ( )
843842 }
844843
845844 /// Get atomic access to a pointer.
@@ -1275,8 +1274,7 @@ assert_eq!(some_var.load(Ordering::SeqCst), 5);
12751274 #[ inline]
12761275 #[ $stable_access]
12771276 pub fn get_mut( & mut self ) -> & mut $int_type {
1278- // SAFETY: the mutable reference guarantees unique ownership.
1279- unsafe { & mut * self . v. get( ) }
1277+ self . v. get_mut( )
12801278 }
12811279 }
12821280
Original file line number Diff line number Diff line change 315315#![ feature( try_reserve) ]
316316#![ feature( unboxed_closures) ]
317317#![ feature( unsafe_block_in_unsafe_fn) ]
318+ #![ feature( unsafe_cell_get_mut) ]
318319#![ feature( unsafe_cell_raw_get) ]
319320#![ feature( untagged_unions) ]
320321#![ feature( unwind_attributes) ]
Original file line number Diff line number Diff line change @@ -406,9 +406,7 @@ impl<T: ?Sized> Mutex<T> {
406406 /// ```
407407 #[ stable( feature = "mutex_get_mut" , since = "1.6.0" ) ]
408408 pub fn get_mut ( & mut self ) -> LockResult < & mut T > {
409- // We know statically that there are no other references to `self`, so
410- // there's no need to lock the inner mutex.
411- let data = unsafe { & mut * self . data . get ( ) } ;
409+ let data = self . data . get_mut ( ) ;
412410 poison:: map_result ( self . poison . borrow ( ) , |_| data)
413411 }
414412}
Original file line number Diff line number Diff line change @@ -404,9 +404,7 @@ impl<T: ?Sized> RwLock<T> {
404404 /// ```
405405 #[ stable( feature = "rwlock_get_mut" , since = "1.6.0" ) ]
406406 pub fn get_mut ( & mut self ) -> LockResult < & mut T > {
407- // We know statically that there are no other references to `self`, so
408- // there's no need to lock the inner lock.
409- let data = unsafe { & mut * self . data . get ( ) } ;
407+ let data = self . data . get_mut ( ) ;
410408 poison:: map_result ( self . poison . borrow ( ) , |_| data)
411409 }
412410}
You can’t perform that action at this time.
0 commit comments