Skip to content

Can't compare FFI function pointers #38848

Closed
@YaLTeR

Description

@YaLTeR

extern "fastcall", "system", "cdecl" and some others function pointers cannot be compared.

I tried this code:

https://is.gd/5JBZee

extern "fastcall" fn test() {}

fn main() {
    let fastcall_ptr: extern "fastcall" fn() = test;
    
    let check = fastcall_ptr == test;
}

I expected to see this happen: the code compiles fine.

Instead, this happened:

error[E0369]: binary operation `==` cannot be applied to type `extern "fastcall" fn()`
note: an implementation of `std::cmp::PartialEq` might be missing for `extern "fastcall" fn()`
error[E0308]: mismatched types
    expected fn pointer, found fn item

Replacing fastcall with C in this example, or getting rid of extern "fastcall" entirely results in code that compiles fine:

https://is.gd/JI89Zs

fn test() {}
extern "C" fn c_test() {}

fn main() {
    let ptr: fn() = test;
    let c_ptr: extern "C" fn() = c_test;
    
    let check = ptr == test;
    let c_check = c_ptr == c_test;
}

rustc 1.16.0-nightly (4682271 2017-01-03)

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-needs-decisionIssue: In need of a decision.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions