extract is_certainly_not_a_block

This commit is contained in:
Mazdak Farrokhzad 2019-12-04 04:31:44 +01:00
parent 66b8ae4bce
commit f6e2bdc341

View File

@ -1721,14 +1721,7 @@ impl<'a> Parser<'a> {
))
}
fn maybe_parse_struct_expr(
&mut self,
lo: Span,
path: &ast::Path,
attrs: &AttrVec,
) -> Option<PResult<'a, P<Expr>>> {
let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL);
let certainly_not_a_block = || {
fn is_certainly_not_a_block(&self) -> bool {
self.look_ahead(1, |t| t.is_ident())
&& (
// `{ ident, ` cannot start a block.
@ -1741,9 +1734,16 @@ impl<'a> Parser<'a> {
self.look_ahead(3, |t| !t.can_begin_type())
)
)
};
}
if struct_allowed || certainly_not_a_block() {
fn maybe_parse_struct_expr(
&mut self,
lo: Span,
path: &ast::Path,
attrs: &AttrVec,
) -> Option<PResult<'a, P<Expr>>> {
let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL);
if struct_allowed || self.is_certainly_not_a_block() {
// This is a struct literal, but we don't can't accept them here.
let expr = self.parse_struct_expr(lo, path.clone(), attrs.clone());
if let (Ok(expr), false) = (&expr, struct_allowed) {