Skip to content

Compiler fails to report len for static A: [T; _] #135010

Closed
@workingjubilee

Description

@workingjubilee

Code

static A: [u8; _] = [12, 23, 34, 45];

Current output

Compiling playground v0.0.1 (/playground)
error: in expressions, `_` can only be used on the left-hand side of an assignment
 --> src/lib.rs:1:16
  |
1 | static A: [u8; _] = [12, 23, 34, 45];
  |                ^ `_` not allowed here

error[E0658]: using `_` for array lengths is unstable
 --> src/lib.rs:1:16
  |
1 | static A: [u8; _] = [12, 23, 34, 45];
  |                ^
  |
  = note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information

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

Desired output

Compiling playground v0.0.1 (/playground)
error: `_` is not a valid array length for a static item
 --> src/lib.rs:1:16
  |
1 | static A: [u8; _] = [12, 23, 34, 45];
  |                ^ `_` not allowed here
  |
  = help: you meant 4

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

Rationale and extra context

rationale: @BoxyUwU expected it to do so.

Other cases

We can also get this:

  = note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
  = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
  = note: this compiler was built on 2025-01-01; consider upgrading it if it is out of date

Rust Version

$ rustc --version --verbose
rustc 1.85.0-nightly (45d11e51b 2025-01-01)
binary: rustc
commit-hash: 45d11e51bb66c2deb63a006fe3953c4b6fbc50c2
commit-date: 2025-01-01
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6

Anything else?

No response

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsF-generic_arg_inferUsing `_` as a const argument: #![feature(generic_arg_infer)]`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

Development

No branches or pull requests

Issue actions