You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This requires us to generalize our prior support for transmuting between
unsized types. In particular, we previously used the `SizeEq` trait to
denote that two types have equal sizes in the face of a cast operation
(in particular, that `*const T as *const U` preserves referent size). In
this commit, we add support for metadata fix-up, which means that we
support casts for which `*const T as *const U` does *not* preserve
referent size. Instead, we compute an affine function at compile time
and apply it at runtime - computing the destination type's metadata as a
function of the source metadata, `dst_meta = A + src_meta * B`. `A` and
`B` are computed at compile time.
We rename `SizeEq` to `SizeCompat`, and permit its `cast_from_raw`
method to perform a runtime metadata fix-up operation. We also relax the
safety post-condition to specify that `cast_from_raw` may return a
pointer with a smaller referent than that of its argument.
This second relaxation prepares us to support size truncating casts, for
example `&[u8] -> &[u16]` - given an odd number of `u8`s, the only way
to return a `&[u16]` is to "lose" the trailing `u8`. We generalize the
safety invariant on `TransmuteFrom` to support such casts.
Makes progress on #1817
Co-authored-by: Jack Wrenn <[email protected]>
gherrit-pr-id: Ib4bc62202e0b3b09d155333b525087f7aa8f02c2
0 commit comments