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

Incorrect error message about enum variant when trying to call a Result #49548

Open
comex opened this issue Apr 1, 2018 · 3 comments
Open

Incorrect error message about enum variant when trying to call a Result #49548

comex opened this issue Apr 1, 2018 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@comex
Copy link
Contributor

comex commented Apr 1, 2018

Test case (playground link):

fn foo() -> Result<i32, i32> {
    Ok(42)
}

fn main() {
    foo()();
}

The real issue is an extra set of parentheses after foo(), which should produce an error because Result<i32, i32> is not a function. However, rustc (stable and current nightly) produces this error message:

error[E0618]: expected function, found enum variant `foo()`
 --> src/main.rs:6:5
  |
6 |     foo()();
  |     ^^^^^^^ not a function
help: `foo()` is a unit variant, you need to write it without the parenthesis
  |
6 |     foo();
  |     ^^^^^
  • The first line is confusing and semi-incorrect: although foo() does evaluate to a value of enum type, it's not a specific variant, and "found enum variant foo()" makes it seem like foo itself is an enum.
  • The line after help: is incorrect: neither of the variants of the Result enum is a unit variant.
  • The suggested fix is correct, which is nice :)
@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 12, 2018
@steveklabnik
Copy link
Member

Triage: no change

@estebank
Copy link
Contributor

Current output:

error[E0618]: expected function, found enum variant `foo()`
 --> src/main.rs:6:5
  |
1 | / fn foo() -> Result<i32, i32> {
2 | |     Ok(42)
3 | | }
  | |_- `foo()` defined here
...
6 |       foo()();
  |       ^^^^^--
  |       |
  |       call expression requires function
help: `foo()` is a unit variant, you need to write it without the parenthesis
  |
6 |     foo();
  |     ^^^^^

@estebank
Copy link
Contributor

estebank commented Nov 11, 2022

Current output:

error[E0618]: expected function, found `Result<i32, i32>`
 --> src/main.rs:6:5
  |
1 | fn foo() -> Result<i32, i32> {
  | ---------------------------- `foo` defined here returns `Result<i32, i32>`
...
6 |     foo()();
  |     ^^^^^--
  |     |
  |     call expression requires function

It seems like the only outstanding thing here would be to recover the previous suggestion with correct wording, but other than that I am happy with the current output.

@estebank estebank added D-papercut Diagnostics: An error or lint that needs small tweaks. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants