mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-09-21 15:11:56 +00:00
8aff5dd570
Restriction lint for function pointer casts The existing lints for function pointer casts cover the cases where a cast is non-portable or would result in truncation, however there's currently no way to forbid numeric function pointer casts entirely. I've added a new lint `fn_to_numeric_cast_any`, which allows one to ban _all_ numeric function pointer casts, including to `usize`. This is useful if you're writing high-level Rust and want to opt-out of potentially surprising behaviour, avoiding silent bugs from forgotten parentheses, e.g. ```rust fn foo() -> u32 { 10 } fn main() { let _ = foo as usize; // oops, forgot to call foo and got a random address instead! } ``` ~~I'm open to suggestions for the naming of the lint, because `fn_to_numeric_cast_any` is a bit clunky. Ideally I'd call this lint `fn_to_numeric_cast`, but that name is already taken for the more specific lint~~. We've stuck with `fn_to_numeric_cast_any` to avoid renaming the existing lint, or choosing a different name that's too generic (like `fn_cast`). I'm also open to changing the suggestion behaviour, as adding parentheses is only one of many possible ways to fix the lint. changelog: add ``[`fn_to_numeric_cast_any`]`` restriction lint |
||
---|---|---|
.. | ||
cargo | ||
ui | ||
ui-cargo | ||
ui-internal | ||
ui-toml | ||
clippy.toml | ||
compile-test.rs | ||
dogfood.rs | ||
fmt.rs | ||
integration.rs | ||
lint_message_convention.rs | ||
missing-test-files.rs | ||
versioncheck.rs |