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

Unhelpful "not a function" error when missing a semicolon #51055

Closed
HMPerson1 opened this issue May 25, 2018 · 1 comment · Fixed by #55862
Closed

Unhelpful "not a function" error when missing a semicolon #51055

HMPerson1 opened this issue May 25, 2018 · 1 comment · Fixed by #55862
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@HMPerson1
Copy link
Contributor

This code (playground):

fn foo() {}
fn bar() -> (i32, i32) {
    foo() // missing semicolon
    
    (0, 0)
}

gives the unhelpful error message:

error[E0618]: expected function, found `()`
 --> src/main.rs:3:5
  |
3 | /     foo() // missing semicolon
4 | |     
5 | |     (0, 0)
  | |__________^ not a function

Happens on 1.26.0-stable and 1.28.0-nightly (2018-05-23 29ffe51).

@sfackler sfackler added the A-diagnostics Area: Messages for errors, warnings, and lints label May 25, 2018
@zackmdavis
Copy link
Member

(need to sleep now, but I'll put up a pull request for this tomorrow)

zmd@ReflectiveCoherence:~/Code/Misc$ rustc +stage1 scratch.rs 
error[E0618]: expected function, found `()`
 --> scratch.rs:3:5
  |
3 |       foo() // missing semicolon
  |       ^    - help: try adding a semicolon: `;`
  |  _____|
  | |
4 | |
5 | |         (0, 0)
  | |______________^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0618`.

@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2018
zackmdavis added a commit to zackmdavis/rust that referenced this issue Nov 11, 2018
Now the main span focuses on the erroneous not-a-function callee,
while showing the entire call expression is relegated to a secondary
span. In the case where the erroneous callee is itself a call, we
point out the definition, and, if the call expression spans multiple
lines, tentatively suggest a semicolon (because we suspect that the
"outer" call is actually supposed to be a tuple).

The new `bug!` assertion is, in fact, safe (`confirm_builtin_call` is
only called by `check_call`, which is only called with a first arg of
kind `ExprKind::Call` in `check_expr_kind`).

Resolves rust-lang#51055.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Nov 18, 2018
…you_call_them, r=estebank

in which the E0618 "expected function" diagnostic gets a makeover

A woman of wisdom once told me, "Better late than never." (Can't reopen the previously-closed pull request from six months ago [due to GitHub limitations](rust-lang#51098 (comment)).)

Now the main span focuses on the erroneous not-a-function callee, while showing the entire call expression is relegated to a secondary span. In the case where the erroneous callee is itself a call, we
point out the definition, and, if the call expression spans multiple lines, tentatively suggest a semicolon (because we suspect that the "outer" call is actually supposed to be a tuple).

![not_a_fn_1](https://user-images.githubusercontent.com/1076988/48309935-96755000-e538-11e8-9390-02a048abb0c2.png)

![not_a_fn_2](https://user-images.githubusercontent.com/1076988/48309936-98d7aa00-e538-11e8-8b9b-257bc77d6261.png)

The new `bug!` assertion is, in fact, safe (`confirm_builtin_call` is only called by `check_call`, which is only called with a first arg of kind `ExprKind::Call` in `check_expr_kind`).

Resolves rust-lang#51055.

r? @estebank
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants