You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0658]: destructuring assignments are unstable
--> src/main.rs:2:17
|
2 | let foo:[u8; _] = [1,2,3];
| ^
|
= 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:2:17
|
2 | let foo:[u8; _] = [1,2,3];
| ^ `_` not allowed here
For more information about this error, try `rustc --explain E0658`.
However the #![feature(destructuring_assignment)] seems to be completely irrelevant here, and indeed adding that (playground)
error:in expressions, `_` can only be used on the left-hand side of an assignment
--> src/main.rs:3:17
|
3 | let foo:[u8; _] = [1,2,3];
| ^ `_` not allowed here
(Tangentially: technically the error message is wrong since _is used in the left hand side of an assignment. Just not as the variable name as rustc expected... )
ah, wait, reading closer , #71126 (comment) implies that this behavior is expected, even if maybe unfortunate. I'll leave this bug report open for now, but feel free to close as WAI if that is the correct reading.
The behaviour is correct, but a little confusingly-worded. By "left-hand side of an assignment", it means the variable being assigned to, rather than any syntax to the left of =. If you can think of better wording that makes this clearer, it would be good to clear this up!
We have to be careful to use terminology most users will understand, and I think "place expression" is jargon that not a lot of users will be familiar with.
@varkor I understand this but it's hard to be both precise and straightforward... Let me try again:
error: in expressions, _ can only be used in the left-hand side expression being assigned to
Another possible version, but I'm not sure if this breaks the original meaning or not:
error: _ can be a part of an expression only when the expression is being assigned to
As a user, I think the predicate "in expressions" confuses me, since I'm using _ in a type signature, but rustc is telling me something about expressions.
PS: I believe this problem is temporary. I guess once the array size can be omitted, this error will be always talking about the variable being assigned to (or does it?)
Sorry to be using this issue's comments section to ask this, but wasn't this the syntax used to ask the compiler to figure out the size of the array foo, being free from having to change that value in code whenever the assigned-from array literal changed?
In other words, I thought this was legal code:
fnmain(){let foo:[u8; _] = [1,2,3];}
I'm very confused... How am I supposed to write that, then?
@araruna This error message is hopefully a temporary state and will probably be fixed with rust-lang/rfcs#2545.
However, we still have to do something about the error message to better the user experience in this period.
Activity
moxian commentedon Oct 20, 2021
ah, wait, reading closer , #71126 (comment) implies that this behavior is expected, even if maybe unfortunate. I'll leave this bug report open for now, but feel free to close as WAI if that is the correct reading.
rami3l commentedon Oct 21, 2021
Encountered a similar case today, and this seems related to rust-lang/rfcs#2545.
varkor commentedon Oct 29, 2021
The behaviour is correct, but a little confusingly-worded. By "left-hand side of an assignment", it means the variable being assigned to, rather than any syntax to the left of
=. If you can think of better wording that makes this clearer, it would be good to clear this up!rami3l commentedon Oct 29, 2021
@varkor According to the Reference:
... maybe here it's better to say:
varkor commentedon Oct 29, 2021
We have to be careful to use terminology most users will understand, and I think "place expression" is jargon that not a lot of users will be familiar with.
rami3l commentedon Oct 30, 2021
@varkor I understand this but it's hard to be both precise and straightforward... Let me try again:
Another possible version, but I'm not sure if this breaks the original meaning or not:
As a user, I think the predicate "in expressions" confuses me, since I'm using
_in a type signature, but rustc is telling me something about expressions.PS: I believe this problem is temporary. I guess once the array size can be omitted, this error will be always talking about the variable being assigned to (or does it?)
araruna commentedon Nov 7, 2021
Sorry to be using this issue's comments section to ask this, but wasn't this the syntax used to ask the compiler to figure out the size of the array
foo, being free from having to change that value in code whenever the assigned-from array literal changed?In other words, I thought this was legal code:
I'm very confused... How am I supposed to write that, then?
rami3l commentedon Nov 7, 2021
@araruna This error message is hopefully a temporary state and will probably be fixed with rust-lang/rfcs#2545.
However, we still have to do something about the error message to better the user experience in this period.
cyrgani commentedon Apr 16, 2026
This code now compiles since #141610.