@@ -24,7 +24,6 @@ use errors::{Applicability, FatalError};
24
24
use smallvec:: { smallvec, SmallVec } ;
25
25
use syntax_pos:: { Span , DUMMY_SP , FileName } ;
26
26
27
- use rustc_data_structures:: fx:: FxHashMap ;
28
27
use rustc_data_structures:: sync:: Lrc ;
29
28
use std:: io:: ErrorKind ;
30
29
use std:: { iter, mem, slice} ;
@@ -73,6 +72,22 @@ macro_rules! ast_fragments {
73
72
}
74
73
75
74
impl AstFragment {
75
+ pub fn add_placeholders( & mut self , placeholders: & [ NodeId ] ) {
76
+ if placeholders. is_empty( ) {
77
+ return ;
78
+ }
79
+ match self {
80
+ $( $( AstFragment :: $Kind( ast) => ast. extend( placeholders. iter( ) . flat_map( |id| {
81
+ // We are repeating through arguments with `many`, to do that we have to
82
+ // mention some macro variable from those arguments even if it's not used.
83
+ #[ cfg_attr( bootstrap, allow( unused_macros) ) ]
84
+ macro _repeating( $flat_map_ast_elt) { }
85
+ placeholder( AstFragmentKind :: $Kind, * id) . $make_ast( )
86
+ } ) ) , ) ?) *
87
+ _ => panic!( "unexpected AST fragment kind" )
88
+ }
89
+ }
90
+
76
91
pub fn make_opt_expr( self ) -> Option <P <ast:: Expr >> {
77
92
match self {
78
93
AstFragment :: OptExpr ( expr) => expr,
@@ -340,7 +355,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
340
355
// Unresolved macros produce dummy outputs as a recovery measure.
341
356
invocations. reverse ( ) ;
342
357
let mut expanded_fragments = Vec :: new ( ) ;
343
- let mut all_derive_placeholders: FxHashMap < ExpnId , Vec < _ > > = FxHashMap :: default ( ) ;
344
358
let mut undetermined_invocations = Vec :: new ( ) ;
345
359
let ( mut progress, mut force) = ( false , !self . monotonic ) ;
346
360
loop {
@@ -418,9 +432,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
418
432
self . cx . resolver . add_derives ( invoc. expansion_data . id , SpecialDerives :: COPY ) ;
419
433
}
420
434
421
- let derive_placeholders =
422
- all_derive_placeholders. entry ( invoc. expansion_data . id ) . or_default ( ) ;
423
- derive_placeholders. reserve ( derives. len ( ) ) ;
435
+ let mut derive_placeholders = Vec :: with_capacity ( derives. len ( ) ) ;
424
436
invocations. reserve ( derives. len ( ) ) ;
425
437
for path in derives {
426
438
let expn_id = ExpnId :: fresh ( None ) ;
@@ -436,7 +448,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
436
448
}
437
449
let fragment = invoc. fragment_kind
438
450
. expect_from_annotatables ( :: std:: iter:: once ( item) ) ;
439
- self . collect_invocations ( fragment, derive_placeholders)
451
+ self . collect_invocations ( fragment, & derive_placeholders)
440
452
}
441
453
} ;
442
454
@@ -455,10 +467,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
455
467
let mut placeholder_expander = PlaceholderExpander :: new ( self . cx , self . monotonic ) ;
456
468
while let Some ( expanded_fragments) = expanded_fragments. pop ( ) {
457
469
for ( expn_id, expanded_fragment) in expanded_fragments. into_iter ( ) . rev ( ) {
458
- let derive_placeholders =
459
- all_derive_placeholders. remove ( & expn_id) . unwrap_or_else ( Vec :: new) ;
460
470
placeholder_expander. add ( NodeId :: placeholder_from_expn_id ( expn_id) ,
461
- expanded_fragment, derive_placeholders ) ;
471
+ expanded_fragment) ;
462
472
}
463
473
}
464
474
fragment_with_placeholders. mut_visit_with ( & mut placeholder_expander) ;
@@ -491,13 +501,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
491
501
monotonic : self . monotonic ,
492
502
} ;
493
503
fragment. mut_visit_with ( & mut collector) ;
504
+ fragment. add_placeholders ( extra_placeholders) ;
494
505
collector. invocations
495
506
} ;
496
507
497
- // FIXME: Merge `extra_placeholders` into the `fragment` as regular placeholders.
498
508
if self . monotonic {
499
509
self . cx . resolver . visit_ast_fragment_with_placeholders (
500
- self . cx . current_expansion . id , & fragment, extra_placeholders) ;
510
+ self . cx . current_expansion . id , & fragment
511
+ ) ;
501
512
}
502
513
503
514
( fragment, invocations)
0 commit comments