about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-06-19 17:33:46 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-06-19 19:15:06 +1000
commit64c2e9ed3bfb6d6e8f9463f90d4eefa736242b8e (patch)
treefb3cafd0be3b2ce7b0bd302c546fcbd3d86de98f /compiler/rustc_parse/src/parser
parent8170acb197d7658505949cefc12e01dfc4c8feab (diff)
downloadrust-64c2e9ed3bfb6d6e8f9463f90d4eefa736242b8e.tar.gz
rust-64c2e9ed3bfb6d6e8f9463f90d4eefa736242b8e.zip
Change how `parse_expr_force_collect` works.
It now parses outer attributes before collecting tokens. This avoids the
problem where the outer attribute tokens were being stored twice -- for
the attribute tokesn, and also for the expression tokens.

Fixes #86055.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index d27c612bbc1..4094fb53659 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -98,9 +98,12 @@ impl<'a> Parser<'a> {
         self.parse_expr_res(Restrictions::empty(), attrs)
     }
 
-    /// Parses an expression, forcing tokens to be collected
+    /// Parses an expression, forcing tokens to be collected.
     pub fn parse_expr_force_collect(&mut self) -> PResult<'a, P<Expr>> {
-        self.collect_tokens_no_attrs(|this| this.parse_expr())
+        self.current_closure.take();
+
+        let attrs = self.parse_outer_attributes()?;
+        self.collect_tokens_no_attrs(|this| this.parse_expr_res(Restrictions::empty(), attrs))
     }
 
     pub fn parse_expr_anon_const(&mut self) -> PResult<'a, AnonConst> {