diff options
| author | lukaslueg <lukas.lueg@gmail.com> | 2021-04-06 18:23:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-06 18:23:21 +0200 |
| commit | 72796a7c36d60cd5d32e181dd0fca924399c2a03 (patch) | |
| tree | 157b3a3527632082291a2c17b39d22ab5395cfe1 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 7f32fda78c60bb5b05e610a1c0c0fecaff07f497 (diff) | |
| parent | 5c897d430dcbec6b10a9925f7de054dbc0ad3c52 (diff) | |
| download | rust-72796a7c36d60cd5d32e181dd0fca924399c2a03.tar.gz rust-72796a7c36d60cd5d32e181dd0fca924399c2a03.zip | |
Merge branch 'master' into stab_peek_mut
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index d64e5173b92..fe190bfe9d9 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -92,6 +92,21 @@ impl<'a> Parser<'a> { self.parse_expr_res(Restrictions::empty(), None) } + /// Parses an expression, forcing tokens to be collected + pub fn parse_expr_force_collect(&mut self) -> PResult<'a, P<Expr>> { + // If we have outer attributes, then the call to `collect_tokens_trailing_token` + // will be made for us. + if matches!(self.token.kind, TokenKind::Pound | TokenKind::DocComment(..)) { + self.parse_expr() + } else { + // If we don't have outer attributes, then we need to ensure + // that collection happens by using `collect_tokens_no_attrs`. + // Expression don't support custom inner attributes, so `parse_expr` + // will never try to collect tokens if we don't have outer attributes. + self.collect_tokens_no_attrs(|this| this.parse_expr()) + } + } + pub(super) fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> { self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value }) } |
