RS.CLIPPY.TRANSMUTE_NULL_TO_FN
Transmute results in a null function pointer, which is undefined behavior
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: transmute_null_to_fn. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for null function pointer creation through transmute.
Why is this bad?
Creating a null function pointer is undefined behavior.
More info: https://doc.rust-lang.org/nomicon/ffi.html#the-nullable-pointer-optimization
Known problems
Not all cases can be detected at the moment of this writing.
For example, variables which hold a null pointer and are then fed to a transmute
call, aren't detectable yet.
Example
let null_fn: fn() = unsafe { std::mem::transmute( std::ptr::null::<()>() ) };
Use instead:
let null_fn: Option<fn()> = None;