Skip to content

Commit e4417cf

Browse files
committedAug 2, 2022
Auto merge of rust-lang#92268 - jswrenn:transmute, r=oli-obk
Initial implementation of transmutability trait. *T'was the night before Christmas and all through the codebase, not a miri was stirring — no hint of `unsafe`!* This PR provides an initial, **incomplete** implementation of *[MCP 411: Lang Item for Transmutability](rust-lang/compiler-team#411. The `core::mem::BikeshedIntrinsicFrom` trait provided by this PR is implemented on-the-fly by the compiler for types `Src` and `Dst` when the bits of all possible values of type `Src` are safely reinterpretable as a value of type `Dst`. What this PR provides is: - [x] [support for transmutations involving primitives](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/primitives) - [x] [support for transmutations involving arrays](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/arrays) - [x] [support for transmutations involving structs](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/structs) - [x] [support for transmutations involving enums](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/enums) - [x] [support for transmutations involving unions](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/unions) - [x] [support for weaker validity checks](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/unions/should_permit_intersecting_if_validity_is_assumed.rs) (i.e., `Assume::VALIDITY`) - [x] visibility checking What isn't yet implemented: - [ ] transmutability options passed using the `Assume` struct - [ ] [support for references](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/references.rs) - [ ] smarter error messages These features will be implemented in future PRs.
2 parents 4493a0f + 965ffb0 commit e4417cf

File tree

96 files changed

+6026
-2
lines changed

Some content is hidden

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

96 files changed

+6026
-2
lines changed
 

‎Cargo.lock

+15
Original file line numberDiff line numberDiff line change
@@ -4553,6 +4553,7 @@ dependencies = [
45534553
"rustc_session",
45544554
"rustc_span",
45554555
"rustc_target",
4556+
"rustc_transmute",
45564557
"smallvec",
45574558
"tracing",
45584559
]
@@ -4577,6 +4578,20 @@ dependencies = [
45774578
"tracing",
45784579
]
45794580

4581+
[[package]]
4582+
name = "rustc_transmute"
4583+
version = "0.1.0"
4584+
dependencies = [
4585+
"itertools",
4586+
"rustc_data_structures",
4587+
"rustc_infer",
4588+
"rustc_macros",
4589+
"rustc_middle",
4590+
"rustc_span",
4591+
"rustc_target",
4592+
"tracing",
4593+
]
4594+
45804595
[[package]]
45814596
name = "rustc_ty_utils"
45824597
version = "0.0.0"

‎compiler/rustc_hir/src/lang_items.rs

+3
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ language_item_table! {
191191
CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1);
192192
DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1);
193193

194+
// language items relating to transmutability
195+
TransmuteTrait, sym::transmute_trait, transmute_trait, Target::Trait, GenericRequirement::Exact(6);
196+
194197
Add(Op), sym::add, add_trait, Target::Trait, GenericRequirement::Exact(1);
195198
Sub(Op), sym::sub, sub_trait, Target::Trait, GenericRequirement::Exact(1);
196199
Mul(Op), sym::mul, mul_trait, Target::Trait, GenericRequirement::Exact(1);

0 commit comments

Comments
 (0)