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/mod.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/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 45964b1c988..5d7ea5b8d57 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -19,8 +19,8 @@ use rustc_ast::token::{self, DelimToken, Token, TokenKind}; use rustc_ast::tokenstream::{self, DelimSpan, LazyTokenStream, Spacing}; use rustc_ast::tokenstream::{CreateTokenStream, TokenStream, TokenTree, TreeAndSpacing}; use rustc_ast::DUMMY_NODE_ID; -use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, CrateSugar, Extern, Unsafe}; -use rustc_ast::{Async, Expr, ExprKind, MacArgs, MacDelimiter, Mutability, StrLit}; +use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, CrateSugar, Extern, HasTokens}; +use rustc_ast::{Async, Expr, ExprKind, MacArgs, MacDelimiter, Mutability, StrLit, Unsafe}; use rustc_ast::{Visibility, VisibilityKind}; use rustc_ast_pretty::pprust; use rustc_data_structures::sync::Lrc; @@ -1234,10 +1234,10 @@ impl<'a> Parser<'a> { /// This restriction shouldn't be an issue in practice, /// since this function is used to record the tokens for /// a parsed AST item, which always has matching delimiters. - pub fn collect_tokens<R>( + pub fn collect_tokens<R: HasTokens>( &mut self, f: impl FnOnce(&mut Self) -> PResult<'a, R>, - ) -> PResult<'a, (R, Option<LazyTokenStream>)> { + ) -> PResult<'a, R> { let start_token = (self.token.clone(), self.token_spacing); let cursor_snapshot = TokenCursor { frame: self.token_cursor.frame.clone(), @@ -1249,7 +1249,7 @@ impl<'a> Parser<'a> { append_unglued_token: self.token_cursor.append_unglued_token.clone(), }; - let ret = f(self)?; + let mut ret = f(self)?; // Produces a `TokenStream` on-demand. Using `cursor_snapshot` // and `num_calls`, we can reconstruct the `TokenStream` seen @@ -1319,7 +1319,8 @@ impl<'a> Parser<'a> { trailing_semi: false, append_unglued_token: self.token_cursor.append_unglued_token.clone(), }; - Ok((ret, Some(LazyTokenStream::new(lazy_impl)))) + ret.finalize_tokens(LazyTokenStream::new(lazy_impl)); + Ok(ret) } /// `::{` or `::*` |
