Skip to content

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

Closed
@gnzlbg

Description

@gnzlbg

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 _ = (||{})(); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions