Skip to content

Commit 79d8cff

Browse files
committed
Auto merge of #108442 - scottmcm:mir-transmute, r=oli-obk
Add `CastKind::Transmute` to MIR ~~Nothing actually produces it in this commit, so I don't know how to test it, but it also means it shouldn't be possible for it to break anything.~~ Includes lowering `transmute` calls to it, so it's used. Zulip Conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Good.20first.20isssue/near/321849610>
2 parents 0908524 + d7f1f63 commit 79d8cff

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

tests/fail/never_transmute_humans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ struct Human;
77

88
fn main() {
99
let _x: ! = unsafe {
10-
std::mem::transmute::<Human, !>(Human) //~ ERROR: transmuting to uninhabited
10+
std::mem::transmute::<Human, !>(Human) //~ ERROR: entering unreachable code
1111
};
1212
}

tests/fail/never_transmute_humans.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: transmuting to uninhabited type
1+
error: Undefined Behavior: entering unreachable code
22
--> $DIR/never_transmute_humans.rs:LL:CC
33
|
44
LL | std::mem::transmute::<Human, !>(Human)
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entering unreachable code
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

tests/fail/never_transmute_void.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ mod m {
1010
pub struct Void(VoidI);
1111

1212
pub fn f(v: Void) -> ! {
13-
match v.0 {} //~ ERROR: entering unreachable code
13+
match v.0 {}
14+
//~^ ERROR: entering unreachable code
1415
}
1516
}
1617

1718
fn main() {
1819
let v = unsafe { std::mem::transmute::<(), m::Void>(()) };
19-
m::f(v); //~ NOTE: inside `main`
20+
m::f(v);
21+
//~^ NOTE: inside `main`
2022
}

0 commit comments

Comments
 (0)