1
Fork 0

Refactor out parse_struct_expr.

This commit is contained in:
Jeffrey Seyfried 2016-09-22 04:45:29 +00:00
parent 1cf592fa40
commit dc7ed303f7

View file

@ -2333,7 +2333,34 @@ impl<'a> Parser<'a> {
Restrictions::RESTRICTION_NO_STRUCT_LITERAL
);
if !prohibited {
// It's a struct literal.
return self.parse_struct_expr(lo, pth, attrs);
}
}
hi = pth.span.hi;
ex = ExprKind::Path(None, pth);
} else {
match self.parse_lit() {
Ok(lit) => {
hi = lit.span.hi;
ex = ExprKind::Lit(P(lit));
}
Err(mut err) => {
self.cancel(&mut err);
let msg = format!("expected expression, found {}",
self.this_token_descr());
return Err(self.fatal(&msg));
}
}
}
}
}
return Ok(self.mk_expr(lo, hi, ex, attrs));
}
fn parse_struct_expr(&mut self, lo: BytePos, pth: ast::Path, mut attrs: ThinVec<Attribute>)
-> PResult<'a, P<Expr>> {
self.bump();
let mut fields = Vec::new();
let mut base = None;
@ -2374,33 +2401,9 @@ impl<'a> Parser<'a> {
}
}
hi = self.span.hi;
let hi = self.span.hi;
self.expect(&token::CloseDelim(token::Brace))?;
ex = ExprKind::Struct(pth, fields, base);
return Ok(self.mk_expr(lo, hi, ex, attrs));
}
}
hi = pth.span.hi;
ex = ExprKind::Path(None, pth);
} else {
match self.parse_lit() {
Ok(lit) => {
hi = lit.span.hi;
ex = ExprKind::Lit(P(lit));
}
Err(mut err) => {
self.cancel(&mut err);
let msg = format!("expected expression, found {}",
self.this_token_descr());
return Err(self.fatal(&msg));
}
}
}
}
}
return Ok(self.mk_expr(lo, hi, ex, attrs));
return Ok(self.mk_expr(lo, hi, ExprKind::Struct(pth, fields, base), attrs));
}
fn parse_or_use_outer_attributes(&mut self,