Open
Description
I tried this code:
#[derive(Debug, PartialEq, Eq)]
enum Foo {
Negative = -1,
Positive = 1,
}
#[test]
fn t() {
let transmuted: Foo = unsafe {
std::mem::transmute::<i8, Foo>(-1)
};
assert_eq!(transmuted, Foo::Negative);
}
I expected to see this happen: The test passes
Instead, this happened:
thread 't' panicked at src/lib.rs:10:9:
trying to construct an enum from an invalid value 0xffffffffffffffffffffffffffffffff
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Meta
rustc --version --verbose
:
rustc 1.90.0-nightly (11ad40bb8 2025-06-28)
binary: rustc
commit-hash: 11ad40bb839ca16f74784b4ab72596ad85587298
commit-date: 2025-06-28
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7
Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=c5012dd5ec0afc1bea52e85e81ff28e9
Seems to be related to #141759