Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fn_to_numeric_cast_any should not warn cast to pointer #12638

Open
taiki-e opened this issue Apr 6, 2024 · 0 comments
Open

fn_to_numeric_cast_any should not warn cast to pointer #12638

taiki-e opened this issue Apr 6, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@taiki-e
Copy link
Member

taiki-e commented Apr 6, 2024

Summary

Docs says "Checks for casts of a function pointer to any integer type", but it actually warns cast to pointer too.

It may make sense to have a separate lint that warns against casts to arbitrary types, but I believe it is wrong anyway for a lint that is intended to warn against casts to integers to warn against casts to pointers.

Lint Name

fn_to_numeric_cast_any

Reproducer

I tried this code:

#![warn(clippy::fn_to_numeric_cast_any)]

fn fn1() {}
fn main() {
    let _ = fn1 as *const ();
    let _ = fn1 as *mut ();
}

I saw this happen:

warning: casting function pointer `fn1` to `*const ()`
 --> src/main.rs:5:13
  |
5 |     let _ = fn1 as *const ();
  |             ^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `fn1() as *const ()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_any
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::fn_to_numeric_cast_any)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: casting function pointer `fn1` to `*mut ()`
 --> src/main.rs:6:13
  |
6 |     let _ = fn1 as *mut ();
  |             ^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `fn1() as *mut ()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_any

I expected to see this happen: no warning

playground

Version

rustc -vV
rustc 1.79.0-nightly (9d79cd5f7 2024-04-05)
binary: rustc
commit-hash: 9d79cd5f79e75bd0d2083260271307ce9acd9081
commit-date: 2024-04-05
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2

Additional Labels

No response

@taiki-e taiki-e added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant