fn main() {
let mut a;
struct S;
(S, a) = (S, ()); // Error
(S {}, a) = (S, ()); // Works
enum E { A }
(E::A, a) = (E::A, ()); // Error
(E::A {}, a) = (E::A, ()); // Works
}
error[E0070]: invalid left-hand side of assignment
--> src/main.rs:4:12
|
4 | (S, a) = (S, ()); // Error
| - ^
| |
| cannot assign to this expression
error[E0070]: invalid left-hand side of assignment
--> src/main.rs:7:15
|
7 | (E::A, a) = (E::A, ()); // Error
| ---- ^
| |
| cannot assign to this expression
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=bf807e599b504f489454388eb27acbbb
The RFC states explicitly we should support them:
https://github.com/rust-lang/rfcs/blob/master/text/2909-destructuring-assignment.md#reference-level-explanation
The class of assignee expressions is defined inductively:
- Place:
place.
- Underscore:
_.
- Tuples:
(assignee, assignee, assignee), (assignee, .., assignee), (.., assignee, assignee), (assignee, assignee, ..).
- Slices:
[assignee, assignee, assignee], [assignee, .., assignee], [.., assignee, assignee], [assignee, assignee, ..].
- Tuple structs:
path(assignee, assignee, assignee), path(assignee, .., assignee), path(.., assignee, assignee), path(assignee, assignee, ..).
- Structs:
path { field: assignee, field: assignee }, path { field: assignee, field: assignee, .. }.
- Unit structs:
path.
@rustbot label: +F-destructuring_assignment
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=bf807e599b504f489454388eb27acbbb
The RFC states explicitly we should support them:
https://github.com/rust-lang/rfcs/blob/master/text/2909-destructuring-assignment.md#reference-level-explanation
@rustbot label: +F-destructuring_assignment