-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weird and inconsistent function pointer comparison behaviour #33879
Comments
Other examples involve function item types |
A few more weirdnesses: fn main() {
let f = foo;
// Compiles, even though the single-argument version doesn't with
// explicit parameter types
let _ = foo as fn(u32, u32) == f;
}
fn foo(param: u32, param2: u32) {
println!("{} {}", param, param2);
} But then fn main() {
let f = foo;
// error: binary operation `==` cannot be applied to type `fn(&u32, u32)` [E0369]
let _ = foo as fn(&u32, u32) == f;
// Compiles
let _ = foo as fn(_, u32) == f;
}
fn foo(param: &u32, param2: u32) {
println!("{} {}", *param, param2);
} So it seems that the number of parameters and whether or not they're references changes whether the compiler accepts the comparison or not |
Ah good point @petrochenkov, it seems the behaviour changed, I was testing with It still leaves the problem of non-commutative comparisons and the error in my 2nd post still happens on the playpen. |
I've edited the original comment to use |
It's a known bug, it affects function pointers with references in arguments.
It's a problem, but it's not a problem specific to function pointers, traits for binary operators like |
Fair enough. Should I close this issue as a duplicate of #24000 then? |
Closing as a duplicate. |
Long story short:
I don't understand why the compiler is so picky about comparing function pointers, in particular I don't understand why it accepts the cast
as fn(_)
but notas fn(u32)
. And even when it works it's not commutative, which for the==
operator is rather unexpected.The text was updated successfully, but these errors were encountered: