@@ -4,7 +4,6 @@ use crate::errors::{
4
4
IncompleteParse , RecursionLimitReached , RemoveExprNotSupported , RemoveNodeNotSupported ,
5
5
UnsupportedKeyValue , WrongFragmentKind ,
6
6
} ;
7
- use crate :: hygiene:: SyntaxContext ;
8
7
use crate :: mbe:: diagnostics:: annotate_err_with_kind;
9
8
use crate :: module:: { mod_dir_path, parse_external_mod, DirOwnership , ParsedExternalMod } ;
10
9
use crate :: placeholders:: { placeholder, PlaceholderExpander } ;
@@ -32,6 +31,7 @@ use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
32
31
use rustc_session:: lint:: BuiltinLintDiag ;
33
32
use rustc_session:: parse:: feature_err;
34
33
use rustc_session:: { Limit , Session } ;
34
+ use rustc_span:: hygiene:: SyntaxContext ;
35
35
use rustc_span:: symbol:: { sym, Ident } ;
36
36
use rustc_span:: { ErrorGuaranteed , FileName , LocalExpnId , Span } ;
37
37
@@ -87,7 +87,7 @@ macro_rules! ast_fragments {
87
87
}
88
88
89
89
impl AstFragment {
90
- pub fn add_placeholders( & mut self , placeholders: & [ NodeId ] ) {
90
+ fn add_placeholders( & mut self , placeholders: & [ NodeId ] ) {
91
91
if placeholders. is_empty( ) {
92
92
return ;
93
93
}
@@ -100,14 +100,14 @@ macro_rules! ast_fragments {
100
100
}
101
101
}
102
102
103
- pub fn make_opt_expr( self ) -> Option <P <ast:: Expr >> {
103
+ pub ( crate ) fn make_opt_expr( self ) -> Option <P <ast:: Expr >> {
104
104
match self {
105
105
AstFragment :: OptExpr ( expr) => expr,
106
106
_ => panic!( "AstFragment::make_* called on the wrong kind of fragment" ) ,
107
107
}
108
108
}
109
109
110
- pub fn make_method_receiver_expr( self ) -> P <ast:: Expr > {
110
+ pub ( crate ) fn make_method_receiver_expr( self ) -> P <ast:: Expr > {
111
111
match self {
112
112
AstFragment :: MethodReceiverExpr ( expr) => expr,
113
113
_ => panic!( "AstFragment::make_* called on the wrong kind of fragment" ) ,
@@ -125,7 +125,7 @@ macro_rules! ast_fragments {
125
125
T :: fragment_to_output( self )
126
126
}
127
127
128
- pub fn mut_visit_with<F : MutVisitor >( & mut self , vis: & mut F ) {
128
+ pub ( crate ) fn mut_visit_with<F : MutVisitor >( & mut self , vis: & mut F ) {
129
129
match self {
130
130
AstFragment :: OptExpr ( opt_expr) => {
131
131
visit_clobber( opt_expr, |opt_expr| {
@@ -372,6 +372,14 @@ impl Invocation {
372
372
InvocationKind :: Derive { path, .. } => path. span ,
373
373
}
374
374
}
375
+
376
+ fn span_mut ( & mut self ) -> & mut Span {
377
+ match & mut self . kind {
378
+ InvocationKind :: Bang { span, .. } => span,
379
+ InvocationKind :: Attr { attr, .. } => & mut attr. span ,
380
+ InvocationKind :: Derive { path, .. } => & mut path. span ,
381
+ }
382
+ }
375
383
}
376
384
377
385
pub struct MacroExpander < ' a , ' b > {
@@ -432,7 +440,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
432
440
break ;
433
441
}
434
442
invocations = mem:: take ( & mut undetermined_invocations) ;
435
- force = !mem:: replace ( & mut progress, false ) ;
443
+ force = !progress;
444
+ progress = false ;
436
445
if force && self . monotonic {
437
446
self . cx . dcx ( ) . span_delayed_bug (
438
447
invocations. last ( ) . unwrap ( ) . 0 . span ( ) ,
@@ -471,7 +480,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
471
480
self . cx . force_mode = force;
472
481
473
482
let fragment_kind = invoc. fragment_kind ;
474
- let ( expanded_fragment , new_invocations ) = match self . expand_invoc ( invoc, & ext. kind ) {
483
+ match self . expand_invoc ( invoc, & ext. kind ) {
475
484
ExpandResult :: Ready ( fragment) => {
476
485
let mut derive_invocations = Vec :: new ( ) ;
477
486
let derive_placeholders = self
@@ -503,12 +512,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
503
512
} )
504
513
. unwrap_or_default ( ) ;
505
514
506
- let ( fragment , collected_invocations) =
515
+ let ( expanded_fragment , collected_invocations) =
507
516
self . collect_invocations ( fragment, & derive_placeholders) ;
508
- // We choose to expand any derive invocations associated with this macro invocation
509
- // *before* any macro invocations collected from the output fragment
517
+ // We choose to expand any derive invocations associated with this macro
518
+ // invocation *before* any macro invocations collected from the output
519
+ // fragment.
510
520
derive_invocations. extend ( collected_invocations) ;
511
- ( fragment, derive_invocations)
521
+
522
+ progress = true ;
523
+ if expanded_fragments. len ( ) < depth {
524
+ expanded_fragments. push ( Vec :: new ( ) ) ;
525
+ }
526
+ expanded_fragments[ depth - 1 ] . push ( ( expn_id, expanded_fragment) ) ;
527
+ invocations. extend ( derive_invocations. into_iter ( ) . rev ( ) ) ;
512
528
}
513
529
ExpandResult :: Retry ( invoc) => {
514
530
if force {
@@ -519,17 +535,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
519
535
} else {
520
536
// Cannot expand, will retry this invocation later.
521
537
undetermined_invocations. push ( ( invoc, Some ( ext) ) ) ;
522
- continue ;
523
538
}
524
539
}
525
- } ;
526
-
527
- progress = true ;
528
- if expanded_fragments. len ( ) < depth {
529
- expanded_fragments. push ( Vec :: new ( ) ) ;
530
540
}
531
- expanded_fragments[ depth - 1 ] . push ( ( expn_id, expanded_fragment) ) ;
532
- invocations. extend ( new_invocations. into_iter ( ) . rev ( ) ) ;
533
541
}
534
542
535
543
self . cx . current_expansion = orig_expansion_data;
@@ -590,11 +598,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
590
598
for ( invoc, _) in invocations. iter_mut ( ) {
591
599
let expn_id = invoc. expansion_data . id ;
592
600
let parent_def = self . cx . resolver . invocation_parent ( expn_id) ;
593
- let span = match & mut invoc. kind {
594
- InvocationKind :: Bang { span, .. } => span,
595
- InvocationKind :: Attr { attr, .. } => & mut attr. span ,
596
- InvocationKind :: Derive { path, .. } => & mut path. span ,
597
- } ;
601
+ let span = invoc. span_mut ( ) ;
598
602
* span = span. with_parent ( Some ( parent_def) ) ;
599
603
}
600
604
}
@@ -957,7 +961,7 @@ pub fn parse_ast_fragment<'a>(
957
961
} )
958
962
}
959
963
960
- pub fn ensure_complete_parse < ' a > (
964
+ pub ( crate ) fn ensure_complete_parse < ' a > (
961
965
parser : & Parser < ' a > ,
962
966
macro_path : & ast:: Path ,
963
967
kind_name : & str ,
0 commit comments