mirror of
https://github.com/rust-lang/rust.git
synced 2025-09-30 08:16:56 +00:00

MIR validation attempts to determine the number of bytes needed to represent the size of the source type to compute the discriminant for the inhabited target enum. For a ZST source, there is no source data to use as a discriminant so no proper runtime check can be generated. Since that should never be possible, insert a delayed bug to ensure the problem has been properly reported to the user by the type checker.
15 lines
330 B
Rust
15 lines
330 B
Rust
// Do not attempt to take the discriminant as the source
|
|
// converted to a `u128`, that won't work for ZST.
|
|
//
|
|
//@ compile-flags: -Zvalidate-mir
|
|
|
|
enum A {
|
|
B,
|
|
C,
|
|
}
|
|
|
|
fn main() {
|
|
let _: A = unsafe { std::mem::transmute(()) };
|
|
//~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
|
|
}
|