Skip to content

Better Diagnostics When Using Wrong Brackets to Create an Array #87672

Closed
@Hpmason

Description

@Hpmason

I ended up spending way too much time debugging the following error, since I was trying to port some C code to rust.

const ARR: [u8; 3] = {
    1, 2, 3
}

Give the error:

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

error: aborting due to previous error

error: could not compile `playground`

The error message is very vague and hard to determine the actual error here.
Seeing as though some programming languages like Java and C use {} for arrays, I think it'd make sense for the compiler to suggest using [] if the user is trying to create an array.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jul 31, 2021
hkmatsumoto

hkmatsumoto commented on Aug 5, 2021

@hkmatsumoto
Member

I suppose adding manual diagnostic somewhere around rustc_parse::parse::parse_block_expr will get the job done.
@rustbot claim

added a commit that references this issue on Sep 21, 2021

Auto merge of rust-lang#87830 - hkmatsumoto:suggest-brackets-for-arra…

e7958d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-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

    Participants

    @Hpmason@inquisitivecrystal@hkmatsumoto

    Issue actions

      Better Diagnostics When Using Wrong Brackets to Create an Array · Issue #87672 · rust-lang/rust