rust/library
Stuart Cook 5b9211c5b3
Rollup merge of #141470 - GuillaumeGomez:function_casts_as_integer, r=urgau
Add new `function_casts_as_integer` lint

The `function_casts_as_integer` lint detects cases where users cast a function pointer into an integer.

*warn-by-default*

### Example

```rust
fn foo() {}
let x = foo as usize;
```

```
warning: casting a function into an integer implicitly
  --> $DIR/function_casts_as_integer.rs:9:17
   |
LL |     let x = foo as usize;
   |                 ^^^^^^^^
   |
help: add `fn() as usize`
   |
LL |     let x = foo as fn() as usize;
   |                 +++++++
```

### Explanation

You should never cast a function directly into an integer but go through a cast as `fn` first to make it obvious what's going on. It also allows to prevent confusion with (associated) constants.

Related to https://github.com/rust-lang/rust/issues/81686 and https://stackoverflow.com/questions/68701177/whats-the-meaning-of-casting-a-rust-enum-variant-to-a-numeric-data-type

r? ````@urgau````
2025-11-11 21:09:32 +11:00
..
alloc Auto merge of #148737 - zachs18:unit-is-zero, r=joboet 2025-11-11 02:44:37 +00:00
alloctests alloc: remove test of unsound specialization behaviour 2025-11-09 17:31:19 +01:00
backtrace@b65ab935fb Update the backtrace submodule 2025-06-16 07:00:13 +00:00
compiler-builtins Mark float intrinsics with no preconditions as safe 2025-09-21 20:37:51 -04:00
core Rollup merge of #141470 - GuillaumeGomez:function_casts_as_integer, r=urgau 2025-11-11 21:09:32 +11:00
coretests Allow function_casts_as_integer in coretest test 2025-11-10 16:38:28 +01:00
panic_abort Use core via rustc-std-workspace-core in library/panic* 2025-07-31 22:47:24 +00:00
panic_unwind Fix new function_casts_as_integer lint errors in core, std, panic_unwind and compiler crates 2025-11-10 16:38:28 +01:00
portable-simd Add alignment parameter to simd_masked_{load,store} 2025-11-04 02:30:59 +05:30
proc_macro Update CURRENT_RUSTC_VERSION post-bump 2025-10-28 13:22:00 -07:00
profiler_builtins Fix profiler_builtins build script to handle full path to profiler lib 2025-04-11 16:57:38 +02:00
rtstartup Update cfg(bootstrap) 2025-07-01 10:55:49 -07:00
rustc-std-workspace-alloc Disable unit tests for stdlib packages that don't contain any 2025-07-24 09:15:28 +00:00
rustc-std-workspace-core Use core via rustc-std-workspace-core in library/panic* 2025-07-31 22:47:24 +00:00
rustc-std-workspace-std Disable unit tests for stdlib packages that don't contain any 2025-07-24 09:15:28 +00:00
std Fix new function_casts_as_integer lint errors in core, std, panic_unwind and compiler crates 2025-11-10 16:38:28 +01:00
std_detect Rollup merge of #147024 - brad0:std_detect_openbsd_elf_aux_info, r=Mark-Simulacrum 2025-11-08 15:42:20 +01:00
stdarch stabilize s390x_target_feature_vector 2025-11-06 12:49:48 +01:00
sysroot Add panic=immediate-abort 2025-09-21 13:12:18 -04:00
test Rollup merge of #142807 - sourcefrog:failfast, r=dtolnay 2025-09-17 14:56:41 +10:00
unwind Move wasm throw intrinsic back to unwind 2025-10-30 15:13:32 +03:00
windows_targets Rollup merge of #144399 - bjorn3:stdlib_tests_separate_packages, r=Mark-Simulacrum 2025-07-28 08:36:53 +02:00
Cargo.lock Auto merge of #147029 - neuschaefer:memchr-2.7.6, r=marcoieni 2025-11-07 21:58:38 +00:00
Cargo.toml Remove the std workspace patch for compiler-builtins 2025-08-19 18:56:35 +00:00