Skip to content

Commit 1ad218f

Browse files
committed
safe transmute: Rename BikeshedIntrinsicFrom to TransmuteFrom
As our implementation of MCP411 nears completion and we begin to solicit testing, it's no longer reasonable to expect testers to type or remember `BikeshedIntrinsicFrom`. The name degrades the ease-of-reading of documentation, and the overall experience of using compiler safe transmute. Tentatively, we'll instead adopt `TransmuteFrom`. This name seems to be the one most likely to be stabilized, after discussion on Zulip [1]. We may want to revisit the ordering of `Src` and `Dst` before stabilization, at which point we'd likely consider `TransmuteInto` or `Transmute`. [1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20should.20.60BikeshedIntrinsicFrom.60.20be.20named.3F
1 parent ae9f501 commit 1ad218f

File tree

112 files changed

+528
-531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+528
-531
lines changed

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ where
862862
_ecx: &mut EvalCtxt<'_, D>,
863863
goal: Goal<I, Self>,
864864
) -> Result<Candidate<I>, NoSolution> {
865-
panic!("`BikeshedIntrinsicFrom` does not have an associated type: {:?}", goal)
865+
panic!("`TransmuteFrom` does not have an associated type: {:?}", goal)
866866
}
867867

868868
fn consider_builtin_effects_intersection_candidate(

library/core/src/mem/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use maybe_uninit::MaybeUninit;
1919

2020
mod transmutability;
2121
#[unstable(feature = "transmutability", issue = "99571")]
22-
pub use transmutability::{Assume, BikeshedIntrinsicFrom};
22+
pub use transmutability::{Assume, TransmuteFrom};
2323

2424
#[stable(feature = "rust1", since = "1.0.0")]
2525
#[doc(inline)]

library/core/src/mem/transmutability.rs

+53-56
Original file line numberDiff line numberDiff line change
@@ -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 }>
9191
where
9292
Src: ?Sized,
9393
{
@@ -140,23 +140,21 @@ where
140140
}
141141
}
142142

143-
/// 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)]
151150
pub 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,
196194

197-
/// 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,
203201

204-
/// 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,
254252

255-
/// 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 {}
301299
impl UnsizedConstParamTy for Assume {}
302300

303301
impl 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")]
308306
pub const NOTHING: Self =
309307
Self { alignment: false, lifetimes: false, safety: false, validity: false };
310308

311-
/// 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")]
316313
pub const ALIGNMENT: Self = Self { alignment: true, ..Self::NOTHING };
317314

318-
/// 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")]
322319
pub const LIFETIMES: Self = Self { lifetimes: true, ..Self::NOTHING };
323320

324-
/// 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")]
328325
pub const SAFETY: Self = Self { safety: true, ..Self::NOTHING };
329326

330-
/// 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")]
334331
pub 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

tests/crashes/123693.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#![feature(transmutability)]
44

55
mod assert {
6-
use std::mem::{Assume, BikeshedIntrinsicFrom};
6+
use std::mem::{Assume, TransmuteFrom};
77

88
pub fn is_transmutable<Src, Dst>()
99
where
10-
Dst: BikeshedIntrinsicFrom<Src, { Assume::NOTHING }>,
10+
Dst: TransmuteFrom<Src, { Assume::NOTHING }>,
1111
{
1212
}
1313
}

tests/crashes/124207.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
trait OpaqueTrait {}
55
type OpaqueType = impl OpaqueTrait;
66
trait AnotherTrait {}
7-
impl<T: std::mem::BikeshedIntrinsicFrom<(), ()>> AnotherTrait for T {}
7+
impl<T: std::mem::TransmuteFrom<(), ()>> AnotherTrait for T {}
88
impl AnotherTrait for OpaqueType {}
99
pub fn main() {}

tests/crashes/125881.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#![feature(transmutability)]
44
#![feature(unboxed_closures,effects)]
55

6-
const fn test() -> impl std::mem::BikeshedIntrinsicFrom() {
6+
const fn test() -> impl std::mem::TransmuteFrom() {
77
|| {}
88
}

tests/crashes/126267.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ pub enum Error {
1414
}
1515

1616
mod assert {
17-
use std::mem::BikeshedIntrinsicFrom;
17+
use std::mem::TransmuteFrom;
1818

1919
pub fn is_transmutable<Src, Dst>()
2020
where
21-
Dst: BikeshedIntrinsicFrom<Src>, // safety is NOT assumed
21+
Dst: TransmuteFrom<Src>, // safety is NOT assumed
2222
{
2323
}
2424
}

tests/crashes/126377.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![feature(generic_const_exprs)]
55

66
mod assert {
7-
use std::mem::{Assume, BikeshedIntrinsicFrom};
7+
use std::mem::{Assume, TransmuteFrom};
88

99
pub fn is_transmutable<
1010
Src,
@@ -15,7 +15,7 @@ mod assert {
1515
const ASSUME_VALIDITY: bool,
1616
>()
1717
where
18-
Dst: BikeshedIntrinsicFrom<
18+
Dst: TransmuteFrom<
1919
Src,
2020
{ }
2121
>,

tests/crashes/126966.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//@ known-bug: rust-lang/rust#126966
22
mod assert {
3-
use std::mem::{Assume, BikeshedIntrinsicFrom};
3+
use std::mem::{Assume, TransmuteFrom};
44

55
pub fn is_transmutable<Src, Dst>()
66
where
7-
Dst: BikeshedIntrinsicFrom<Src>,
7+
Dst: TransmuteFrom<Src>,
88
{
99
}
1010
}

tests/ui/const-generics/adt_const_params/transmutable-ice-110969.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#![allow(incomplete_features, unstable_features)]
55

66
mod assert {
7-
use std::mem::BikeshedIntrinsicFrom;
7+
use std::mem::TransmuteFrom;
88

99
pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>()
1010
where
11-
Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
11+
Dst: TransmuteFrom<Src, Context, ASSUME>,
1212
//~^ ERROR trait takes at most 2 generic arguments but 3 generic arguments were supplied
1313
{
1414
}

0 commit comments

Comments
 (0)