Skip to content

Destructuring assignment - #2909

Merged
nikomatsakis merged 29 commits into
rust-lang:masterfrom
varkor:destructuring-assignment
Oct 27, 2020
Merged

Destructuring assignment#2909
nikomatsakis merged 29 commits into
rust-lang:masterfrom
varkor:destructuring-assignment

Conversation

@varkor

@varkor varkor commented Apr 17, 2020

Copy link
Copy Markdown
Contributor

This RFC is co-authored with @fanzier.

We allow destructuring on assignment, as in let declarations. For instance, the following are now
accepted:

(a, (b.x.y, c)) = (0, (1, 2));
(x, y, .., z) = (1.0, 2.0, 3.0, 4.0, 5.0);
[_, f, *baz()] = foo();
[g, _, h, ..] = ['a', 'w', 'e', 's', 'o', 'm', 'e', '!'];
Struct { x: a, y: b } = bar();
Struct { x, y } = Struct { x: 5, y: 6 };

This brings assignment in line with let declaration, in which destructuring is permitted. This
will simplify and improve idiomatic code involving mutability.

A working prototype may be found at rust-lang/rust#71156.

Rendered.

Thanks to @joshtriplett for providing feedback on the RFC.

Closes #372.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. T-lang Relevant to the language team, which will review and decide on the RFC. to-announce

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destructuring assignment