Lines Matching full:src
40 /// Given `Dst: TryTransmuteFromPtr<Src, A, SV, DV, C, _>`, callers may assume
43 /// Given `src: Ptr<'a, Src, (A, _, SV)>`, if the referent of `src` is
44 /// `DV`-valid for `Dst`, then it is sound to transmute `src` into `dst: Ptr<'a,
49 /// Given `src: Ptr<Src, (A, _, SV)>` and `dst: Ptr<Dst, (A, Unaligned, DV)>`,
50 /// `Dst: TryTransmuteFromPtr<Src, A, SV, DV, C, _>` is sound if all of the
56 /// `SV`-valid referents of `src` (NOTE: this condition effectively bans
62 /// `SV`-valid referents of `src` (NOTE: this condition effectively bans
65 /// - No safe code, given access to `src` and `dst`, can cause undefined
68 /// - `Src: Immutable` and `Dst: Immutable`
69 /// - It is sound for shared code to operate on a `&Src` and `&Dst` which
75 /// - `src: Ptr<'a, Src, (A, _, SV)>`
76 /// - `src`'s referent is `DV`-valid for `Dst`
78 /// We are trying to prove that it is sound to perform a cast from `src` to a
80 /// such a cast does not violate any of `src`'s invariants, and that it
83 /// First, by `C: CastExact`, `src`'s address is unchanged, so it still satisfies
88 /// - If it is `Exclusive`, then both `src` and `dst` satisfy `Exclusive`
89 /// aliasing trivially: since `src` and `dst` have the same lifetime, `src` is
93 /// - `Src: Immutable` and `Dst: Immutable`, and so neither `src` nor `dst`
95 /// - It is explicitly sound for safe code to operate on a `&Src` and a `&Dst`
98 /// Third, `src`'s validity is satisfied. By invariant, `src`'s referent began
99 /// as an `SV`-valid `Src`. It is guaranteed to remain so, as either of the
103 /// `SV`-valid referents of `src`. Thus, any value written via `dst` is
104 /// guaranteed to be an `SV`-valid referent of `src`.
112 /// `SV`-valid referents of `src`. Thus, any value written via `src` is
115 Src: ?Sized,
119 C: CastExact<Src, Self>,
129 // - Forwards transmutation: By `Dst: MutationCompatible<Src, A, SV, DV, _>`, we
135 // - Aliasing is `Shared`, `Src: Immutable`, and `Dst: Immutable`, in which
138 // referent as `src`. By `Dst: TransmuteFrom<Src, SV, DV>`, the set of
140 // referents of `src`.
142 // addresses the same referent as `src`. By `Src: TransmuteFrom<Dst, DV, SV>`,
143 // the set of `DV`-valid referents of `src` is a subset of the set of
145 // - No safe code, given access to `src` and `dst`, can cause undefined
146 // behavior: By `Dst: MutationCompatible<Src, A, SV, DV, _>`, at least one of
149 // - `Src: Immutable` and `Dst: Immutable`
150 // - `Dst: InvariantsEq<Src>`, which guarantees that `Src` and `Dst` have the
152 unsafe impl<Src, Dst, SV, DV, A, C, R>
153 TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dst
158 Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
159 Dst: MutationCompatible<Src, A, SV, DV, R> + ?Sized,
160 C: CastExact<Src, Dst>,
165 // - Forwards transmutation: Since aliasing is `Shared` and `Src: Immutable`,
166 // `src` does not permit mutation of its referent.
169 // - No safe code, given access to `src` and `dst`, can cause undefined
170 // behavior: `Src: Immutable` and `Dst: Immutable`
171 unsafe impl<Src, Dst, SV, DV, C> TryTransmuteFromPtr<Src, Shared, SV, DV, C, BecauseImmutable>
176 Src: Immutable + ?Sized,
178 C: CastExact<Src, Dst>,
182 /// Denotes that `src: Ptr<Src, (A, _, SV)>` and `dst: Ptr<Self, (A, _, DV)>`,
184 /// to break library safety invariants of `Src` or `Self`.
189 /// - `Src: Read<A, _>` and `Self: Read<A, _>`
190 /// - `Self: InvariantsEq<Src>`, and, for some `V`:
191 /// - `Dst: TransmuteFrom<Src, V, V>`
192 /// - `Src: TransmuteFrom<Dst, V, V>`
193 pub unsafe trait MutationCompatible<Src: ?Sized, A: Aliasing, SV, DV, R> {}
198 // SAFETY: `Src: Read<A, _>` and `Dst: Read<A, _>`.
199 unsafe impl<Src: ?Sized, Dst: ?Sized, A: Aliasing, SV: Validity, DV: Validity, R>
200 MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
202 Src: Read<A, R>,
219 // SAFETY: `Dst: InvariantsEq<Src> + TransmuteFrom<Src, SV, DV>`, and `Src:
221 unsafe impl<Src: ?Sized, Dst: ?Sized, A: Aliasing, SV: Validity, DV: Validity>
222 MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dst
224 Src: TransmuteFrom<Dst, DV, SV>,
225 Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src>,
267 /// `Dst: TransmuteFromPtr<Src, A, SV, DV, _>` is equivalent to `Dst:
268 /// TryTransmuteFromPtr<Src, A, SV, DV, _> + TransmuteFrom<Src, SV, DV>`.
270 Src: ?Sized,
274 C: CastExact<Src, Self>,
276 >: TryTransmuteFromPtr<Src, A, SV, DV, C, R> + TransmuteFrom<Src, SV, DV>
283 Src: ?Sized,
288 C: CastExact<Src, Dst>,
290 > TransmuteFromPtr<Src, A, SV, DV, C, R> for Dst
292 Dst: TransmuteFrom<Src, SV, DV> + TryTransmuteFromPtr<Src, A, SV, DV, C, R>,
296 /// Denotes that any `SV`-valid `Src` may soundly be transmuted into a
301 /// Given `src: Ptr<Src, (_, _, SV)>` and `dst: Ptr<Dst, (_, _, DV)>`, if the
302 /// referents of `src` and `dst` are the same size, then the set of bit patterns
303 /// allowed to appear in `src`'s referent must be a subset of the set allowed to
306 /// If the referents are not the same size, then `Dst: TransmuteFrom<Src, SV,
308 pub unsafe trait TransmuteFrom<Src: ?Sized, SV, DV> {}
311 /// raw pointer to `Src` to a raw pointer to `Self`.
325 pub trait SizeEq<Src: ?Sized> {
326 type CastFrom: CastExact<Src, Self>;
333 // SAFETY: Since `Src: IntoBytes`, the set of valid `Src`'s is the set of
336 unsafe impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
338 Src: IntoBytes + ?Sized,
346 unsafe impl<Src, Dst> TransmuteFrom<Src, Initialized, Valid> for Dst
348 Src: ?Sized,
354 // nothing to do with `Src` or `Dst` - we're basically just saying `[u8; N]` is
359 unsafe impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
361 Src: ?Sized,
372 unsafe impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
374 Src: ?Sized,
496 fn test_size_eq<Src, Dst: SizeEq<Src>>(mut src: Src) { in test_size_eq() argument
498 <Dst as SizeEq<Src>>::CastFrom::project(crate::pointer::PtrInner::from_mut(&mut src)); in test_size_eq()