about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-24 20:09:18 +0000
committerbors <bors@rust-lang.org>2021-01-24 20:09:18 +0000
commit1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8 (patch)
tree8374e75dc7972f71192fe25804c4109b3ddcf0a1 /compiler/rustc_parse/src/parser
parent9a9477fada5baf69d693e717d6df902e411a73d6 (diff)
parentbd07165690481aaa4c99b9c3ab6e20fbebae8f54 (diff)
downloadrust-1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8.tar.gz
rust-1d0d76f8dd4f5f6ecbeab575b87edaf1c9f56bb8.zip
Auto merge of #81337 - petrochenkov:kvcollect, r=Aaron1011
parser: Collect tokens for values in key-value attributes

Fixes #81208 which happens when we parse the attribute value for the second time with an overridden span to synthesize tokens.

It also may be faster to collect tokens instead of re-synthesizing them.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/mod.rs8
1 files changed, 2 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs
index f11c6591de9..c575c821964 100644
--- a/compiler/rustc_parse/src/parser/mod.rs
+++ b/compiler/rustc_parse/src/parser/mod.rs
@@ -980,12 +980,8 @@ impl<'a> Parser<'a> {
                         }
                     }
 
-                    // The value here is never passed to macros as tokens by itself (not as a part
-                    // of the whole attribute), so we don't collect tokens here. If this changes,
-                    // then token will need to be collected. One catch here is that we are using
-                    // a nonterminal for keeping the expression, but this nonterminal should not
-                    // be wrapped into a group when converting to token stream.
-                    let expr = self.parse_expr()?;
+                    // Collect tokens because they are used during lowering to HIR.
+                    let expr = self.collect_tokens(|this| this.parse_expr())?;
                     let span = expr.span;
 
                     match &expr.kind {