Why is this an issue?

Creating a null function pointer using transmute results in undefined behavior, as null function pointers are not valid in Rust. Instead, use Option<fn()> to safely represent a nullable function pointer.

Code examples

Noncompliant code example

let null_fn: fn() = unsafe { std::mem::transmute(std::ptr::null::<()>()) }; // Noncompliant

Compliant solution

let null_fn: Option<fn()> = None; // Compliant

Resources

Documentation