-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
static TEST : [i32; _] = [1i32, 2i32];
fn main() {}
The current output is:
error[E0658]: destructuring assignments are unstable
--> src/main.rs:1:21
|
1 | static TEST : [i32; _] = [1i32, 2i32];
| ^
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
Ideally the output should look like:
error[E0747]: type provided when a constant was expected
--> src/main.rs:3:16
|
1 | static TEST : [i32; _] = [1i32, 2i32];
| ^
|
= help: const arguments cannot yet be inferred with `_`
The sample code doesn't seem to be related to the destructuring assignment
feature nonetheless.
This, although quite artificial looking, use case too causes the wrong looking output
fn test() -> [i32; _] { [2, 1] }
fn main() {}
Output:
error[E0658]: destructuring assignments are unstable
--> src/main.rs:3:20
|
3 | fn test() -> [i32; _] { [2, 1] }
| ^
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
error: in expressions, `_` can only be used on the left-hand side of an assignment
--> src/main.rs:3:20
|
3 | fn test() -> [i32; _] { [2, 1] }
| ^ `_` not allowed here
Some code seems to print correct the error messages (kinda?):
struct T<const U : usize>([i32; U]);
fn test() -> T<_> { T([2, 1]) }
fn main() {}
Output
error[E0747]: type provided when a constant was expected
--> src/main.rs:3:16
|
3 | fn test() -> T<_> { T([2, 1]) }
| ^
|
= help: const arguments cannot yet be inferred with `_`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> src/main.rs:3:16
|
3 | fn test() -> T<_> { T([2, 1]) }
| ^ not allowed in type signatures
Meta
This happens on stable, beta and nightly.
fmease
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.