diff options
| author | bors <bors@rust-lang.org> | 2021-10-07 14:14:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-10-07 14:14:19 +0000 |
| commit | 8aff5dd570fe4fbefdcf25358980fe8680e4eea5 (patch) | |
| tree | 2b2417585ed7152d51dcf001cd867060c4efb348 /clippy_lints/src/lib.register_lints.rs | |
| parent | 872f3213f21a5efb622115ec9e63e0fe5350b266 (diff) | |
| parent | fbd0fb9aedbee06d0eefeecd62bc710832e0c457 (diff) | |
Auto merge of #7705 - michaelsproul:fn_to_numeric_cast_any, r=camsteffen
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
Diffstat (limited to 'clippy_lints/src/lib.register_lints.rs')
| -rw-r--r-- | clippy_lints/src/lib.register_lints.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 2ba2b3da55c..3c6d8103b6d 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -67,6 +67,7 @@ store.register_lints(&[ casts::CAST_SIGN_LOSS, casts::CHAR_LIT_AS_U8, casts::FN_TO_NUMERIC_CAST, + casts::FN_TO_NUMERIC_CAST_ANY, casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION, casts::PTR_AS_PTR, casts::UNNECESSARY_CAST, |
