Skip to content

Commit f6e2bdc

Browse files
committed
extract is_certainly_not_a_block
1 parent 66b8ae4 commit f6e2bdc

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/librustc_parse/parser/expr.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,29 +1721,29 @@ impl<'a> Parser<'a> {
17211721
))
17221722
}
17231723

1724+
fn is_certainly_not_a_block(&self) -> bool {
1725+
self.look_ahead(1, |t| t.is_ident())
1726+
&& (
1727+
// `{ ident, ` cannot start a block.
1728+
self.look_ahead(2, |t| t == &token::Comma)
1729+
|| self.look_ahead(2, |t| t == &token::Colon)
1730+
&& (
1731+
// `{ ident: token, ` cannot start a block.
1732+
self.look_ahead(4, |t| t == &token::Comma) ||
1733+
// `{ ident: ` cannot start a block unless it's a type ascription `ident: Type`.
1734+
self.look_ahead(3, |t| !t.can_begin_type())
1735+
)
1736+
)
1737+
}
1738+
17241739
fn maybe_parse_struct_expr(
17251740
&mut self,
17261741
lo: Span,
17271742
path: &ast::Path,
17281743
attrs: &AttrVec,
17291744
) -> Option<PResult<'a, P<Expr>>> {
17301745
let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL);
1731-
let certainly_not_a_block = || {
1732-
self.look_ahead(1, |t| t.is_ident())
1733-
&& (
1734-
// `{ ident, ` cannot start a block.
1735-
self.look_ahead(2, |t| t == &token::Comma)
1736-
|| self.look_ahead(2, |t| t == &token::Colon)
1737-
&& (
1738-
// `{ ident: token, ` cannot start a block.
1739-
self.look_ahead(4, |t| t == &token::Comma) ||
1740-
// `{ ident: ` cannot start a block unless it's a type ascription `ident: Type`.
1741-
self.look_ahead(3, |t| !t.can_begin_type())
1742-
)
1743-
)
1744-
};
1745-
1746-
if struct_allowed || certainly_not_a_block() {
1746+
if struct_allowed || self.is_certainly_not_a_block() {
17471747
// This is a struct literal, but we don't can't accept them here.
17481748
let expr = self.parse_struct_expr(lo, path.clone(), attrs.clone());
17491749
if let (Ok(expr), false) = (&expr, struct_allowed) {

0 commit comments

Comments
 (0)