error: closure bodies that contain statements must be surrounded by braces
--> src/lib.rs:2:17
|
2 | let value = || {};
| ^^
3 |
4 | (value;);
| ^
|
note: statement found outside of a block
--> src/lib.rs:4:11
|
2 | let value = || {};
| -- this expression is a statement because of the trailing semicolon
3 |
4 | (value;);
| ^ this `;` turns the preceding closure into a statement
note: the closure body may be incorrectly delimited
--> src/lib.rs:2:17
|
2 | let value = || {};
| ^^^^^ this is the parsed closure...
3 |
4 | (value;);
| - ...but likely you meant the closure to end here
help: try adding braces
|
2 ~ let value = || { {};
3 |
4 ~ (value;});
|
Desired output
error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `;`
--> src/lib.rs:4:11
|
4 | (value;);
| ^ expected one of 8 possible tokens
Rationale and extra context
This error is unrelated to the closure, and indeed, applying the suggestion leaves us with:
fn test() {
let value = || { {};
(value; });
}
Which now has an improperly closed brace. The correct code would (most likely) be (value)
The original code I had made the suggestion even weirder since the closure was an argument to a Higher Order Function (instead of bound to a variable) and the last line was a function call with a ; after its argument (instead of a paren expression), which happened due to a typo 😅. Just in case something following that structure would make for a useful test case as well:
fn test() {
let value = std::iter::once_with(|| ());
std::men::drop(value;);
}
Code
Current output
Desired output
Rationale and extra context
This error is unrelated to the closure, and indeed, applying the suggestion leaves us with:
Which now has an improperly closed brace. The correct code would (most likely) be
(value)
The original code I had made the suggestion even weirder since the closure was an argument to a Higher Order Function (instead of bound to a variable) and the last line was a function call with a
;
after its argument (instead of a paren expression), which happened due to a typo 😅. Just in case something following that structure would make for a useful test case as well:Other cases
No response
Rust Version
Anything else?
No response