Skip to content

Improvement for comparision against fn #59488

Closed
@tumdum

Description

@tumdum
fn foo() -> i32 {
    42
}

fn main() {
    foo > 12;
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
 --> src/main.rs:6:5
  |
6 |     foo > 12;
  |     ^^^^^^^^
  |
  = note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`

error[E0308]: mismatched types
 --> src/main.rs:6:11
  |
6 |     foo > 12;
  |           ^^ expected fn item, found integer
  |
  = note: expected type `fn() -> i32 {foo}`
             found type `{integer}`

error: aborting due to 2 previous errors

A much more useful note would be to suggest to the user that a instead of comparing function she should compare result of function evaluation - rustc should suggest that user should add pair of parentheses to call a function ("did you forget the ‘()’ ?").

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions