Skip to content

Commit 3ad9449

Browse files
committed
Make UniqueArc invariant for soundness
1 parent 368b322 commit 3ad9449

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

alloc/src/sync.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,7 +4110,11 @@ pub struct UniqueArc<
41104110
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
41114111
> {
41124112
ptr: NonNull<ArcInner<T>>,
4113-
phantom: PhantomData<ArcInner<T>>,
4113+
// Define the ownership of `ArcInner<T>` for drop-check
4114+
_marker: PhantomData<ArcInner<T>>,
4115+
// Invariance is necessary for soundness: once other `Weak`
4116+
// references exist, we already have a form of shared mutability!
4117+
_marker2: PhantomData<*mut T>,
41144118
alloc: A,
41154119
}
41164120

@@ -4155,7 +4159,7 @@ impl<T, A: Allocator> UniqueArc<T, A> {
41554159
},
41564160
alloc,
41574161
));
4158-
Self { ptr: ptr.into(), phantom: PhantomData, alloc }
4162+
Self { ptr: ptr.into(), _marker: PhantomData, _marker2: PhantomData, alloc }
41594163
}
41604164
}
41614165

0 commit comments

Comments
 (0)