RS.CLIPPY.FN_TO_NUMERIC_CAST_ANY
Casting a function pointer to any integer type
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: fn_to_numeric_cast_any. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for casts of a function pointer to any integer type.
Why restrict this?
Casting a function pointer to an integer can have surprising results and can occur accidentally if parentheses are omitted from a function call. If you aren't doing anything low-level with function pointers then you can opt out of casting functions to integers in order to avoid mistakes. Alternatively, you can use this lint to audit all uses of function pointer casts in your code.
Example
// fn1 is cast as `usize`
fn fn1() -> u16 {
1
};
let _ = fn1 as usize;
Use instead:
// maybe you intended to call the function?
fn fn2() -> u16 {
1
};
let _ = fn2() as usize;
// or
// maybe you intended to cast it to a function type?
fn fn3() -> u16 {
1
}
let _ = fn3 as fn() -> u16;