Closed

Description
I'm trying to execute some data in Rust, however I'm getting this error:
error[E0080]: it is undefined behavior to use this value
--> src/main.rs:9:1
|
9 | / const executable_data: extern "C" fn() = unsafe {
10 | | std::mem::transmute(address)
11 | | };
| |__^ type validation failed: encountered a pointer, but expected a function pointer
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
Here's the part of my code that matters:
const executable_data: extern "C" fn() = unsafe {
std::mem::transmute(address)
};
In my opinion, there should be a way to force the compiler to accept something like this, because I'm very certain that this is not undefined behavior. Even if it is, I would like to know for certain by learning it the hard way, but sadly the compiler doesn't even let me compile it, so I can't.