|
($(#[$attr:meta])* $tyvar:ident => $atomic:ty [$native:ty]) => { |
|
// We implement for `$atomic` and set `Inner = $native`. The caller has |
|
// promised that `$atomic` and `$native` are an atomic type and its |
|
// native counterpart, respectively. Per [1], `$atomic` and `$native` |
|
// have the same size. |
|
// |
|
// [1] TODO(#896), TODO(https://github.com/rust-lang/rust/pull/121943): |
|
// Cite docs once they've landed. |
|
$(#[$attr])* |
|
unsafe impl<$tyvar, I: Invariants> TransparentWrapper<I> for $atomic { |
|
unsafe_impl_transparent_wrapper_for_atomic!(@inner $atomic [$native]); |
|
} |
|
}; |
|
(@inner $atomic:ty [$native:ty]) => { |
|
type Inner = UnsafeCell<$native>; |
|
|
|
// SAFETY: It is "obvious" that each atomic type contains a single |
|
// `UnsafeCell` that covers all bytes of the type, but we can also prove |
|
// it: |
|
// - Since `$atomic` provides an API which permits loading and storing |
|
// values of type `$native` via a `&self` (shared) reference, *some* |
|
// interior mutation must be happening, and interior mutation can only |
|
// happen via `UnsafeCell`. Further, there must be enough bytes in |
|
// `$atomic` covered by an `UnsafeCell` to hold every possible value |
|
// of `$native`. |
|
// - Per [1], `$atomic` has the same size as `$native`. This on its own |
|
// isn't enough: it would still be possible for `$atomic` to store |
|
// `$native` using a compact representation (for `$native` types for |
|
// which some bit patterns are illegal). However, this is ruled out by |
|
// the fact that `$atomic` has the same bit validity as `$native` [1]. |
|
// Thus, we can conclude that every byte of `$atomic` must be covered |
|
// by an `UnsafeCell`. |
|
// |
|
// Thus, every byte of `$atomic` is covered by an `UnsafeCell`, and we |
|
// set `type Inner = UnsafeCell<$native>`. Thus, `Self` and |
|
// `Self::Inner` have `UnsafeCell`s covering the same byte ranges. |
|
// |
|
// [1] TODO(#896), TODO(https://github.com/rust-lang/rust/pull/121943): |
|
// Cite docs once they've landed. |
|
type UnsafeCellVariance = Covariant; |
|
|
|
// SAFETY: No safety justification is required for an invariant |
|
// variance. |
|
type AlignmentVariance = Invariant; |
|
|
|
// SAFETY: Per [1], all atomic types have the same bit validity as their |
|
// native counterparts. The caller has promised that `$atomic` and |
|
// `$native` are an atomic type and its native counterpart, |
|
// respectively. |
|
// |
|
// [1] TODO(#896), TODO(https://github.com/rust-lang/rust/pull/121943): |
|
// Cite docs once they've landed. |
|
type ValidityVariance = Covariant; |
This issue tracks all safety proofs which are not complete and need to be completed before we perform a stable release. All such proofs are marked as
// TODO(#896).Outstanding TODOs as of b96b620 (2024-04-29):
zerocopy/src/lib.rs
Lines 3831 to 3870 in b96b620
zerocopy/src/lib.rs
Lines 3908 to 3920 in b96b620
zerocopy/src/lib.rs
Lines 3984 to 3987 in b96b620
zerocopy/src/lib.rs
Lines 4009 to 4029 in b96b620
zerocopy/src/lib.rs
Lines 4267 to 4270 in b96b620
zerocopy/src/util.rs
Lines 107 to 119 in b96b620
zerocopy/src/util.rs
Lines 149 to 161 in b96b620
zerocopy/src/util.rs
Lines 194 to 206 in b96b620
zerocopy/src/util.rs
Lines 349 to 401 in b96b620