Skip to content
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

Improvement for comparision against fn #59488

Closed
tumdum opened this issue Mar 28, 2019 · 4 comments
Closed

Improvement for comparision against fn #59488

tumdum opened this issue Mar 28, 2019 · 4 comments
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`

Comments

@tumdum
Copy link

tumdum commented Mar 28, 2019

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 ‘()’ ?").

@estebank estebank added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Mar 28, 2019
@rchaser53
Copy link
Contributor

rchaser53 commented Apr 7, 2019

I'd like to work on this.
Add the sentence "did you forget the ‘()’ ?" like below.
If is it ok, I will send the PR.

error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
  --> $DIR/issue-59488.rs:6:9
   |
LL |     foo > 12;
   |     --- ^ -- {integer}
   |     |
   |     fn() -> i32 {foo}
   |     did you forget `()`?
   |
   = note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`

bors added a commit that referenced this issue Apr 14, 2019
Improvement for comparision against fn

I try to add error message.
related: #59488
@JohnTitor
Copy link
Member

Is this fixed in #59798?

@rchaser53
Copy link
Contributor

Yes. #59798 happens degraded. but it will be resolved in #60073

@davidtwco
Copy link
Member

Closing, suggestion is implemented on nightly:

error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
 --> src/main.rs:6:9
  |
6 |     foo > 12;
  |     --- ^ -- {integer}
  |     |
  |     fn() -> i32 {foo}
  |     help: you might have forgotten to call this function: `foo()`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`
Projects
None yet
Development

No branches or pull requests

5 participants