]> git.lizzy.rs Git - rust.git/commitdiff
Clarify and restrict when `{Arc,Rc}::get_mut_unchecked` is allowed.
authorZachary S <zasample18+github@gmail.com>
Fri, 2 Sep 2022 06:34:34 +0000 (01:34 -0500)
committerZachary S <zasample18+github@gmail.com>
Fri, 18 Nov 2022 18:50:41 +0000 (12:50 -0600)
library/alloc/src/rc.rs
library/alloc/src/sync.rs

index f3cbfe27b3eed620adf88462ecba8e7c0dfdf80e..1e9ed3889e84f17abd6eaa795c3d88bca548d603 100644 (file)
@@ -1091,10 +1091,11 @@ pub fn get_mut(this: &mut Self) -> Option<&mut T> {
     ///
     /// # Safety
     ///
-    /// Any other `Rc` or [`Weak`] pointers to the same allocation must not be dereferenced
-    /// for the duration of the returned borrow.
-    /// This is trivially the case if no such pointers exist,
-    /// for example immediately after `Rc::new`.
+    /// If any other `Rc` or [`Weak`] pointers to the same allocation exist, then
+    /// they must be must not be dereferenced or have active borrows for the duration
+    /// of the returned borrow, and their inner type must be exactly the same as the
+    /// inner type of this Rc (including lifetimes). This is trivially the case if no
+    /// such pointers exist, for example immediately after `Rc::new`.
     ///
     /// # Examples
     ///
index 37e07eb5998b332ffdeb54f4fe675557800e289d..2bb5030c51eb616a41b3a9707db0dbd13cd76411 100644 (file)
@@ -1630,10 +1630,11 @@ pub fn get_mut(this: &mut Self) -> Option<&mut T> {
     ///
     /// # Safety
     ///
-    /// Any other `Arc` or [`Weak`] pointers to the same allocation must not be dereferenced
-    /// for the duration of the returned borrow.
-    /// This is trivially the case if no such pointers exist,
-    /// for example immediately after `Arc::new`.
+    /// If any other `Arc` or [`Weak`] pointers to the same allocation exist, then
+    /// they must be must not be dereferenced or have active borrows for the duration
+    /// of the returned borrow, and their inner type must be exactly the same as the
+    /// inner type of this Rc (including lifetimes). This is trivially the case if no
+    /// such pointers exist, for example immediately after `Arc::new`.
     ///
     /// # Examples
     ///