Repository navigation
Open
Labels
C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Using the following flags
--force-warn clippy::fn-to-numeric-cast-any
this code:
//@ run-pass
#![allow(dead_code, function_casts_as_integer)]
fn main()
{
fn foo() {
println!("foo!");
}
assert_eq!(foo as *const u8 as usize, foo as usize);
}caused the following diagnostics:
Checking crate-a v0.1.0 (/tmp/icemaker_global_tempdir.S7F855GV8ySO/icemaker_clippyfix_tempdir.wIPx0bUFJxnm/crate-a)
warning: casting function pointer `foo` to `usize`
--> src/main.rs:11:43
|
11 | assert_eq!(foo as *const u8 as usize, foo as usize);
| ^^^^^^^^^^^^
|
= help: for further information visit https://clippy.rust-lang.org/main/index.html#fn_to_numeric_cast_any
= note: requested on the command line with `--force-warn clippy::fn-to-numeric-cast-any`
help: did you mean to invoke the function?
|
11 | assert_eq!(foo as *const u8 as usize, foo() as usize);
| ++
warning: `crate-a` (bin "crate-a") generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
However after applying these diagnostics, the resulting code:
//@ run-pass
#![allow(dead_code, function_casts_as_integer)]
fn main()
{
fn foo() {
println!("foo!");
}
assert_eq!(foo as *const u8 as usize, foo() as usize);
}no longer compiled:
Checking crate-a v0.1.0 (/tmp/icemaker_global_tempdir.S7F855GV8ySO/icemaker_clippyfix_tempdir.wIPx0bUFJxnm/crate-a)
error[E0605]: non-primitive cast: `()` as `usize`
--> src/main.rs:11:43
|
11 | assert_eq!(foo as *const u8 as usize, foo() as usize);
| ^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
For more information about this error, try `rustc --explain E0605`.
error: could not compile `crate-a` (bin "crate-a") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `crate-a` (bin "crate-a" test) due to 1 previous error
Version:
rustc 1.102.0-nightly (646bb8409 2026-11-17)
binary: rustc
commit-hash: 646bb8409b143093219faff19f3a685b874109d6
commit-date: 2026-11-17
host: x86_64-unknown-linux-gnu
release: 1.102.0-nightly
LLVM version: 23.1.5
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
Activity