Skip to content

redundant_closure false positive, extern fn #7881

Open
@SamRodri

Description

@SamRodri

Lint name: redundant_closure

I tried this code:

pub extern "C" fn foo(func: extern fn()) {
    bar(|| func())
}

pub fn bar(func: impl FnOnce()) {
    func()
}

I expected no lints here, because FnOnce is not implemented for extern fn.

The suggestion causes a compile time error by passing func directly:

pub extern "C" fn foo(func: extern fn()) {
    bar(func)
}

Meta

Rust version (rustc -Vv):

rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-pc-windows-msvc
release: 1.56.0
LLVM version: 13.0.0

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-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