Skip to content

"using _ for array lengths is unstable" error should suggest the number of elements #100448

Closed
@Kampfkarren

Description

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fe35b2f5f585f0303661ac61e880d1fe

const NUMBERS: [i32; _] = [
    1, 2, 3
];

The current output is:

error[[E0658]](https://doc.rust-lang.org/stable/error-index.html#E0658): using `_` for array lengths is unstable
 --> src/lib.rs:1:22
  |
1 | const NUMBERS: [i32; _] = [
  |                      ^
  |
  = note: [see issue #85077 <https://github.com/rust-lang/rust/issues/85077>](https://github.com/rust-lang/rust/issues/85077) for more information

error: in expressions, `_` can only be used on the left-hand side of an assignment
 --> src/lib.rs:1:22
  |
1 | const NUMBERS: [i32; _] = [
  |                      ^ `_` not allowed here

For more information about this error, try `rustc --explain E0658`.
error: could not compile `playground` due to 2 previous errors

Ideally, the output should suggest that this should be [i32; 3].

Activity

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

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