Skip to content

as-pointer-underscore suggests *const fn() -> u32 {foo} #15281

@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn clippy::as-pointer-underscore

this code:

fn foo() -> u32 {
    42
}

fn main() {
    let _ = &foo as *const _;
}

caused the following diagnostics:

    Checking _a v0.1.0 (/tmp/icemaker_global_tempdir.rRt3FW0YoNlv/icemaker_clippyfix_tempdir.1JeGlSZeKs9N/_a)
warning: using inferred pointer cast
 --> src/main.rs:6:21
  |
6 |     let _ = &foo as *const _;
  |                     ^^^^^^^^ help: use explicit type: `*const fn() -> u32 {foo}`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#as_pointer_underscore
  = note: requested on the command line with `--force-warn clippy::as-pointer-underscore`

warning: `_a` (bin "_a") generated 1 warning (run `cargo clippy --fix --bin "_a"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.36s

However after applying these diagnostics, the resulting code:

fn foo() -> u32 {
    42
}

fn main() {
    let _ = &foo as *const fn() -> u32 {foo};
}

no longer compiled:

    Checking _a v0.1.0 (/tmp/icemaker_global_tempdir.rRt3FW0YoNlv/icemaker_clippyfix_tempdir.1JeGlSZeKs9N/_a)
error: expected one of `!`, `(`, `.`, `::`, `;`, `<`, `?`, or `else`, found `{`
 --> src/main.rs:6:40
  |
6 |     let _ = &foo as *const fn() -> u32 {foo};
  |                                        ^ expected one of 8 possible tokens

error: could not compile `_a` (bin "_a" test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_a` (bin "_a") due to 1 previous error

Version:

rustc 1.90.0-nightly (3014e79f9 2025-07-15)
binary: rustc
commit-hash: 3014e79f9c8d5510ea7b3a3b70d171d0948b1e96
commit-date: 2025-07-15
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions