@@ -138,7 +138,6 @@ pub struct Parser<'a> {
138138 // Important: This must only be advanced from `bump` to ensure that
139139 // `token_cursor.num_next_calls` is updated properly.
140140 token_cursor : TokenCursor ,
141- desugar_doc_comments : bool ,
142141 /// This field is used to keep track of how many left angle brackets we have seen. This is
143142 /// required in order to detect extra leading left angle brackets (`<` characters) and error
144143 /// appropriately.
@@ -225,6 +224,9 @@ struct TokenCursor {
225224 // because it's the outermost token stream which never has delimiters.
226225 stack : Vec < ( TokenTreeCursor , Delimiter , DelimSpan ) > ,
227226
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.
228230 desugar_doc_comments : bool ,
229231
230232 // Counts the number of calls to `{,inlined_}next`.
@@ -255,33 +257,38 @@ struct TokenCursor {
255257}
256258
257259impl 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 ( )
260262 }
261263
262264 /// This always-inlined version should only be used on hot code paths.
263265 #[ inline( always) ]
264- fn inlined_next ( & mut self , desugar_doc_comments : bool ) -> ( Token , Spacing ) {
266+ fn inlined_next ( & mut self ) -> ( Token , Spacing ) {
265267 loop {
266268 // FIXME: we currently don't return `Delimiter` open/close delims. To fix #67062 we will
267269 // need to, whereupon the `delim != Delimiter::Invisible` conditions below can be
268270 // removed.
269271 if let Some ( tree) = self . tree_cursor . next_ref ( ) {
270272 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+ }
283290 }
284- } ,
291+ }
285292 & TokenTree :: Delimited ( sp, delim, ref tts) => {
286293 let trees = tts. clone ( ) . into_trees ( ) ;
287294 self . stack . push ( ( mem:: replace ( & mut self . tree_cursor , trees) , delim, sp) ) ;
@@ -463,7 +470,6 @@ impl<'a> Parser<'a> {
463470 desugar_doc_comments,
464471 break_last_token : false ,
465472 } ,
466- desugar_doc_comments,
467473 unmatched_angle_bracket_count : 0 ,
468474 max_angle_bracket_count : 0 ,
469475 last_unexpected_token_span : None ,
@@ -1107,7 +1113,7 @@ impl<'a> Parser<'a> {
11071113 pub fn bump ( & mut self ) {
11081114 // Note: destructuring here would give nicer code, but it was found in #96210 to be slower
11091115 // 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 ( ) ;
11111117 self . token_cursor . num_next_calls += 1 ;
11121118 // We've retrieved an token from the underlying
11131119 // cursor, so we no longer need to worry about
@@ -1157,7 +1163,7 @@ impl<'a> Parser<'a> {
11571163 let mut i = 0 ;
11581164 let mut token = Token :: dummy ( ) ;
11591165 while i < dist {
1160- token = cursor. next ( /* desugar_doc_comments */ false ) . 0 ;
1166+ token = cursor. next ( ) . 0 ;
11611167 if matches ! (
11621168 token. kind,
11631169 token:: OpenDelim ( Delimiter :: Invisible ) | token:: CloseDelim ( Delimiter :: Invisible )
0 commit comments