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 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | 872f3213f21a5efb622115ec9e63e0fe5350b266 (diff) | |
| parent | fbd0fb9aedbee06d0eefeecd62bc710832e0c457 (diff) | |
| download | rust-8aff5dd570fe4fbefdcf25358980fe8680e4eea5.tar.gz rust-8aff5dd570fe4fbefdcf25358980fe8680e4eea5.zip | |
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 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
