File tree 5 files changed +7
-16
lines changed
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> {
496
496
#[ inline]
497
497
#[ stable( feature = "cell_get_mut" , since = "1.11.0" ) ]
498
498
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 ( )
503
500
}
504
501
505
502
/// Returns a `&Cell<T>` from a `&mut T`
@@ -945,8 +942,7 @@ impl<T: ?Sized> RefCell<T> {
945
942
#[ inline]
946
943
#[ stable( feature = "cell_get_mut" , since = "1.11.0" ) ]
947
944
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 ( )
950
946
}
951
947
952
948
/// 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> {
838
838
#[ inline]
839
839
#[ stable( feature = "atomic_access" , since = "1.15.0" ) ]
840
840
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 ( )
843
842
}
844
843
845
844
/// Get atomic access to a pointer.
@@ -1275,8 +1274,7 @@ assert_eq!(some_var.load(Ordering::SeqCst), 5);
1275
1274
#[ inline]
1276
1275
#[ $stable_access]
1277
1276
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( )
1280
1278
}
1281
1279
}
1282
1280
Original file line number Diff line number Diff line change 315
315
#![ feature( try_reserve) ]
316
316
#![ feature( unboxed_closures) ]
317
317
#![ feature( unsafe_block_in_unsafe_fn) ]
318
+ #![ feature( unsafe_cell_get_mut) ]
318
319
#![ feature( unsafe_cell_raw_get) ]
319
320
#![ feature( untagged_unions) ]
320
321
#![ feature( unwind_attributes) ]
Original file line number Diff line number Diff line change @@ -406,9 +406,7 @@ impl<T: ?Sized> Mutex<T> {
406
406
/// ```
407
407
#[ stable( feature = "mutex_get_mut" , since = "1.6.0" ) ]
408
408
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 ( ) ;
412
410
poison:: map_result ( self . poison . borrow ( ) , |_| data)
413
411
}
414
412
}
Original file line number Diff line number Diff line change @@ -404,9 +404,7 @@ impl<T: ?Sized> RwLock<T> {
404
404
/// ```
405
405
#[ stable( feature = "rwlock_get_mut" , since = "1.6.0" ) ]
406
406
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 ( ) ;
410
408
poison:: map_result ( self . poison . borrow ( ) , |_| data)
411
409
}
412
410
}
You can’t perform that action at this time.
0 commit comments