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

feature(destructuring_assignment) suggested errorneously #90095

Open
moxian opened this issue Oct 20, 2021 · 8 comments
Open

feature(destructuring_assignment) suggested errorneously #90095

moxian opened this issue Oct 20, 2021 · 8 comments
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

@moxian
Copy link
Contributor

moxian commented Oct 20, 2021

(playground)

fn main(){
  let foo: [u8; _] = [1,2,3];
}
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)

#![feature(destructuring_assignment)]
fn main(){
  let foo: [u8; _] = [1,2,3];
}

still gives error of

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

cc #71126

@moxian moxian 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 Oct 20, 2021
@moxian
Copy link
Contributor Author

moxian commented 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
Copy link
Member

rami3l commented Oct 21, 2021

Encountered a similar case today, and this seems related to rust-lang/rfcs#2545.

@varkor
Copy link
Member

varkor commented 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
Copy link
Member

rami3l commented Oct 29, 2021

@varkor According to the Reference:

The assigned place operand must be a place expression...

... maybe here it's better to say:

error: in expressions, _ can only be used in the place expression being assigned to

@varkor
Copy link
Member

varkor commented 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
Copy link
Member

rami3l commented Oct 30, 2021

@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?)

@araruna
Copy link

araruna commented 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:

fn main(){
  let foo: [u8; _] = [1,2,3];
}

I'm very confused... How am I supposed to write that, then?

@rami3l
Copy link
Member

rami3l commented 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.

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

No branches or pull requests

4 participants