|
| 1 | +/// Are values of a type transmutable into values of another type? |
| 2 | +/// |
| 3 | +/// This trait is implemented on-the-fly by the compiler for types `Src` and `Self` when the bits of |
| 4 | +/// any value of type `Self` are safely transmutable into a value of type `Dst`, in a given `Context`, |
| 5 | +/// notwithstanding whatever safety checks you have asked the compiler to [`Assume`] are satisfied. |
| 6 | +#[unstable(feature = "transmutability", issue = "99571")] |
| 7 | +#[cfg_attr(not(bootstrap), lang = "transmute_trait")] |
| 8 | +#[rustc_on_unimplemented( |
| 9 | + message = "`{Src}` cannot be safely transmuted into `{Self}` in the defining scope of `{Context}`.", |
| 10 | + label = "`{Src}` cannot be safely transmuted into `{Self}` in the defining scope of `{Context}`." |
| 11 | +)] |
| 12 | +pub unsafe trait BikeshedIntrinsicFrom< |
| 13 | + Src, |
| 14 | + Context, |
| 15 | + const ASSUME_ALIGNMENT: bool, |
| 16 | + const ASSUME_LIFETIMES: bool, |
| 17 | + const ASSUME_VALIDITY: bool, |
| 18 | + const ASSUME_VISIBILITY: bool, |
| 19 | +> where |
| 20 | + Src: ?Sized, |
| 21 | +{ |
| 22 | +} |
| 23 | + |
| 24 | +/// What transmutation safety conditions shall the compiler assume that *you* are checking? |
| 25 | +#[unstable(feature = "transmutability", issue = "99571")] |
| 26 | +#[derive(PartialEq, Eq, Clone, Copy, Debug)] |
| 27 | +pub struct Assume { |
| 28 | + /// When `true`, the compiler assumes that *you* are ensuring (either dynamically or statically) that |
| 29 | + /// destination referents do not have stricter alignment requirements than source referents. |
| 30 | + pub alignment: bool, |
| 31 | + |
| 32 | + /// When `true`, the compiler assume that *you* are ensuring that lifetimes are not extended in a manner |
| 33 | + /// that violates Rust's memory model. |
| 34 | + pub lifetimes: bool, |
| 35 | + |
| 36 | + /// When `true`, the compiler assumes that *you* are ensuring that the source type is actually a valid |
| 37 | + /// instance of the destination type. |
| 38 | + pub validity: bool, |
| 39 | + |
| 40 | + /// When `true`, the compiler assumes that *you* have ensured that it is safe for you to violate the |
| 41 | + /// type and field privacy of the destination type (and sometimes of the source type, too). |
| 42 | + pub visibility: bool, |
| 43 | +} |
0 commit comments