3
3
use base_db:: { salsa, CrateId , FileId , SourceDatabase } ;
4
4
use either:: Either ;
5
5
use limit:: Limit ;
6
- use mbe:: { syntax_node_to_token_tree, MatchedArmIndex } ;
6
+ use mbe:: { syntax_node_to_token_tree, DocCommentDesugarMode , MatchedArmIndex } ;
7
7
use rustc_hash:: FxHashSet ;
8
8
use span:: { AstIdMap , Span , SyntaxContextData , SyntaxContextId } ;
9
9
use syntax:: { ast, AstNode , Parse , SyntaxElement , SyntaxError , SyntaxNode , SyntaxToken , T } ;
@@ -156,11 +156,25 @@ pub fn expand_speculative(
156
156
// Build the subtree and token mapping for the speculative args
157
157
let ( mut tt, undo_info) = match loc. kind {
158
158
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
+ ) ,
160
169
SyntaxFixupUndoInfo :: NONE ,
161
170
) ,
162
171
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
+ ) ,
164
178
SyntaxFixupUndoInfo :: NONE ,
165
179
) ,
166
180
MacroCallKind :: Derive { derive_attr_index : index, .. }
@@ -176,7 +190,12 @@ pub fn expand_speculative(
176
190
177
191
let censor_cfg =
178
192
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
+ ) ;
180
199
fixups. append . retain ( |it, _| match it {
181
200
syntax:: NodeOrToken :: Token ( _) => true ,
182
201
it => !censor. contains ( it) && !censor_cfg. contains ( it) ,
@@ -191,6 +210,7 @@ pub fn expand_speculative(
191
210
fixups. append ,
192
211
fixups. remove ,
193
212
span,
213
+ DocCommentDesugarMode :: ProcMacro ,
194
214
) ,
195
215
fixups. undo_info ,
196
216
)
@@ -212,7 +232,12 @@ pub fn expand_speculative(
212
232
} ?;
213
233
match attr. token_tree ( ) {
214
234
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
+ ) ;
216
241
tree. delimiter = tt:: Delimiter :: invisible_spanned ( span) ;
217
242
218
243
Some ( tree)
@@ -432,7 +457,16 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
432
457
return dummy_tt ( kind) ;
433
458
}
434
459
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
+ ) ;
436
470
if loc. def . is_proc_macro ( ) {
437
471
// proc macros expect their inputs without parentheses, MBEs expect it with them included
438
472
tt. delimiter . kind = tt:: DelimiterKind :: Invisible ;
@@ -469,7 +503,8 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
469
503
let ( mut tt, undo_info) = {
470
504
let syntax = item_node. syntax ( ) ;
471
505
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 ) ;
473
508
fixups. append . retain ( |it, _| match it {
474
509
syntax:: NodeOrToken :: Token ( _) => true ,
475
510
it => !censor. contains ( it) && !censor_cfg. contains ( it) ,
@@ -484,6 +519,7 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
484
519
fixups. append ,
485
520
fixups. remove ,
486
521
span,
522
+ DocCommentDesugarMode :: ProcMacro ,
487
523
) ,
488
524
fixups. undo_info ,
489
525
)
0 commit comments