Closed
Description
Given the following code:
#![warn(clippy::fn_to_numeric_cast)]
fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 {
f as i32
}
Clippy gives the following suggestion:
error: casting function pointer `f` to `i32`, which truncates the value
--> $DIR/fn_to_numeric_cast.rs:53:5
|
LL | f as i32
| ^^^^^^^^ help: try: `f as usize`
Applying this, results in a compilation error:
error[E0308]: mismatched types
--> tests/ui/fn_to_numeric_cast.fixed:53:5
|
52 | fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 {
| --- expected `i32` because of return type
53 | f as usize
| ^^^^^^^^^^ expected i32, found usize
I'm not really sure if Clippy can suggest to change the return type of the function as well. Or maybe Clippy should mark this suggestion as MaybeIncorrect
if the cast is the return value of the function?
(Split off from #3630)
edit: Also make sure this is fixed for fn_to_numeric_cast_with_truncation