33use base_db:: { salsa, CrateId , FileId , SourceDatabase } ;
44use either:: Either ;
55use limit:: Limit ;
6- use mbe:: { syntax_node_to_token_tree, MatchedArmIndex } ;
6+ use mbe:: { syntax_node_to_token_tree, DocCommentDesugarMode , MatchedArmIndex } ;
77use rustc_hash:: FxHashSet ;
88use span:: { AstIdMap , Span , SyntaxContextData , SyntaxContextId } ;
99use syntax:: { ast, AstNode , Parse , SyntaxElement , SyntaxError , SyntaxNode , SyntaxToken , T } ;
@@ -156,11 +156,25 @@ pub fn expand_speculative(
156156 // Build the subtree and token mapping for the speculative args
157157 let ( mut tt, undo_info) = match loc. kind {
158158 MacroCallKind :: FnLike { .. } => (
159- mbe:: syntax_node_to_token_tree ( speculative_args, span_map, span) ,
159+ mbe:: syntax_node_to_token_tree (
160+ speculative_args,
161+ span_map,
162+ span,
163+ if loc. def . is_proc_macro ( ) {
164+ DocCommentDesugarMode :: ProcMacro
165+ } else {
166+ DocCommentDesugarMode :: Mbe
167+ } ,
168+ ) ,
160169 SyntaxFixupUndoInfo :: NONE ,
161170 ) ,
162171 MacroCallKind :: Attr { .. } if loc. def . is_attribute_derive ( ) => (
163- mbe:: syntax_node_to_token_tree ( speculative_args, span_map, span) ,
172+ mbe:: syntax_node_to_token_tree (
173+ speculative_args,
174+ span_map,
175+ span,
176+ DocCommentDesugarMode :: ProcMacro ,
177+ ) ,
164178 SyntaxFixupUndoInfo :: NONE ,
165179 ) ,
166180 MacroCallKind :: Derive { derive_attr_index : index, .. }
@@ -176,7 +190,12 @@ pub fn expand_speculative(
176190
177191 let censor_cfg =
178192 cfg_process:: process_cfg_attrs ( db, speculative_args, & loc) . unwrap_or_default ( ) ;
179- let mut fixups = fixup:: fixup_syntax ( span_map, speculative_args, span) ;
193+ let mut fixups = fixup:: fixup_syntax (
194+ span_map,
195+ speculative_args,
196+ span,
197+ DocCommentDesugarMode :: ProcMacro ,
198+ ) ;
180199 fixups. append . retain ( |it, _| match it {
181200 syntax:: NodeOrToken :: Token ( _) => true ,
182201 it => !censor. contains ( it) && !censor_cfg. contains ( it) ,
@@ -191,6 +210,7 @@ pub fn expand_speculative(
191210 fixups. append ,
192211 fixups. remove ,
193212 span,
213+ DocCommentDesugarMode :: ProcMacro ,
194214 ) ,
195215 fixups. undo_info ,
196216 )
@@ -212,7 +232,12 @@ pub fn expand_speculative(
212232 } ?;
213233 match attr. token_tree ( ) {
214234 Some ( token_tree) => {
215- let mut tree = syntax_node_to_token_tree ( token_tree. syntax ( ) , span_map, span) ;
235+ let mut tree = syntax_node_to_token_tree (
236+ token_tree. syntax ( ) ,
237+ span_map,
238+ span,
239+ DocCommentDesugarMode :: ProcMacro ,
240+ ) ;
216241 tree. delimiter = tt:: Delimiter :: invisible_spanned ( span) ;
217242
218243 Some ( tree)
@@ -432,7 +457,16 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
432457 return dummy_tt ( kind) ;
433458 }
434459
435- let mut tt = mbe:: syntax_node_to_token_tree ( tt. syntax ( ) , map. as_ref ( ) , span) ;
460+ let mut tt = mbe:: syntax_node_to_token_tree (
461+ tt. syntax ( ) ,
462+ map. as_ref ( ) ,
463+ span,
464+ if loc. def . is_proc_macro ( ) {
465+ DocCommentDesugarMode :: ProcMacro
466+ } else {
467+ DocCommentDesugarMode :: Mbe
468+ } ,
469+ ) ;
436470 if loc. def . is_proc_macro ( ) {
437471 // proc macros expect their inputs without parentheses, MBEs expect it with them included
438472 tt. delimiter . kind = tt:: DelimiterKind :: Invisible ;
@@ -469,7 +503,8 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
469503 let ( mut tt, undo_info) = {
470504 let syntax = item_node. syntax ( ) ;
471505 let censor_cfg = cfg_process:: process_cfg_attrs ( db, syntax, & loc) . unwrap_or_default ( ) ;
472- let mut fixups = fixup:: fixup_syntax ( map. as_ref ( ) , syntax, span) ;
506+ let mut fixups =
507+ fixup:: fixup_syntax ( map. as_ref ( ) , syntax, span, DocCommentDesugarMode :: ProcMacro ) ;
473508 fixups. append . retain ( |it, _| match it {
474509 syntax:: NodeOrToken :: Token ( _) => true ,
475510 it => !censor. contains ( it) && !censor_cfg. contains ( it) ,
@@ -484,6 +519,7 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
484519 fixups. append ,
485520 fixups. remove ,
486521 span,
522+ DocCommentDesugarMode :: ProcMacro ,
487523 ) ,
488524 fixups. undo_info ,
489525 )
0 commit comments