diff options
| author | bors <bors@rust-lang.org> | 2021-01-15 05:36:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-15 05:36:48 +0000 |
| commit | dcf622eb70aebe16d40c5f88fa2a41fa7019541c (patch) | |
| tree | 0dc48e3ed0ac3cb88d7b86224b2248ae40b9add4 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 3419da89aaaa678f680032fef9764e875aa06026 (diff) | |
| parent | a961e6785c7ed33a532bb6172ae0c95f44db5726 (diff) | |
| download | rust-dcf622eb70aebe16d40c5f88fa2a41fa7019541c.tar.gz rust-dcf622eb70aebe16d40c5f88fa2a41fa7019541c.zip | |
Auto merge of #80993 - Aaron1011:collect-set-tokens, r=petrochenkov
Set tokens on AST node in `collect_tokens` A new `HasTokens` trait is introduced, which is used to move logic from the callers of `collect_tokens` into the body of `collect_tokens`. In addition to reducing duplication, this paves the way for PR #80689, which needs to perform additional logic during token collection.
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index f4332e4548a..6db415ead41 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -472,7 +472,8 @@ impl<'a> Parser<'a> { /// Parses a prefix-unary-operator expr. fn parse_prefix_expr(&mut self, attrs: Option<AttrVec>) -> PResult<'a, P<Expr>> { let attrs = self.parse_or_use_outer_attributes(attrs)?; - self.maybe_collect_tokens(super::attr::maybe_needs_tokens(&attrs), |this| { + let needs_tokens = super::attr::maybe_needs_tokens(&attrs); + let do_parse = |this: &mut Parser<'a>| { let lo = this.token.span; // Note: when adding new unary operators, don't forget to adjust TokenKind::can_begin_expr() let (hi, ex) = match this.token.uninterpolate().kind { @@ -488,7 +489,8 @@ impl<'a> Parser<'a> { _ => return this.parse_dot_or_call_expr(Some(attrs)), }?; Ok(this.mk_expr(lo.to(hi), ex, attrs)) - }) + }; + if needs_tokens { self.collect_tokens(do_parse) } else { do_parse(self) } } fn parse_prefix_expr_common(&mut self, lo: Span) -> PResult<'a, (Span, P<Expr>)> { @@ -1125,20 +1127,6 @@ impl<'a> Parser<'a> { } } - fn maybe_collect_tokens( - &mut self, - needs_tokens: bool, - f: impl FnOnce(&mut Self) -> PResult<'a, P<Expr>>, - ) -> PResult<'a, P<Expr>> { - if needs_tokens { - let (mut expr, tokens) = self.collect_tokens(f)?; - expr.tokens = tokens; - Ok(expr) - } else { - f(self) - } - } - fn parse_lit_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> { let lo = self.token.span; match self.parse_opt_lit() { |
