Skip to content

Commit d7f1f63

Browse files
committed
Add CastKind::Transmute to MIR
Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic. Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
1 parent 7467f81 commit d7f1f63

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)