Open
Description
Code
pub fn bad_func1(num: i64) -> i32 {
let v2 = unsafe { std::mem::transmute::<i64, &i32>(num) };
*v2
}
Current output
No warning, but the assembly only contains a single `ud2` instruction, which will terminate the program with `SIGILL` if executed.
Desired output
Warn user that this function has undefined behavior and will not work as intended.
Rationale and extra context
This warning should be emitted at very last stages of compiling, and it might be very hard to implement in the current compiler architecture. But it can save time of the developer, specially when there is no test coverage for that function.
It should be a warning and not a hard error, since optimizations can work differently from version to version.
Other cases
Rust Version
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7
Anything else?
No response