@@ -404,6 +404,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
404
404
// Recursively expand all macro invocations in this AST fragment.
405
405
pub fn fully_expand_fragment ( & mut self , input_fragment : AstFragment ) -> AstFragment {
406
406
let orig_expansion_data = self . cx . current_expansion . clone ( ) ;
407
+ let orig_force_mode = self . cx . force_mode ;
407
408
self . cx . current_expansion . depth = 0 ;
408
409
409
410
// Collect all macro invocations and replace them with placeholders.
@@ -432,6 +433,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
432
433
}
433
434
invocations = mem:: take ( & mut undetermined_invocations) ;
434
435
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
+ }
435
442
continue ;
436
443
} ;
437
444
@@ -460,18 +467,18 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
460
467
461
468
let ExpansionData { depth, id : expn_id, .. } = invoc. expansion_data ;
462
469
self . cx . current_expansion = invoc. expansion_data . clone ( ) ;
470
+ self . cx . force_mode = force;
463
471
464
472
// FIXME(jseyfried): Refactor out the following logic
465
473
let ( expanded_fragment, new_invocations) = match res {
466
474
InvocationRes :: Single ( ext) => match self . expand_invoc ( invoc, & ext. kind ) {
467
475
ExpandResult :: Ready ( fragment) => self . collect_invocations ( fragment, & [ ] ) ,
468
- ExpandResult :: Retry ( invoc, explanation ) => {
476
+ ExpandResult :: Retry ( invoc) => {
469
477
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
+ ) ;
475
482
} else {
476
483
// Cannot expand, will retry this invocation later.
477
484
undetermined_invocations
@@ -526,6 +533,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
526
533
}
527
534
528
535
self . cx . current_expansion = orig_expansion_data;
536
+ self . cx . force_mode = orig_force_mode;
529
537
530
538
// Finally incorporate all the expanded macros into the input AST fragment.
531
539
let mut placeholder_expander = PlaceholderExpander :: new ( self . cx , self . monotonic ) ;
@@ -735,20 +743,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
735
743
Ok ( meta) => {
736
744
let items = match expander. expand ( self . cx , span, & meta, item) {
737
745
ExpandResult :: Ready ( items) => items,
738
- ExpandResult :: Retry ( item, explanation ) => {
746
+ ExpandResult :: Retry ( item) => {
739
747
// 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,
749
754
} ,
750
- explanation ,
751
- ) ;
755
+ ..invoc
756
+ } ) ;
752
757
}
753
758
} ;
754
759
fragment_kind. expect_from_annotatables ( items)
@@ -781,15 +786,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
781
786
let meta = ast:: MetaItem { kind : ast:: MetaItemKind :: Word , span, path } ;
782
787
let items = match expander. expand ( self . cx , span, & meta, item) {
783
788
ExpandResult :: Ready ( items) => items,
784
- ExpandResult :: Retry ( item, explanation ) => {
789
+ ExpandResult :: Retry ( item) => {
785
790
// 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
+ } ) ;
793
795
}
794
796
} ;
795
797
fragment_kind. expect_from_annotatables ( items)
0 commit comments