-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Description
Long story short:
fn main() {
let f = foo;
// error: binary operation `==` cannot be applied to type `fn(u32) {foo}` [E0369]
let _ = f == foo;
// error: binary operation `==` cannot be applied to type `fn(u32) {foo}` [E0369]
let _ = foo == f;
// error: binary operation `==` cannot be applied to type `fn(u32) {foo}` [E0369]
let _ = foo as fn(&u32) == f;
// Compiles, even though as far as I can tell it should be
// equivalent to the previous one
let _ = foo as fn(_) == f;
// error: binary operation `==` cannot be applied to type `fn(u32) {foo}` [E0369]
let _ = f == foo as fn(_);
}
fn foo(param: &u32) {
println!("{}", param);
}
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 not as fn(u32)
. And even when it works it's not commutative, which for the ==
operator is rather unexpected.
Metadata
Metadata
Assignees
Labels
No labels