@@ -138,7 +138,6 @@ pub struct Parser<'a> {
138
138
// Important: This must only be advanced from `bump` to ensure that
139
139
// `token_cursor.num_next_calls` is updated properly.
140
140
token_cursor : TokenCursor ,
141
- desugar_doc_comments : bool ,
142
141
/// This field is used to keep track of how many left angle brackets we have seen. This is
143
142
/// required in order to detect extra leading left angle brackets (`<` characters) and error
144
143
/// appropriately.
@@ -225,6 +224,9 @@ struct TokenCursor {
225
224
// because it's the outermost token stream which never has delimiters.
226
225
stack : Vec < ( TokenTreeCursor , Delimiter , DelimSpan ) > ,
227
226
227
+ // We need to desugar doc comments from `/// foo` form into `#[doc =
228
+ // r"foo"]` form when parsing declarative macro inputs in `parse_tt`,
229
+ // because some declarative macros look for `doc` attributes.
228
230
desugar_doc_comments : bool ,
229
231
230
232
// Counts the number of calls to `{,inlined_}next`.
@@ -255,33 +257,38 @@ struct TokenCursor {
255
257
}
256
258
257
259
impl TokenCursor {
258
- fn next ( & mut self , desugar_doc_comments : bool ) -> ( Token , Spacing ) {
259
- self . inlined_next ( desugar_doc_comments )
260
+ fn next ( & mut self ) -> ( Token , Spacing ) {
261
+ self . inlined_next ( )
260
262
}
261
263
262
264
/// This always-inlined version should only be used on hot code paths.
263
265
#[ inline( always) ]
264
- fn inlined_next ( & mut self , desugar_doc_comments : bool ) -> ( Token , Spacing ) {
266
+ fn inlined_next ( & mut self ) -> ( Token , Spacing ) {
265
267
loop {
266
268
// FIXME: we currently don't return `Delimiter` open/close delims. To fix #67062 we will
267
269
// need to, whereupon the `delim != Delimiter::Invisible` conditions below can be
268
270
// removed.
269
271
if let Some ( tree) = self . tree_cursor . next_ref ( ) {
270
272
match tree {
271
- & TokenTree :: Token ( ref token, spacing) => match ( desugar_doc_comments, token) {
272
- ( true , & Token { kind : token:: DocComment ( _, attr_style, data) , span } ) => {
273
- let desugared = self . desugar ( attr_style, data, span) ;
274
- self . tree_cursor . replace_prev_and_rewind ( desugared) ;
275
- // Continue to get the first token of the desugared doc comment.
276
- }
277
- _ => {
278
- debug_assert ! ( !matches!(
279
- token. kind,
280
- token:: OpenDelim ( _) | token:: CloseDelim ( _)
281
- ) ) ;
282
- return ( token. clone ( ) , spacing) ;
273
+ & TokenTree :: Token ( ref token, spacing) => {
274
+ match ( self . desugar_doc_comments , token) {
275
+ (
276
+ true ,
277
+ & Token { kind : token:: DocComment ( _, attr_style, data) , span } ,
278
+ ) => {
279
+ let desugared = self . desugar ( attr_style, data, span) ;
280
+ self . tree_cursor . replace_prev_and_rewind ( desugared) ;
281
+ // Continue to get the first token of the desugared doc comment.
282
+ }
283
+ _ => {
284
+ debug_assert ! ( !matches!(
285
+ token. kind,
286
+ token:: OpenDelim ( _) | token:: CloseDelim ( _)
287
+ ) ) ;
288
+ return ( token. clone ( ) , spacing) ;
289
+ }
283
290
}
284
- } ,
291
+ }
285
292
& TokenTree :: Delimited ( sp, delim, ref tts) => {
286
293
let trees = tts. clone ( ) . into_trees ( ) ;
287
294
self . stack . push ( ( mem:: replace ( & mut self . tree_cursor , trees) , delim, sp) ) ;
@@ -463,7 +470,6 @@ impl<'a> Parser<'a> {
463
470
desugar_doc_comments,
464
471
break_last_token : false ,
465
472
} ,
466
- desugar_doc_comments,
467
473
unmatched_angle_bracket_count : 0 ,
468
474
max_angle_bracket_count : 0 ,
469
475
last_unexpected_token_span : None ,
@@ -1107,7 +1113,7 @@ impl<'a> Parser<'a> {
1107
1113
pub fn bump ( & mut self ) {
1108
1114
// Note: destructuring here would give nicer code, but it was found in #96210 to be slower
1109
1115
// than `.0`/`.1` access.
1110
- let mut next = self . token_cursor . inlined_next ( self . desugar_doc_comments ) ;
1116
+ let mut next = self . token_cursor . inlined_next ( ) ;
1111
1117
self . token_cursor . num_next_calls += 1 ;
1112
1118
// We've retrieved an token from the underlying
1113
1119
// cursor, so we no longer need to worry about
@@ -1157,7 +1163,7 @@ impl<'a> Parser<'a> {
1157
1163
let mut i = 0 ;
1158
1164
let mut token = Token :: dummy ( ) ;
1159
1165
while i < dist {
1160
- token = cursor. next ( /* desugar_doc_comments */ false ) . 0 ;
1166
+ token = cursor. next ( ) . 0 ;
1161
1167
if matches ! (
1162
1168
token. kind,
1163
1169
token:: OpenDelim ( Delimiter :: Invisible ) | token:: CloseDelim ( Delimiter :: Invisible )
0 commit comments