@@ -99,80 +99,34 @@ impl<'a> Parser<'a> {
99
99
// we always capture tokens for any `Nonterminal` which needs them.
100
100
Ok ( match kind {
101
101
NonterminalKind :: Item => match self . collect_tokens ( |this| this. parse_item ( ) ) ? {
102
- ( Some ( mut item) , tokens) => {
103
- // If we captured tokens during parsing (due to outer attributes),
104
- // use those.
105
- if item. tokens . is_none ( ) {
106
- item. tokens = tokens;
107
- }
108
- token:: NtItem ( item)
109
- }
110
- ( None , _) => {
102
+ Some ( item) => token:: NtItem ( item) ,
103
+ None => {
111
104
return Err ( self . struct_span_err ( self . token . span , "expected an item keyword" ) ) ;
112
105
}
113
106
} ,
114
107
NonterminalKind :: Block => {
115
- let ( mut block, tokens) = self . collect_tokens ( |this| this. parse_block ( ) ) ?;
116
- // We have have eaten an NtBlock, which could already have tokens
117
- if block. tokens . is_none ( ) {
118
- block. tokens = tokens;
119
- }
120
- token:: NtBlock ( block)
108
+ token:: NtBlock ( self . collect_tokens ( |this| this. parse_block ( ) ) ?)
121
109
}
122
- NonterminalKind :: Stmt => {
123
- let ( stmt, tokens) = self . collect_tokens ( |this| this. parse_stmt ( ) ) ?;
124
- match stmt {
125
- Some ( mut s) => {
126
- if s. tokens ( ) . is_none ( ) {
127
- s. set_tokens ( tokens) ;
128
- }
129
- token:: NtStmt ( s)
130
- }
131
- None => {
132
- return Err ( self . struct_span_err ( self . token . span , "expected a statement" ) ) ;
133
- }
110
+ NonterminalKind :: Stmt => match self . collect_tokens ( |this| this. parse_stmt ( ) ) ? {
111
+ Some ( s) => token:: NtStmt ( s) ,
112
+ None => {
113
+ return Err ( self . struct_span_err ( self . token . span , "expected a statement" ) ) ;
134
114
}
135
- }
115
+ } ,
136
116
NonterminalKind :: Pat2018 { .. } | NonterminalKind :: Pat2021 { .. } => {
137
- let ( mut pat , tokens ) = self . collect_tokens ( |this| match kind {
117
+ token :: NtPat ( self . collect_tokens ( |this| match kind {
138
118
NonterminalKind :: Pat2018 { .. } => this. parse_pat ( None ) ,
139
119
NonterminalKind :: Pat2021 { .. } => {
140
120
this. parse_top_pat ( GateOr :: Yes , RecoverComma :: No )
141
121
}
142
122
_ => unreachable ! ( ) ,
143
- } ) ?;
144
- // We have have eaten an NtPat, which could already have tokens
145
- if pat. tokens . is_none ( ) {
146
- pat. tokens = tokens;
147
- }
148
- token:: NtPat ( pat)
149
- }
150
- NonterminalKind :: Expr => {
151
- let ( mut expr, tokens) = self . collect_tokens ( |this| this. parse_expr ( ) ) ?;
152
- // If we captured tokens during parsing (due to outer attributes),
153
- // use those.
154
- if expr. tokens . is_none ( ) {
155
- expr. tokens = tokens;
156
- }
157
- token:: NtExpr ( expr)
123
+ } ) ?)
158
124
}
125
+ NonterminalKind :: Expr => token:: NtExpr ( self . collect_tokens ( |this| this. parse_expr ( ) ) ?) ,
159
126
NonterminalKind :: Literal => {
160
- let ( mut lit, tokens) =
161
- self . collect_tokens ( |this| this. parse_literal_maybe_minus ( ) ) ?;
162
- // We have have eaten a nonterminal, which could already have tokens
163
- if lit. tokens . is_none ( ) {
164
- lit. tokens = tokens;
165
- }
166
- token:: NtLiteral ( lit)
167
- }
168
- NonterminalKind :: Ty => {
169
- let ( mut ty, tokens) = self . collect_tokens ( |this| this. parse_ty ( ) ) ?;
170
- // We have an eaten an NtTy, which could already have tokens
171
- if ty. tokens . is_none ( ) {
172
- ty. tokens = tokens;
173
- }
174
- token:: NtTy ( ty)
127
+ token:: NtLiteral ( self . collect_tokens ( |this| this. parse_literal_maybe_minus ( ) ) ?)
175
128
}
129
+ NonterminalKind :: Ty => token:: NtTy ( self . collect_tokens ( |this| this. parse_ty ( ) ) ?) ,
176
130
// this could be handled like a token, since it is one
177
131
NonterminalKind :: Ident => {
178
132
if let Some ( ( ident, is_raw) ) = get_macro_ident ( & self . token ) {
@@ -185,32 +139,15 @@ impl<'a> Parser<'a> {
185
139
}
186
140
}
187
141
NonterminalKind :: Path => {
188
- let ( mut path, tokens) =
189
- self . collect_tokens ( |this| this. parse_path ( PathStyle :: Type ) ) ?;
190
- // We have have eaten an NtPath, which could already have tokens
191
- if path. tokens . is_none ( ) {
192
- path. tokens = tokens;
193
- }
194
- token:: NtPath ( path)
142
+ token:: NtPath ( self . collect_tokens ( |this| this. parse_path ( PathStyle :: Type ) ) ?)
195
143
}
196
144
NonterminalKind :: Meta => {
197
- let ( mut attr, tokens) = self . collect_tokens ( |this| this. parse_attr_item ( false ) ) ?;
198
- // We may have eaten a nonterminal, which could already have tokens
199
- if attr. tokens . is_none ( ) {
200
- attr. tokens = tokens;
201
- }
202
- token:: NtMeta ( P ( attr) )
145
+ token:: NtMeta ( P ( self . collect_tokens ( |this| this. parse_attr_item ( false ) ) ?) )
203
146
}
204
147
NonterminalKind :: TT => token:: NtTT ( self . parse_token_tree ( ) ) ,
205
- NonterminalKind :: Vis => {
206
- let ( mut vis, tokens) =
207
- self . collect_tokens ( |this| this. parse_visibility ( FollowedByType :: Yes ) ) ?;
208
- // We may have etan an `NtVis`, which could already have tokens
209
- if vis. tokens . is_none ( ) {
210
- vis. tokens = tokens;
211
- }
212
- token:: NtVis ( vis)
213
- }
148
+ NonterminalKind :: Vis => token:: NtVis (
149
+ self . collect_tokens ( |this| this. parse_visibility ( FollowedByType :: Yes ) ) ?,
150
+ ) ,
214
151
NonterminalKind :: Lifetime => {
215
152
if self . check_lifetime ( ) {
216
153
token:: NtLifetime ( self . expect_lifetime ( ) . ident )
0 commit comments