@@ -17,7 +17,7 @@ use rustc_ast::util::map_in_place::MapInPlace;
17
17
use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
18
18
use rustc_ast_pretty:: pprust;
19
19
use rustc_attr:: { self as attr, is_builtin_attr, HasAttrs } ;
20
- use rustc_errors:: { Applicability , FatalError , PResult } ;
20
+ use rustc_errors:: { Applicability , PResult } ;
21
21
use rustc_feature:: Features ;
22
22
use rustc_parse:: parser:: Parser ;
23
23
use rustc_parse:: validate_attr;
@@ -645,7 +645,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
645
645
) )
646
646
. emit ( ) ;
647
647
self . cx . trace_macros_diag ( ) ;
648
- FatalError . raise ( ) ;
649
648
}
650
649
651
650
/// A macro's expansion does not fit in this fragment kind.
@@ -665,8 +664,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
665
664
invoc : Invocation ,
666
665
ext : & SyntaxExtensionKind ,
667
666
) -> 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 ( ) ) ) ;
670
678
}
671
679
672
680
let ( fragment_kind, span) = ( invoc. fragment_kind , invoc. span ( ) ) ;
0 commit comments