Refactor out parse_struct_expr
.
This commit is contained in:
parent
1cf592fa40
commit
dc7ed303f7
1 changed files with 48 additions and 45 deletions
|
@ -2333,7 +2333,34 @@ impl<'a> Parser<'a> {
|
||||||
Restrictions::RESTRICTION_NO_STRUCT_LITERAL
|
Restrictions::RESTRICTION_NO_STRUCT_LITERAL
|
||||||
);
|
);
|
||||||
if !prohibited {
|
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();
|
self.bump();
|
||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
let mut base = None;
|
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))?;
|
self.expect(&token::CloseDelim(token::Brace))?;
|
||||||
ex = ExprKind::Struct(pth, fields, base);
|
return Ok(self.mk_expr(lo, hi, ExprKind::Struct(pth, fields, base), attrs));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_or_use_outer_attributes(&mut self,
|
fn parse_or_use_outer_attributes(&mut self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue