I'm not sure if this is a bug, but it does seem really weird.
The following code constructs a null reference pointing to a function item type. Then, it calls that null reference.
fn foo() {}
fn main() {
let mut f = &foo;
unsafe {
(&raw mut f).cast::<usize>().write(0);
}
f();
}
According to Miri, the above code somehow doesn't have any UB. This seems wrong.
Strangely, adding another layer of reference causes Miri to report UB:
fn foo() {}
fn main() {
let mut f = &&foo;
unsafe {
(&raw mut f).cast::<usize>().write(0);
}
f();
}
error: Undefined Behavior: constructing invalid value of type &&fn() {foo}: encountered a null reference
--> src/main.rs:8:5
|
8 | f();
| ^ Undefined Behavior occurred here
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 1 previous error
Reproducible on the playground with Miri version 0.1.0 (2026-07-22 6f72b5dd5f)
I'm not sure if this is a bug, but it does seem really weird.
The following code constructs a null reference pointing to a function item type. Then, it calls that null reference.
According to Miri, the above code somehow doesn't have any UB. This seems wrong.
Strangely, adding another layer of reference causes Miri to report UB:
Reproducible on the playground with Miri version
0.1.0 (2026-07-22 6f72b5dd5f)