Arrays are cool and all because they enable optimizations when size is known...
But you can't let the compiler infer the size anywhere. While that arguably makes sense in consts and statics, you can't even do it when using let - while with types it works fine!
What's the point of making let x: [(); _] = []; an error?! And a confusing one at that, too...
So it hasn't always been that bad. Doing a quick bisection on released versions of the compile. The error message on <=1.49 is:
error: expected expression, found reserved identifier `_`
--> <source>:2:17
|
2 | let x: [(); _] = [];
| - ^ expected expression
| |
| while parsing the type for `x`
While on versions >=1.50 the error is:
error[E0658]: destructuring assignments are unstable
--> <source>:2:17
|
2 | let x: [(); _] = [];
| ^
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
error: in expressions, `_` can only be used on the left-hand side of an assignment
--> <source>:2:17
|
2 | let x: [(); _] = [];
| ^ `_` not allowed here
So as you can see, this is mostly a regression on the error messages side. This probably (I don't know, haven't checked nor know where to check) is something to do with Const-Generics and might already be planned.
error[E0658]: destructuring assignments are unstable
--> src/main.rs:2:5
|
2 | _;
| ^
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
error: in expressions, `_` can only be used on the left-hand side of an assignment
--> src/main.rs:2:5
|
2 | _;
| ^ `_` not allowed here
It should also be noted that _ is used to infer types while [(); /* is a const */] which can't (yet) be inferred.
error[E0747]: type provided when a constant was expected
--> src/main.rs:5:11
|
5 | foo::<_>([(); 3]);
| ^
|
= help: const arguments cannot yet be inferred with `_`