@@ -404,6 +404,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
404404 // Recursively expand all macro invocations in this AST fragment.
405405 pub fn fully_expand_fragment ( & mut self , input_fragment : AstFragment ) -> AstFragment {
406406 let orig_expansion_data = self . cx . current_expansion . clone ( ) ;
407+ let orig_force_mode = self . cx . force_mode ;
407408 self . cx . current_expansion . depth = 0 ;
408409
409410 // Collect all macro invocations and replace them with placeholders.
@@ -432,6 +433,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
432433 }
433434 invocations = mem:: take ( & mut undetermined_invocations) ;
434435 force = !mem:: replace ( & mut progress, false ) ;
436+ if force && self . monotonic {
437+ self . cx . sess . delay_span_bug (
438+ invocations. last ( ) . unwrap ( ) . 0 . span ( ) ,
439+ "expansion entered force mode without producing any errors" ,
440+ ) ;
441+ }
435442 continue ;
436443 } ;
437444
@@ -460,18 +467,18 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
460467
461468 let ExpansionData { depth, id : expn_id, .. } = invoc. expansion_data ;
462469 self . cx . current_expansion = invoc. expansion_data . clone ( ) ;
470+ self . cx . force_mode = force;
463471
464472 // FIXME(jseyfried): Refactor out the following logic
465473 let ( expanded_fragment, new_invocations) = match res {
466474 InvocationRes :: Single ( ext) => match self . expand_invoc ( invoc, & ext. kind ) {
467475 ExpandResult :: Ready ( fragment) => self . collect_invocations ( fragment, & [ ] ) ,
468- ExpandResult :: Retry ( invoc, explanation ) => {
476+ ExpandResult :: Retry ( invoc) => {
469477 if force {
470- // We are stuck, stop retrying and produce a dummy fragment.
471- let span = invoc. span ( ) ;
472- self . cx . span_err ( span, & explanation) ;
473- let fragment = invoc. fragment_kind . dummy ( span) ;
474- self . collect_invocations ( fragment, & [ ] )
478+ self . cx . span_bug (
479+ invoc. span ( ) ,
480+ "expansion entered force mode but is still stuck" ,
481+ ) ;
475482 } else {
476483 // Cannot expand, will retry this invocation later.
477484 undetermined_invocations
@@ -526,6 +533,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
526533 }
527534
528535 self . cx . current_expansion = orig_expansion_data;
536+ self . cx . force_mode = orig_force_mode;
529537
530538 // Finally incorporate all the expanded macros into the input AST fragment.
531539 let mut placeholder_expander = PlaceholderExpander :: new ( self . cx , self . monotonic ) ;
@@ -735,20 +743,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
735743 Ok ( meta) => {
736744 let items = match expander. expand ( self . cx , span, & meta, item) {
737745 ExpandResult :: Ready ( items) => items,
738- ExpandResult :: Retry ( item, explanation ) => {
746+ ExpandResult :: Retry ( item) => {
739747 // Reassemble the original invocation for retrying.
740- return ExpandResult :: Retry (
741- Invocation {
742- kind : InvocationKind :: Attr {
743- attr,
744- item,
745- derives,
746- after_derive,
747- } ,
748- ..invoc
748+ return ExpandResult :: Retry ( Invocation {
749+ kind : InvocationKind :: Attr {
750+ attr,
751+ item,
752+ derives,
753+ after_derive,
749754 } ,
750- explanation ,
751- ) ;
755+ ..invoc
756+ } ) ;
752757 }
753758 } ;
754759 fragment_kind. expect_from_annotatables ( items)
@@ -781,15 +786,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
781786 let meta = ast:: MetaItem { kind : ast:: MetaItemKind :: Word , span, path } ;
782787 let items = match expander. expand ( self . cx , span, & meta, item) {
783788 ExpandResult :: Ready ( items) => items,
784- ExpandResult :: Retry ( item, explanation ) => {
789+ ExpandResult :: Retry ( item) => {
785790 // Reassemble the original invocation for retrying.
786- return ExpandResult :: Retry (
787- Invocation {
788- kind : InvocationKind :: Derive { path : meta. path , item } ,
789- ..invoc
790- } ,
791- explanation,
792- ) ;
791+ return ExpandResult :: Retry ( Invocation {
792+ kind : InvocationKind :: Derive { path : meta. path , item } ,
793+ ..invoc
794+ } ) ;
793795 }
794796 } ;
795797 fragment_kind. expect_from_annotatables ( items)
0 commit comments