fn
ptr RS-E1027Creating a null function pointer is undefined behavior.
Certain Rust types are defined to never be null.
This includes references (&T, &mut T), boxes (Box
When interfacing with C, pointers that might be null
are often used, possibly requiring some convoluted
transmutes and/or unsafe code to handle conversions
to or from Rust types.
However, trying to construct or work with these invalid values is undefined behavior.
fn foo() {
let null_fn: fn() = unsafe { std::mem::transmute( std::ptr::null::<()>() ) };
}
fn foo() {
let null_fn: Option<fn()> = None;
}