Skip to content

Commit 64c2e9e

Browse files
committed
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.
1 parent 8170acb commit 64c2e9e

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

compiler/rustc_parse/src/parser/expr.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ impl<'a> Parser<'a> {
9898
self.parse_expr_res(Restrictions::empty(), attrs)
9999
}
100100

101-
/// Parses an expression, forcing tokens to be collected
101+
/// Parses an expression, forcing tokens to be collected.
102102
pub fn parse_expr_force_collect(&mut self) -> PResult<'a, P<Expr>> {
103-
self.collect_tokens_no_attrs(|this| this.parse_expr())
103+
self.current_closure.take();
104+
105+
let attrs = self.parse_outer_attributes()?;
106+
self.collect_tokens_no_attrs(|this| this.parse_expr_res(Restrictions::empty(), attrs))
104107
}
105108

106109
pub fn parse_expr_anon_const(&mut self) -> PResult<'a, AnonConst> {

tests/ui/proc-macro/expr-stmt-nonterminal-tokens.stdout

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = #[allow(warnings)] #[allow(warnings)] 0; 0 }, }
1+
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = #[allow(warnings)] 0; 0 }, }
22
PRINT-DERIVE INPUT (DEBUG): TokenStream [
33
Ident {
44
ident: "enum",
@@ -39,31 +39,6 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
3939
Group {
4040
delimiter: None,
4141
stream: TokenStream [
42-
Punct {
43-
ch: '#',
44-
spacing: Alone,
45-
span: #0 bytes(543..544),
46-
},
47-
Group {
48-
delimiter: Bracket,
49-
stream: TokenStream [
50-
Ident {
51-
ident: "allow",
52-
span: #0 bytes(545..550),
53-
},
54-
Group {
55-
delimiter: Parenthesis,
56-
stream: TokenStream [
57-
Ident {
58-
ident: "warnings",
59-
span: #0 bytes(551..559),
60-
},
61-
],
62-
span: #0 bytes(550..560),
63-
},
64-
],
65-
span: #0 bytes(544..561),
66-
},
6742
Punct {
6843
ch: '#',
6944
spacing: Alone,

0 commit comments

Comments
 (0)