Closed
Description
Given the following code:
fn main() {
let num = 5;
(1..num).reduce(|a, b|
println!("{}", a); // <== Here
a * b
).unwrap();
}
The current output is:
Compiling playground v0.0.1 (/playground)
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> src/main.rs:4:26
|
4 | println!("{}", a); // <== Here
| ^
| |
| expected one of `)`, `,`, `.`, `?`, or an operator
| help: missing `,`
error[E0425]: cannot find value `a` in this scope
--> src/main.rs:5:9
|
5 | a * b
| ^ not found in this scope
error[E0425]: cannot find value `b` in this scope
--> src/main.rs:5:13
|
5 | a * b
| ^ not found in this scope
error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> src/main.rs:3:14
|
3 | (1..num).reduce(|a, b|
| ______________^^^^^^_-
| | |
| | expected 1 argument
4 | | println!("{}", a); // <== Here
| |_________________________-
5 | a * b
| ----- supplied 2 arguments
|
note: associated function defined here
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0061, E0425.
For more information about an error, try `rustc --explain E0061`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Ideally the output should look like:
3 | (1..num).reduce(|a, b| {
| ____________________________^
| | Multi-line closure requires scope brackets
I was trying to debug an iterator and added a println!
call. To my surprise, it caused the compiler to fail and emit MANY warnings. None of them pointed at the real problem which is that I was missing curly brackets {}
.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: The lexing & parsing of Rust source code to an ASTCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.