@@ -4,7 +4,6 @@ use crate::errors::{
44 IncompleteParse , RecursionLimitReached , RemoveExprNotSupported , RemoveNodeNotSupported ,
55 UnsupportedKeyValue , WrongFragmentKind ,
66} ;
7- use crate :: hygiene:: SyntaxContext ;
87use crate :: mbe:: diagnostics:: annotate_err_with_kind;
98use crate :: module:: { mod_dir_path, parse_external_mod, DirOwnership , ParsedExternalMod } ;
109use crate :: placeholders:: { placeholder, PlaceholderExpander } ;
@@ -32,6 +31,7 @@ use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
3231use rustc_session:: lint:: BuiltinLintDiag ;
3332use rustc_session:: parse:: feature_err;
3433use rustc_session:: { Limit , Session } ;
34+ use rustc_span:: hygiene:: SyntaxContext ;
3535use rustc_span:: symbol:: { sym, Ident } ;
3636use rustc_span:: { ErrorGuaranteed , FileName , LocalExpnId , Span } ;
3737
@@ -87,7 +87,7 @@ macro_rules! ast_fragments {
8787 }
8888
8989 impl AstFragment {
90- pub fn add_placeholders( & mut self , placeholders: & [ NodeId ] ) {
90+ fn add_placeholders( & mut self , placeholders: & [ NodeId ] ) {
9191 if placeholders. is_empty( ) {
9292 return ;
9393 }
@@ -100,14 +100,14 @@ macro_rules! ast_fragments {
100100 }
101101 }
102102
103- pub fn make_opt_expr( self ) -> Option <P <ast:: Expr >> {
103+ pub ( crate ) fn make_opt_expr( self ) -> Option <P <ast:: Expr >> {
104104 match self {
105105 AstFragment :: OptExpr ( expr) => expr,
106106 _ => panic!( "AstFragment::make_* called on the wrong kind of fragment" ) ,
107107 }
108108 }
109109
110- pub fn make_method_receiver_expr( self ) -> P <ast:: Expr > {
110+ pub ( crate ) fn make_method_receiver_expr( self ) -> P <ast:: Expr > {
111111 match self {
112112 AstFragment :: MethodReceiverExpr ( expr) => expr,
113113 _ => panic!( "AstFragment::make_* called on the wrong kind of fragment" ) ,
@@ -125,7 +125,7 @@ macro_rules! ast_fragments {
125125 T :: fragment_to_output( self )
126126 }
127127
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 ) {
129129 match self {
130130 AstFragment :: OptExpr ( opt_expr) => {
131131 visit_clobber( opt_expr, |opt_expr| {
@@ -372,6 +372,14 @@ impl Invocation {
372372 InvocationKind :: Derive { path, .. } => path. span ,
373373 }
374374 }
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+ }
375383}
376384
377385pub struct MacroExpander < ' a , ' b > {
@@ -432,7 +440,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
432440 break ;
433441 }
434442 invocations = mem:: take ( & mut undetermined_invocations) ;
435- force = !mem:: replace ( & mut progress, false ) ;
443+ force = !progress;
444+ progress = false ;
436445 if force && self . monotonic {
437446 self . cx . dcx ( ) . span_delayed_bug (
438447 invocations. last ( ) . unwrap ( ) . 0 . span ( ) ,
@@ -471,7 +480,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
471480 self . cx . force_mode = force;
472481
473482 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 ) {
475484 ExpandResult :: Ready ( fragment) => {
476485 let mut derive_invocations = Vec :: new ( ) ;
477486 let derive_placeholders = self
@@ -503,12 +512,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
503512 } )
504513 . unwrap_or_default ( ) ;
505514
506- let ( fragment , collected_invocations) =
515+ let ( expanded_fragment , collected_invocations) =
507516 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.
510520 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 ( ) ) ;
512528 }
513529 ExpandResult :: Retry ( invoc) => {
514530 if force {
@@ -519,17 +535,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
519535 } else {
520536 // Cannot expand, will retry this invocation later.
521537 undetermined_invocations. push ( ( invoc, Some ( ext) ) ) ;
522- continue ;
523538 }
524539 }
525- } ;
526-
527- progress = true ;
528- if expanded_fragments. len ( ) < depth {
529- expanded_fragments. push ( Vec :: new ( ) ) ;
530540 }
531- expanded_fragments[ depth - 1 ] . push ( ( expn_id, expanded_fragment) ) ;
532- invocations. extend ( new_invocations. into_iter ( ) . rev ( ) ) ;
533541 }
534542
535543 self . cx . current_expansion = orig_expansion_data;
@@ -590,11 +598,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
590598 for ( invoc, _) in invocations. iter_mut ( ) {
591599 let expn_id = invoc. expansion_data . id ;
592600 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 ( ) ;
598602 * span = span. with_parent ( Some ( parent_def) ) ;
599603 }
600604 }
@@ -957,7 +961,7 @@ pub fn parse_ast_fragment<'a>(
957961 } )
958962}
959963
960- pub fn ensure_complete_parse < ' a > (
964+ pub ( crate ) fn ensure_complete_parse < ' a > (
961965 parser : & Parser < ' a > ,
962966 macro_path : & ast:: Path ,
963967 kind_name : & str ,
0 commit comments