safe transmute: Rename `BikeshedIntrinsicFrom` to `TransmuteFrom` · patricklam/verify-rust-std@33e2d7e
@@ -11,10 +11,10 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
1111///
1212/// # Safety
1313///
14-/// If `Dst: BikeshedIntrinsicFrom<Src, ASSUMPTIONS>`, the compiler guarantees
15-/// that `Src` is soundly *union-transmutable* into a value of type `Dst`,
16-/// provided that the programmer has guaranteed that the given
17-/// [`ASSUMPTIONS`](Assume) are satisfied.
14+/// If `Dst: TransmuteFrom<Src, ASSUMPTIONS>`, the compiler guarantees that
15+/// `Src` is soundly *union-transmutable* into a value of type `Dst`, provided
16+/// that the programmer has guaranteed that the given [`ASSUMPTIONS`](Assume)
17+/// are satisfied.
1818///
1919/// A union-transmute is any bit-reinterpretation conversion in the form of:
2020///
@@ -47,15 +47,15 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
4747#[cfg_attr(not(bootstrap), doc = "```rust")]
4848/// #![feature(transmutability)]
4949///
50-/// use core::mem::{Assume, BikeshedIntrinsicFrom};
50+/// use core::mem::{Assume, TransmuteFrom};
5151///
5252/// let src = 42u8; // size = 1
5353///
5454/// #[repr(C, align(2))]
5555/// struct Dst(u8); // size = 2
5656//
5757/// let _ = unsafe {
58-/// <Dst as BikeshedIntrinsicFrom<u8, { Assume::SAFETY }>>::transmute(src)
58+/// <Dst as TransmuteFrom<u8, { Assume::SAFETY }>>::transmute(src)
5959/// };
6060/// ```
6161///
@@ -87,7 +87,7 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
8787#[lang = "transmute_trait"]
8888#[rustc_deny_explicit_impl(implement_via_object = false)]
8989#[rustc_coinductive]
90-pub unsafe trait BikeshedIntrinsicFrom<Src, const ASSUME: Assume = { Assume::NOTHING }>
90+pub unsafe trait TransmuteFrom<Src, const ASSUME: Assume = { Assume::NOTHING }>
9191where
9292Src: ?Sized,
9393{
@@ -140,23 +140,21 @@ where
140140}
141141}
142142143-/// Configurable proof assumptions of [`BikeshedIntrinsicFrom`].
143+/// Configurable proof assumptions of [`TransmuteFrom`].
144144///
145145/// When `false`, the respective proof obligation belongs to the compiler. When
146146/// `true`, the onus of the safety proof belongs to the programmer.
147-/// [`BikeshedIntrinsicFrom`].
148147#[unstable(feature = "transmutability", issue = "99571")]
149148#[lang = "transmute_opts"]
150149#[derive(PartialEq, Eq, Clone, Copy, Debug)]
151150pub struct Assume {
152-/// When `false`, [`BikeshedIntrinsicFrom`] is not implemented for
153- /// transmutations that might violate the the alignment requirements of
154- /// references; e.g.:
151+/// When `false`, [`TransmuteFrom`] is not implemented for transmutations
152+ /// that might violate the the alignment requirements of references; e.g.:
155153 ///
156154 #[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
157155#[cfg_attr(not(bootstrap), doc = "```compile_fail,E0277")]
158156/// #![feature(transmutability)]
159- /// use core::mem::{align_of, BikeshedIntrinsicFrom};
157+ /// use core::mem::{align_of, TransmuteFrom};
160158 ///
161159 /// assert_eq!(align_of::<[u8; 2]>(), 1);
162160 /// assert_eq!(align_of::<u16>(), 2);
@@ -165,26 +163,26 @@ pub struct Assume {
165163 ///
166164 /// // SAFETY: No safety obligations.
167165 /// let dst: &u16 = unsafe {
168- /// <_ as BikeshedIntrinsicFrom<_>>::transmute(src)
166+ /// <_ as TransmuteFrom<_>>::transmute(src)
169167 /// };
170168 /// ```
171169 ///
172- /// When `true`, [`BikeshedIntrinsicFrom`] assumes that *you* have ensured
170+ /// When `true`, [`TransmuteFrom`] assumes that *you* have ensured
173171 /// that references in the transmuted value satisfy the alignment
174172 /// requirements of their referent types; e.g.:
175173 ///
176174 #[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
177175#[cfg_attr(not(bootstrap), doc = "```rust")]
178176/// #![feature(pointer_is_aligned_to, transmutability)]
179- /// use core::mem::{align_of, Assume, BikeshedIntrinsicFrom};
177+ /// use core::mem::{align_of, Assume, TransmuteFrom};
180178 ///
181179 /// let src: &[u8; 2] = &[0xFF, 0xFF];
182180 ///
183181 /// let maybe_dst: Option<&u16> = if <*const _>::is_aligned_to(src, align_of::<u16>()) {
184182 /// // SAFETY: We have checked above that the address of `src` satisfies the
185183 /// // alignment requirements of `u16`.
186184 /// Some(unsafe {
187- /// <_ as BikeshedIntrinsicFrom<_, { Assume::ALIGNMENT }>>::transmute(src)
185+ /// <_ as TransmuteFrom<_, { Assume::ALIGNMENT }>>::transmute(src)
188186 /// })
189187 /// } else {
190188 /// None
@@ -194,21 +192,21 @@ pub struct Assume {
194192 /// ```
195193 pub alignment: bool,
196194197-/// When `false`, [`BikeshedIntrinsicFrom`] is not implemented for
198- /// transmutations that extend the lifetimes of references.
195+/// When `false`, [`TransmuteFrom`] is not implemented for transmutations
196+ /// that extend the lifetimes of references.
199197 ///
200- /// When `true`, [`BikeshedIntrinsicFrom`] assumes that *you* have ensured
201- /// that references in the transmuted value do not outlive their referents.
198+ /// When `true`, [`TransmuteFrom`] assumes that *you* have ensured that
199+ /// references in the transmuted value do not outlive their referents.
202200 pub lifetimes: bool,
203201204-/// When `false`, [`BikeshedIntrinsicFrom`] is not implemented for
205- /// transmutations that might violate the library safety invariants of the
206- /// destination type; e.g.:
202+/// When `false`, [`TransmuteFrom`] is not implemented for transmutations
203+ /// that might violate the library safety invariants of the destination
204+ /// type; e.g.:
207205 ///
208206 #[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
209207#[cfg_attr(not(bootstrap), doc = "```compile_fail,E0277")]
210208/// #![feature(transmutability)]
211- /// use core::mem::BikeshedIntrinsicFrom;
209+ /// use core::mem::TransmuteFrom;
212210 ///
213211 /// let src: u8 = 3;
214212 ///
@@ -219,18 +217,18 @@ pub struct Assume {
219217 ///
220218 /// // SAFETY: No safety obligations.
221219 /// let dst: EvenU8 = unsafe {
222- /// <_ as BikeshedIntrinsicFrom<_>>::transmute(src)
220+ /// <_ as TransmuteFrom<_>>::transmute(src)
223221 /// };
224222 /// ```
225223 ///
226- /// When `true`, [`BikeshedIntrinsicFrom`] assumes that *you* have ensured
224+ /// When `true`, [`TransmuteFrom`] assumes that *you* have ensured
227225 /// that undefined behavior does not arise from using the transmuted value;
228226 /// e.g.:
229227 ///
230228 #[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
231229#[cfg_attr(not(bootstrap), doc = "```rust")]
232230/// #![feature(transmutability)]
233- /// use core::mem::{Assume, BikeshedIntrinsicFrom};
231+ /// use core::mem::{Assume, TransmuteFrom};
234232 ///
235233 /// let src: u8 = 42;
236234 ///
@@ -242,7 +240,7 @@ pub struct Assume {
242240 /// let maybe_dst: Option<EvenU8> = if src % 2 == 0 {
243241 /// // SAFETY: We have checked above that the value of `src` is even.
244242 /// Some(unsafe {
245- /// <_ as BikeshedIntrinsicFrom<_, { Assume::SAFETY }>>::transmute(src)
243+ /// <_ as TransmuteFrom<_, { Assume::SAFETY }>>::transmute(src)
246244 /// })
247245 /// } else {
248246 /// None
@@ -252,39 +250,39 @@ pub struct Assume {
252250 /// ```
253251 pub safety: bool,
254252255-/// When `false`, [`BikeshedIntrinsicFrom`] is not implemented for
256- /// transmutations that might violate the language-level bit-validity
257- /// invariant of the destination type; e.g.:
253+/// When `false`, [`TransmuteFrom`] is not implemented for transmutations
254+ /// that might violate the language-level bit-validity invariant of the
255+ /// destination type; e.g.:
258256 ///
259257 #[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
260258#[cfg_attr(not(bootstrap), doc = "```compile_fail,E0277")]
261259/// #![feature(transmutability)]
262- /// use core::mem::BikeshedIntrinsicFrom;
260+ /// use core::mem::TransmuteFrom;
263261 ///
264262 /// let src: u8 = 3;
265263 ///
266264 /// // SAFETY: No safety obligations.
267265 /// let dst: bool = unsafe {
268- /// <_ as BikeshedIntrinsicFrom<_>>::transmute(src)
266+ /// <_ as TransmuteFrom<_>>::transmute(src)
269267 /// };
270268 /// ```
271269 ///
272- /// When `true`, [`BikeshedIntrinsicFrom`] assumes that *you* have ensured
270+ /// When `true`, [`TransmuteFrom`] assumes that *you* have ensured
273271 /// that the value being transmuted is a bit-valid instance of the
274272 /// transmuted value; e.g.:
275273 ///
276274 #[cfg_attr(bootstrap, doc = "```rust,ignore not runnable on bootstrap")]
277275#[cfg_attr(not(bootstrap), doc = "```rust")]
278276/// #![feature(transmutability)]
279- /// use core::mem::{Assume, BikeshedIntrinsicFrom};
277+ /// use core::mem::{Assume, TransmuteFrom};
280278 ///
281279 /// let src: u8 = 1;
282280 ///
283281 /// let maybe_dst: Option<bool> = if src == 0 || src == 1 {
284282 /// // SAFETY: We have checked above that the value of `src` is a bit-valid
285283 /// // instance of `bool`.
286284 /// Some(unsafe {
287- /// <_ as BikeshedIntrinsicFrom<_, { Assume::VALIDITY }>>::transmute(src)
285+ /// <_ as TransmuteFrom<_, { Assume::VALIDITY }>>::transmute(src)
288286 /// })
289287 /// } else {
290288 /// None
@@ -301,35 +299,34 @@ impl ConstParamTy_ for Assume {}
301299impl UnsizedConstParamTy for Assume {}
302300303301impl Assume {
304-/// With this, [`BikeshedIntrinsicFrom`] does not assume you have ensured
305- /// any safety obligations are met, and relies only upon its own analysis to
306- /// (dis)prove transmutability.
302+/// With this, [`TransmuteFrom`] does not assume you have ensured any safety
303+ /// obligations are met, and relies only upon its own analysis to (dis)prove
304+ /// transmutability.
307305 #[unstable(feature = "transmutability", issue = "99571")]
308306pub const NOTHING: Self =
309307Self { alignment: false, lifetimes: false, safety: false, validity: false };
310308311-/// With this, [`BikeshedIntrinsicFrom`] assumes only that you have ensured
312- /// that references in the transmuted value satisfy the alignment
313- /// requirements of their referent types. See [`Assume::alignment`] for
314- /// examples.
309+/// With this, [`TransmuteFrom`] assumes only that you have ensured that
310+ /// references in the transmuted value satisfy the alignment requirements of
311+ /// their referent types. See [`Assume::alignment`] for examples.
315312 #[unstable(feature = "transmutability", issue = "99571")]
316313pub const ALIGNMENT: Self = Self { alignment: true, ..Self::NOTHING };
317314318-/// With this, [`BikeshedIntrinsicFrom`] assumes only that you have ensured
319- /// that references in the transmuted value do not outlive their referents.
320- /// See [`Assume::lifetimes`] for examples.
315+/// With this, [`TransmuteFrom`] assumes only that you have ensured that
316+ /// references in the transmuted value do not outlive their referents. See
317+ /// [`Assume::lifetimes`] for examples.
321318 #[unstable(feature = "transmutability", issue = "99571")]
322319pub const LIFETIMES: Self = Self { lifetimes: true, ..Self::NOTHING };
323320324-/// With this, [`BikeshedIntrinsicFrom`] assumes only that you have ensured
325- /// that undefined behavior does not arise from using the transmuted value.
326- /// See [`Assume::safety`] for examples.
321+/// With this, [`TransmuteFrom`] assumes only that you have ensured that
322+ /// undefined behavior does not arise from using the transmuted value. See
323+ /// [`Assume::safety`] for examples.
327324 #[unstable(feature = "transmutability", issue = "99571")]
328325pub const SAFETY: Self = Self { safety: true, ..Self::NOTHING };
329326330-/// With this, [`BikeshedIntrinsicFrom`] assumes only that you have ensured
331- /// that the value being transmuted is a bit-valid instance of the
332- /// transmuted value. See [`Assume::validity`] for examples.
327+/// With this, [`TransmuteFrom`] assumes only that you have ensured that the
328+ /// value being transmuted is a bit-valid instance of the transmuted value.
329+ /// See [`Assume::validity`] for examples.
333330 #[unstable(feature = "transmutability", issue = "99571")]
334331pub const VALIDITY: Self = Self { validity: true, ..Self::NOTHING };
335332@@ -348,7 +345,7 @@ impl Assume {
348345 /// transmutability,
349346 /// )]
350347 /// #![allow(incomplete_features)]
351- /// use core::mem::{align_of, Assume, BikeshedIntrinsicFrom};
348+ /// use core::mem::{align_of, Assume, TransmuteFrom};
352349 ///
353350 /// /// Attempts to transmute `src` to `&Dst`.
354351 /// ///
@@ -360,15 +357,15 @@ impl Assume {
360357 /// /// alignment, are satisfied.
361358 /// unsafe fn try_transmute_ref<'a, Src, Dst, const ASSUME: Assume>(src: &'a Src) -> Option<&'a Dst>
362359 /// where
363- /// &'a Dst: BikeshedIntrinsicFrom<&'a Src, { ASSUME.and(Assume::ALIGNMENT) }>,
360+ /// &'a Dst: TransmuteFrom<&'a Src, { ASSUME.and(Assume::ALIGNMENT) }>,
364361 /// {
365362 /// if <*const _>::is_aligned_to(src, align_of::<Dst>()) {
366363 /// // SAFETY: By the above dynamic check, we have ensured that the address
367364 /// // of `src` satisfies the alignment requirements of `&Dst`. By contract
368365 /// // on the caller, the safety obligations required by `ASSUME` have also
369366 /// // been satisfied.
370367 /// Some(unsafe {
371- /// <_ as BikeshedIntrinsicFrom<_, { ASSUME.and(Assume::ALIGNMENT) }>>::transmute(src)
368+ /// <_ as TransmuteFrom<_, { ASSUME.and(Assume::ALIGNMENT) }>>::transmute(src)
372369 /// })
373370 /// } else {
374371 /// None