diff options
| author | bors <bors@rust-lang.org> | 2021-01-22 02:42:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-22 02:42:38 +0000 |
| commit | dc1eee2f256efbd1d3b50b6b090232f81cac6d72 (patch) | |
| tree | 3c4b490d54ce2e526d7ed3958bfd32569dfb75f1 /compiler/rustc_parse/src/parser/mod.rs | |
| parent | a9a396d8ed0244ba8bb3fe1793ae2a6fdabd7754 (diff) | |
| parent | 11b1e370161dd09c095350c66f7b187fc9654ec6 (diff) | |
| download | rust-dc1eee2f256efbd1d3b50b6b090232f81cac6d72.tar.gz rust-dc1eee2f256efbd1d3b50b6b090232f81cac6d72.zip | |
Auto merge of #81177 - Aaron1011:fix/force-capture-tokens, r=petrochenkov
Force token collection to run when parsing nonterminals Fixes #81007 Previously, we would fail to collect tokens in the proper place when only builtin attributes were present. As a result, we would end up with attribute tokens in the collected `TokenStream`, leading to duplication when we attempted to prepend the attributes from the AST node. We now explicitly track when token collection must be performed due to nomterminal parsing.
Diffstat (limited to 'compiler/rustc_parse/src/parser/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 5d7ea5b8d57..c85b7a00732 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -54,6 +54,13 @@ enum BlockMode { Ignore, } +/// Whether or not we should force collection of tokens for an AST node, +/// regardless of whether or not it has attributes +pub enum ForceCollect { + Yes, + No, +} + /// Like `maybe_whole_expr`, but for things other than expressions. #[macro_export] macro_rules! maybe_whole { @@ -1413,3 +1420,16 @@ fn make_token_stream( assert!(stack.is_empty(), "Stack should be empty: final_buf={:?} stack={:?}", final_buf, stack); TokenStream::new(final_buf.inner) } + +#[macro_export] +macro_rules! maybe_collect_tokens { + ($self:ident, $force_collect:expr, $attrs:expr, $f:expr) => { + if matches!($force_collect, ForceCollect::Yes) + || $crate::parser::attr::maybe_needs_tokens($attrs) + { + $self.collect_tokens($f) + } else { + $f($self) + } + }; +} |
