Skip to content

Wrong error message when omitting braces from closure with return type which returns tuple #138748

Closed
@schuelermine

Description

@schuelermine

Code

fn main() {
    let f: Box<dyn Fn() -> (i32, i32)> = Box::new(|| -> (i32, i32) (1, 2));
}

Current output

error: this is a block expression, not an array
 --> src/main.rs:2:68
  |
2 |     let f: Box<dyn Fn() -> (i32, i32)> = Box::new(|| -> (i32, i32) (1, 2));
  |                                                                    ^^^^^
  |
help: to make an array, use square brackets instead of curly braces
  |
2 -     let f: Box<dyn Fn() -> (i32, i32)> = Box::new(|| -> (i32, i32) (1, 2));
2 +     let f: Box<dyn Fn() -> (i32, i32)> = Box::new(|| -> (i32, i32) [1, ]));
  |

error: expected one of `.`, `;`, `?`, `else`, or an operator, found `)`
 --> src/main.rs:2:74
  |
2 |     let f: Box<dyn Fn() -> (i32, i32)> = Box::new(|| -> (i32, i32) (1, 2));
  |                                                                          ^ expected one of `.`, `;`, `?`, `else`, or an operator

Desired output

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.87.0-nightly (1aeb99d24 2025-03-19)
binary: rustc
commit-hash: 1aeb99d248e1b0069110cb03c6f1dcc7b36fd7f3
commit-date: 2025-03-19
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Anything else?

No response

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions