@@ -110,10 +110,19 @@ impl<I: invariant::Validity> ValidityVariance<I> for Invariant {
110
110
unsafe impl < T , I : Invariants > TransparentWrapper < I > for MaybeUninit < T > {
111
111
type Inner = T ;
112
112
113
- // SAFETY: Per [1], `MaybeUninit<T>` has `UnsafeCell`s covering the same
114
- // byte ranges as `Inner = T`.
113
+ // SAFETY: `MaybeUninit<T>` has `UnsafeCell`s covering the same byte ranges
114
+ // as `Inner = T`. This is not explicitly documented, but it can be
115
+ // inferred. Per [1] in the preceding safety comment, `MaybeUninit<T>` has
116
+ // the same size as `T`. Further, note the signature of
117
+ // `MaybeUninit::assume_init_ref` [2]:
118
+ //
119
+ // pub unsafe fn assume_init_ref(&self) -> &T
120
+ //
121
+ // If the argument `&MaybeUninit<T>` and the returned `&T` had `UnsafeCell`s
122
+ // at different offsets, this would be unsound. Its existence is proof that
123
+ // this is not the case.
115
124
//
116
- // [1] TODO(#896): Write a safety proof before the next stable release.
125
+ // [2] https://doc.rust-lang.org/1.81.0/std/mem/union.MaybeUninit.html#method.assume_init_ref
117
126
type UnsafeCellVariance = Covariant ;
118
127
// SAFETY: Per [1], `MaybeUninit<T>` has the same layout as `T`, and thus
119
128
// has the same alignment as `T`.
@@ -280,7 +289,7 @@ unsafe impl<T: ?Sized, I: Invariants> TransparentWrapper<I> for UnsafeCell<T> {
280
289
// subsequent sentence in the documentation makes it clear that this is the
281
290
// intention.
282
291
//
283
- // [1] Per https://doc.rust-lang.org/std /cell/struct.UnsafeCell.html#memory-layout:
292
+ // [1] Per https://doc.rust-lang.org/1.81.0/core /cell/struct.UnsafeCell.html#memory-layout:
284
293
//
285
294
// `UnsafeCell<T>` has the same in-memory representation as its inner type
286
295
// `T`. A consequence of this guarantee is that it is possible to convert
0 commit comments