-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code: link
fn main() {
println!("{}", || 123 ());
}The current output is:
Compiling playground v0.0.1 (/playground)
error[[E0618]](https://doc.rust-lang.org/nightly/error-index.html#E0618): expected function, found `{integer}`
--> src/main.rs:2:23
|
2 | println!("{}", || 123 ());
| ^^^---
| |
| call expression requires function
For more information about this error, try `rustc --explain E0618`.
error: could not compile `playground` due to previous error
Ideally the output should suggest adding parentheses around the closure before calling it, since that suggestion is already present if the return value of the closure is wrapped in braces, as shown below.
fn main() {
println!("{}", || { 123 } ());
}Output with help suggestion:
Compiling playground v0.0.1 (/playground)
error[[E0618]](https://doc.rust-lang.org/nightly/error-index.html#E0618): expected function, found `{integer}`
--> src/main.rs:2:23
|
2 | println!("{}", || { 123 } ());
| ^^^^^^^---
| |
| call expression requires function
|
help: if you meant to create this closure and immediately call it, surround the closure with parentheses
|
2 | println!("{}", (|| { 123 }) ());
| + +
For more information about this error, try `rustc --explain E0618`.
error: could not compile `playground` due to previous error
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.