Skip to content

Confusing error when forgetting a semicolon before an array #99658

Closed
@dullbananas

Description

@dullbananas

playground

Given the following code:

fn bar() -> [u8; 2] {
    foo() // missing semicolon
    [1, 2]
}

The current output is:

error: expected one of `.`, `?`, `]`, or an operator, found `,
 --> src/lib.rs:6:7
  |
6 |     [1, 2]
  |       ^ expected one of `.`, `?`, `]`, or an operator

This is very confusing unless you notice the missing semicolon. The error message should mention that foo()[1, 2] is interpreted as an indexing expression, with something like "error when parsing index expression".

Metadata

Metadata

Assignees

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