Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Kampfkarren opened this issue Aug 12, 2022 · 1 comment · Fixed by #100590
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kampfkarren
Copy link
Contributor

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].

@Kampfkarren Kampfkarren added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 12, 2022
@WaffleLapkin
Copy link
Member

This can use diagnostic stashing in ast lowering, so that later, in type check, when we can infer the infer constant we can provide a better diagnostic. I haven't found where in type check to do this yet :')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants