document & impl the transmutation modeled by BikeshedIntrinsicFrom
· rust-lang/rust@2540070 (original) (raw)
File tree
17 files changed
lines changed
- compiler/rustc_ty_utils/src
17 files changed
lines changed
Original file line number |
Diff line number |
Diff line change |
@@ -363,6 +363,11 @@ fn resolve_associated_item<'tcx>( |
|
|
363 |
363 |
tcx.item_name(trait_item_id) |
364 |
364 |
), |
365 |
365 |
} |
|
366 |
+} else if tcx.is_lang_item(trait_ref.def_id, LangItem::TransmuteTrait) { |
|
367 |
+let name = tcx.item_name(trait_item_id); |
|
368 |
+assert_eq!(name, sym::transmute); |
|
369 |
+let args = tcx.erase_regions(rcvr_args); |
|
370 |
+Some(ty::Instance::new(trait_item_id, args)) |
366 |
371 |
} else { |
367 |
372 |
Instance::try_resolve_item_for_coroutine(tcx, trait_item_id, trait_id, rcvr_args) |
368 |
373 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -19,7 +19,7 @@ fn main() -> () { |
|
|
19 |
19 |
StorageLive(_2); |
20 |
20 |
StorageLive(_3); |
21 |
21 |
_3 = (); |
22 |
|
-_2 = transmute::<(), Void>(move _3) -> bb4; |
|
22 |
+_2 = std::intrinsics::transmute::<(), Void>(move _3) -> bb4; |
23 |
23 |
} |
24 |
24 |
|
25 |
25 |
bb1: { |
Original file line number |
Diff line number |
Diff line change |
@@ -9,7 +9,7 @@ |
|
|
9 |
9 |
bb0: { |
10 |
10 |
StorageLive(_2); |
11 |
11 |
_2 = copy _1; |
12 |
|
-- _0 = transmute::<std::cmp::Ordering, i8>(move _2) -> [return: bb1, unwind unreachable]; |
|
12 |
+- _0 = std::intrinsics::transmute::<std::cmp::Ordering, i8>(move _2) -> [return: bb1, unwind unreachable]; |
13 |
13 |
+ _0 = move _2 as i8 (Transmute); |
14 |
14 |
+ goto -> bb1; |
15 |
15 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -9,7 +9,7 @@ |
|
|
9 |
9 |
bb0: { |
10 |
10 |
StorageLive(_2); |
11 |
11 |
_2 = copy _1; |
12 |
|
-- _0 = transmute::<std::cmp::Ordering, i8>(move _2) -> [return: bb1, unwind unreachable]; |
|
12 |
+- _0 = std::intrinsics::transmute::<std::cmp::Ordering, i8>(move _2) -> [return: bb1, unwind unreachable]; |
13 |
13 |
+ _0 = move _2 as i8 (Transmute); |
14 |
14 |
+ goto -> bb1; |
15 |
15 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -9,7 +9,7 @@ |
|
|
9 |
9 |
bb0: { |
10 |
10 |
StorageLive(_2); |
11 |
11 |
_2 = copy _1; |
12 |
|
-- _0 = transmute::<&T, *const T>(move _2) -> [return: bb1, unwind unreachable]; |
|
12 |
+- _0 = std::intrinsics::transmute::<&T, *const T>(move _2) -> [return: bb1, unwind unreachable]; |
13 |
13 |
+ _0 = move _2 as *const T (Transmute); |
14 |
14 |
+ goto -> bb1; |
15 |
15 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -9,7 +9,7 @@ |
|
|
9 |
9 |
bb0: { |
10 |
10 |
StorageLive(_2); |
11 |
11 |
_2 = copy _1; |
12 |
|
-- _0 = transmute::<&T, *const T>(move _2) -> [return: bb1, unwind unreachable]; |
|
12 |
+- _0 = std::intrinsics::transmute::<&T, *const T>(move _2) -> [return: bb1, unwind unreachable]; |
13 |
13 |
+ _0 = move _2 as *const T (Transmute); |
14 |
14 |
+ goto -> bb1; |
15 |
15 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -11,7 +11,7 @@ |
|
|
11 |
11 |
|
12 |
12 |
bb0: { |
13 |
13 |
StorageLive(_1); |
14 |
|
-- _1 = transmute::<usize, Box>(const 1_usize) -> [return: bb1, unwind unreachable]; |
|
14 |
+- _1 = std::intrinsics::transmute::<usize, Box>(const 1_usize) -> [return: bb1, unwind unreachable]; |
15 |
15 |
+ _1 = const 1_usize as std::boxed::Box (Transmute); |
16 |
16 |
+ goto -> bb1; |
17 |
17 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -11,7 +11,7 @@ |
|
|
11 |
11 |
|
12 |
12 |
bb0: { |
13 |
13 |
StorageLive(_1); |
14 |
|
-- _1 = transmute::<usize, Box>(const 1_usize) -> [return: bb1, unwind unreachable]; |
|
14 |
+- _1 = std::intrinsics::transmute::<usize, Box>(const 1_usize) -> [return: bb1, unwind unreachable]; |
15 |
15 |
+ _1 = const 1_usize as std::boxed::Box (Transmute); |
16 |
16 |
+ goto -> bb1; |
17 |
17 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -10,7 +10,7 @@ |
|
|
10 |
10 |
|
11 |
11 |
bb0: { |
12 |
12 |
StorageLive(_1); |
13 |
|
-- _1 = transmute::<usize, &mut Never>(const 1_usize) -> [return: bb1, unwind unreachable]; |
|
13 |
+- _1 = std::intrinsics::transmute::<usize, &mut Never>(const 1_usize) -> [return: bb1, unwind unreachable]; |
14 |
14 |
+ _1 = const 1_usize as &mut Never (Transmute); |
15 |
15 |
+ goto -> bb1; |
16 |
16 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -10,7 +10,7 @@ |
|
|
10 |
10 |
|
11 |
11 |
bb0: { |
12 |
12 |
StorageLive(_1); |
13 |
|
-- _1 = transmute::<usize, &mut Never>(const 1_usize) -> [return: bb1, unwind unreachable]; |
|
13 |
+- _1 = std::intrinsics::transmute::<usize, &mut Never>(const 1_usize) -> [return: bb1, unwind unreachable]; |
14 |
14 |
+ _1 = const 1_usize as &mut Never (Transmute); |
15 |
15 |
+ goto -> bb1; |
16 |
16 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -10,7 +10,7 @@ |
|
|
10 |
10 |
|
11 |
11 |
bb0: { |
12 |
12 |
StorageLive(_1); |
13 |
|
-- _1 = transmute::<usize, &Never>(const 1_usize) -> [return: bb1, unwind unreachable]; |
|
13 |
+- _1 = std::intrinsics::transmute::<usize, &Never>(const 1_usize) -> [return: bb1, unwind unreachable]; |
14 |
14 |
+ _1 = const 1_usize as &Never (Transmute); |
15 |
15 |
+ goto -> bb1; |
16 |
16 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -10,7 +10,7 @@ |
|
|
10 |
10 |
|
11 |
11 |
bb0: { |
12 |
12 |
StorageLive(_1); |
13 |
|
-- _1 = transmute::<usize, &Never>(const 1_usize) -> [return: bb1, unwind unreachable]; |
|
13 |
+- _1 = std::intrinsics::transmute::<usize, &Never>(const 1_usize) -> [return: bb1, unwind unreachable]; |
14 |
14 |
+ _1 = const 1_usize as &Never (Transmute); |
15 |
15 |
+ goto -> bb1; |
16 |
16 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -9,7 +9,7 @@ |
|
|
9 |
9 |
bb0: { |
10 |
10 |
StorageLive(_2); |
11 |
11 |
_2 = copy _1; |
12 |
|
-- _0 = transmute::<(), Never>(move _2) -> unwind unreachable; |
|
12 |
+- _0 = std::intrinsics::transmute::<(), Never>(move _2) -> unwind unreachable; |
13 |
13 |
+ _0 = move _2 as Never (Transmute); |
14 |
14 |
+ unreachable; |
15 |
15 |
} |
Original file line number |
Diff line number |
Diff line change |
@@ -9,7 +9,7 @@ |
|
|
9 |
9 |
bb0: { |
10 |
10 |
StorageLive(_2); |
11 |
11 |
_2 = copy _1; |
12 |
|
-- _0 = transmute::<(), Never>(move _2) -> unwind unreachable; |
|
12 |
+- _0 = std::intrinsics::transmute::<(), Never>(move _2) -> unwind unreachable; |
13 |
13 |
+ _0 = move _2 as Never (Transmute); |
14 |
14 |
+ unreachable; |
15 |
15 |
} |
| Original file line number | Diff line number | Diff line change | |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | |
| @@ -1,12 +1,12 @@ | | | |
| 1 | | -error[E0277]: expected a `FnOnce(&str)` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}` | |
| | 1 | +error[E0277]: expected a `FnOnce(&str)` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}` | | |
| 2 | 2 | --> $DIR/coerce-unsafe-to-closure.rs:2:44 | |
| 3 | 3 | | | |
| 4 | 4 | LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute); | |
| 5 | 5 | | --- ^^^^^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | |
| 6 | 6 | | | |
| 7 | 7 | | required by a bound introduced by this call | |
| 8 | 8 | | | |
| 9 | | - = help: the trait `FnOnce(&str)` is not implemented for fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}` | |
| | 9 | + = help: the trait `FnOnce(&str)` is not implemented for fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}` | | |
| 10 | 10 | = note: unsafe function cannot be called generically without an unsafe block | |
| 11 | 11 | note: required by a bound in `Option::::map` | |
| 12 | 12 | --> $SRC_DIR/core/src/option.rs:LL:COL | |
Original file line number |
Diff line number |
Diff line change |
@@ -7,9 +7,9 @@ LL | let _: unsafe extern "rust-intrinsic" fn(isize) -> usize = std::mem::tr |
|
|
7 |
7 |
| expected due to this |
8 |
8 |
| |
9 |
9 |
= note: expected fn pointer `unsafe extern "rust-intrinsic" fn(isize) -> usize` |
10 |
|
- found fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}` |
|
10 |
+ found fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}` |
11 |
11 |
|
12 |
|
-error[E0606]: casting `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}` as `unsafe extern "rust-intrinsic" fn(isize) -> usize` is invalid |
|
12 |
+error[E0606]: casting `unsafe extern "rust-intrinsic" fn(_) -> _ {std::intrinsics::transmute::<_, _>}` as `unsafe extern "rust-intrinsic" fn(isize) -> usize` is invalid |
13 |
13 |
--> $DIR/reify-intrinsic.rs:11:13 |
14 |
14 |
| |
15 |
15 |
LL | let _ = std::mem::transmute as unsafe extern "rust-intrinsic" fn(isize) -> usize; |