Implement destructuring assignment for structs and slices

Co-authored-by: varkor <github@varkor.com>
This commit is contained in:
Fabian Zaiser 2020-11-07 14:28:55 +00:00
parent cf9cf7c923
commit de84ad95b4
32 changed files with 619 additions and 108 deletions

View file

@ -2087,7 +2087,7 @@ impl<'a> Parser<'a> {
recover: bool,
) -> PResult<'a, P<Expr>> {
let mut fields = Vec::new();
let mut base = None;
let mut base = ast::StructRest::None;
let mut recover_async = false;
attrs.extend(self.parse_inner_attributes()?);
@ -2102,8 +2102,14 @@ impl<'a> Parser<'a> {
while self.token != token::CloseDelim(token::Brace) {
if self.eat(&token::DotDot) {
let exp_span = self.prev_token.span;
// We permit `.. }` on the left-hand side of a destructuring assignment.
if self.check(&token::CloseDelim(token::Brace)) {
self.sess.gated_spans.gate(sym::destructuring_assignment, self.prev_token.span);
base = ast::StructRest::Rest(self.prev_token.span.shrink_to_hi());
break;
}
match self.parse_expr() {
Ok(e) => base = Some(e),
Ok(e) => base = ast::StructRest::Base(e),
Err(mut e) if recover => {
e.emit();
self.recover_stmt();