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

error message when creating a closure and directly calling not very clear #55851

Closed
gnzlbg opened this issue Nov 10, 2018 · 1 comment
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Nov 10, 2018

Creating a closure and directly calling it:

fn main() { let _ = ||{}(); }

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0618]: expected function, found `()`
 --> src/main.rs:1:23
  |
1 | fn main() { let _ = ||{}(); }
  |                       ^^^^ not a function

error: aborting due to previous error
For more information about this error, try `rustc --explain E0618`.

Which doesn't really hint at what the problem is. The problem is that the closure must be surrounded by () - playground:

fn main() { let _ = (||{})(); }
@varkor varkor added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 10, 2018
@estebank
Copy link
Contributor

estebank commented Dec 6, 2018

To make matters more fun, the following is valid rust code:

fn main() { let _ = ||{||{}}(); }

It'll be hard to deal with this as it's the parser creating a certain AST that the type checker then chokes on without enough context. We might be able to special case this, but would only feel comfortable if it were a very small amount of code to deal with it.

Centril added a commit to Centril/rust that referenced this issue Mar 10, 2019
…twco

When encountetring `||{}()`, suggest the likely intended `(||{})()`

Fix rust-lang#55851.
Centril added a commit to Centril/rust that referenced this issue Mar 10, 2019
…twco

When encountetring `||{}()`, suggest the likely intended `(||{})()`

Fix rust-lang#55851.
Centril added a commit to Centril/rust that referenced this issue Mar 10, 2019
…twco

When encountetring `||{}()`, suggest the likely intended `(||{})()`

Fix rust-lang#55851.
Centril added a commit to Centril/rust that referenced this issue Mar 11, 2019
…twco

When encountetring `||{}()`, suggest the likely intended `(||{})()`

Fix rust-lang#55851.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Mar 13, 2019
…twco

When encountetring `||{}()`, suggest the likely intended `(||{})()`

Fix rust-lang#55851.
Centril added a commit to Centril/rust that referenced this issue Mar 16, 2019
…twco

When encountetring `||{}()`, suggest the likely intended `(||{})()`

Fix rust-lang#55851.
bors added a commit that referenced this issue Mar 22, 2019
When encountering `||{}()`, suggest the likely intended `(||{})()`

Fix #55851.
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
Projects
None yet
Development

No branches or pull requests

3 participants