about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorFrank Steffahn <fdsteffahn@gmail.com>2025-01-11 22:18:52 +0100
committerFrank Steffahn <fdsteffahn@gmail.com>2025-01-11 22:36:25 +0100
commitdf57d65c708354d2e2549217a5fa4d7ca89eebfc (patch)
tree5f442abbfaa783f2a41dfcb0a00fd89c98c43385 /library/alloc/src
parentfb65a3ee576feab95a632eb062f466d7a0342310 (diff)
downloadrust-df57d65c708354d2e2549217a5fa4d7ca89eebfc.tar.gz
rust-df57d65c708354d2e2549217a5fa4d7ca89eebfc.zip
Make UniqueRc invariant for soundness
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/rc.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs
index 9256cb0703a..ae3318b839d 100644
--- a/library/alloc/src/rc.rs
+++ b/library/alloc/src/rc.rs
@@ -3708,7 +3708,11 @@ pub struct UniqueRc<
     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
 > {
     ptr: NonNull<RcInner<T>>,
-    phantom: PhantomData<RcInner<T>>,
+    // Define the ownership of `RcInner<T>` for drop-check
+    _marker: PhantomData<RcInner<T>>,
+    // Invariance is necessary for soundness: once other `Weak`
+    // references exist, we already have a form of shared mutability!
+    _marker2: PhantomData<*mut T>,
     alloc: A,
 }
 
@@ -3994,7 +3998,7 @@ impl<T, A: Allocator> UniqueRc<T, A> {
             },
             alloc,
         ));
-        Self { ptr: ptr.into(), phantom: PhantomData, alloc }
+        Self { ptr: ptr.into(), _marker: PhantomData, _marker2: PhantomData, alloc }
     }
 }