diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-04 04:31:44 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-23 13:41:55 +0100 |
| commit | f6e2bdc341a5f25da3f29b5f37150fd320e90e8c (patch) | |
| tree | 0fc63293d5aa2d323117a3bf1beeca22b0a15bbe /src/librustc_parse/parser/expr.rs | |
| parent | 66b8ae4bce061907bb1fdb88ba6f0a9ad918c378 (diff) | |
| download | rust-f6e2bdc341a5f25da3f29b5f37150fd320e90e8c.tar.gz rust-f6e2bdc341a5f25da3f29b5f37150fd320e90e8c.zip | |
extract is_certainly_not_a_block
Diffstat (limited to 'src/librustc_parse/parser/expr.rs')
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 10912c84efc..5a44b5edc53 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -1721,6 +1721,21 @@ impl<'a> Parser<'a> { )) } + fn is_certainly_not_a_block(&self) -> bool { + self.look_ahead(1, |t| t.is_ident()) + && ( + // `{ ident, ` cannot start a block. + self.look_ahead(2, |t| t == &token::Comma) + || self.look_ahead(2, |t| t == &token::Colon) + && ( + // `{ ident: token, ` cannot start a block. + self.look_ahead(4, |t| t == &token::Comma) || + // `{ ident: ` cannot start a block unless it's a type ascription `ident: Type`. + self.look_ahead(3, |t| !t.can_begin_type()) + ) + ) + } + fn maybe_parse_struct_expr( &mut self, lo: Span, @@ -1728,22 +1743,7 @@ impl<'a> Parser<'a> { attrs: &AttrVec, ) -> Option<PResult<'a, P<Expr>>> { let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL); - let certainly_not_a_block = || { - self.look_ahead(1, |t| t.is_ident()) - && ( - // `{ ident, ` cannot start a block. - self.look_ahead(2, |t| t == &token::Comma) - || self.look_ahead(2, |t| t == &token::Colon) - && ( - // `{ ident: token, ` cannot start a block. - self.look_ahead(4, |t| t == &token::Comma) || - // `{ ident: ` cannot start a block unless it's a type ascription `ident: Type`. - self.look_ahead(3, |t| !t.can_begin_type()) - ) - ) - }; - - if struct_allowed || certainly_not_a_block() { + 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) { |
