@@ -17,7 +17,7 @@ use rustc_ast::util::map_in_place::MapInPlace;
1717use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
1818use rustc_ast_pretty:: pprust;
1919use rustc_attr:: { self as attr, is_builtin_attr, HasAttrs } ;
20- use rustc_errors:: { Applicability , FatalError , PResult } ;
20+ use rustc_errors:: { Applicability , PResult } ;
2121use rustc_feature:: Features ;
2222use rustc_parse:: parser:: Parser ;
2323use rustc_parse:: validate_attr;
@@ -645,7 +645,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
645645 ) )
646646 . emit ( ) ;
647647 self . cx . trace_macros_diag ( ) ;
648- FatalError . raise ( ) ;
649648 }
650649
651650 /// A macro's expansion does not fit in this fragment kind.
@@ -665,8 +664,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
665664 invoc : Invocation ,
666665 ext : & SyntaxExtensionKind ,
667666 ) -> ExpandResult < AstFragment , Invocation > {
668- if self . cx . current_expansion . depth > self . cx . ecfg . recursion_limit {
669- self . error_recursion_limit_reached ( ) ;
667+ let recursion_limit =
668+ self . cx . reduced_recursion_limit . unwrap_or ( self . cx . ecfg . recursion_limit ) ;
669+ if self . cx . current_expansion . depth > recursion_limit {
670+ if self . cx . reduced_recursion_limit . is_none ( ) {
671+ self . error_recursion_limit_reached ( ) ;
672+ }
673+
674+ // Reduce the recursion limit by half each time it triggers.
675+ self . cx . reduced_recursion_limit = Some ( recursion_limit / 2 ) ;
676+
677+ return ExpandResult :: Ready ( invoc. fragment_kind . dummy ( invoc. span ( ) ) ) ;
670678 }
671679
672680 let ( fragment_kind, span) = ( invoc. fragment_kind , invoc. span ( ) ) ;
0 commit comments