-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
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 func() {
|| 123
}
fn main() {
println!("{}", func()())
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
--> src/main.rs:2:5
|
1 | fn func() {
| - help: a return type might be missing here: `-> _`
2 | || 123
| ^^^^^^ expected `()`, found closure
|
= note: expected unit type `()`
found closure `[closure@src/main.rs:2:5: 2:7]`
error[[E0618]](https://doc.rust-lang.org/nightly/error-index.html#E0618): expected function, found `()`
--> src/main.rs:6:20
|
1 | fn func() {
| --------- `func` defined here returns `()`
...
6 | println!("{}", func()())
| ^^^^^^--
| |
| call expression requires function
Some errors have detailed explanations: E0308, E0618.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `playground` due to 2 previous errors
Ideally the output should suggest how to specify the return type when a function returns a closure.
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.