Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3bab8e4

Browse files
matthiaskrgrgitbot
authored and
gitbot
committedMar 11, 2025
Rollup merge of rust-lang#135379 - steffahn:uniquerc-invariant, r=Mark-Simulacrum
Make (unstable API) `UniqueRc` invariant for soundness Add test case from rust-lang#133572 (comment) (comment in review of `UniqueArc`), and fix the issue for `UniqueRc`.
2 parents f568a1e + 3947bc2 commit 3bab8e4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎alloc/src/rc.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3708,7 +3708,11 @@ pub struct UniqueRc<
37083708
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
37093709
> {
37103710
ptr: NonNull<RcInner<T>>,
3711-
phantom: PhantomData<RcInner<T>>,
3711+
// Define the ownership of `RcInner<T>` for drop-check
3712+
_marker: PhantomData<RcInner<T>>,
3713+
// Invariance is necessary for soundness: once other `Weak`
3714+
// references exist, we already have a form of shared mutability!
3715+
_marker2: PhantomData<*mut T>,
37123716
alloc: A,
37133717
}
37143718

@@ -3994,7 +3998,7 @@ impl<T, A: Allocator> UniqueRc<T, A> {
39943998
},
39953999
alloc,
39964000
));
3997-
Self { ptr: ptr.into(), phantom: PhantomData, alloc }
4001+
Self { ptr: ptr.into(), _marker: PhantomData, _marker2: PhantomData, alloc }
39984002
}
39994003
}
40004004

0 commit comments

Comments
 (0)
Please sign in to comment.