11use crate :: base:: * ;
22use crate :: config:: StripUnconfigured ;
33use crate :: errors:: {
4- IncompleteParse , RecursionLimitReached , RemoveExprNotSupported , RemoveNodeNotSupported ,
5- UnsupportedKeyValue , WrongFragmentKind ,
4+ ExpansionGrowthLimitReached , IncompleteParse , RecursionLimitReached , RemoveExprNotSupported ,
5+ RemoveNodeNotSupported , UnsupportedKeyValue , WrongFragmentKind ,
66} ;
77use crate :: hygiene:: SyntaxContext ;
88use crate :: mbe:: diagnostics:: annotate_err_with_kind;
@@ -628,20 +628,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
628628 limit => limit * 2 ,
629629 } ;
630630
631- self . cx
632- . struct_span_err (
633- expn_data. call_site ,
634- & format ! (
635- "expansion grow limit reached while expanding `{}`" ,
636- expn_data. kind. descr( )
637- ) ,
638- )
639- . help ( & format ! (
640- "consider increasing the expansion grow limit by adding a \
641- `#![expansion_growth_limit = \" {}\" ]` attribute to your crate (`{}`)",
642- suggested_limit, self . cx. ecfg. crate_name,
643- ) )
644- . emit ( ) ;
631+ self . cx . emit_err ( ExpansionGrowthLimitReached {
632+ span : expn_data. call_site ,
633+ descr : expn_data. kind . descr ( ) ,
634+ suggested_limit,
635+ crate_name : & self . cx . ecfg . crate_name ,
636+ } ) ;
645637 self . cx . trace_macros_diag ( ) ;
646638 }
647639
@@ -663,7 +655,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
663655
664656 // Reduce the recursion limit by half each time it triggers.
665657 self . cx . reduced_recursion_limit = Some ( expansion_limit / 2 ) ;
666-
667658 return Err ( ( ) ) ;
668659 }
669660 Ok ( ( ) )
@@ -697,11 +688,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
697688 self . parse_ast_fragment ( tok_result, fragment_kind, & mac. path , span)
698689 }
699690 SyntaxExtensionKind :: LegacyBang ( expander) => {
700- if self . reduce_expansion_growth_limit ( mac. args . inner_tokens ( ) . len ( ) ) . is_err ( ) {
691+ if self . reduce_expansion_growth_limit ( mac. args . tokens . len ( ) ) . is_err ( ) {
701692 return ExpandResult :: Ready ( fragment_kind. dummy ( span) ) ;
702693 }
703- let prev = self . cx . current_expansion . prior_type_ascription ;
704- self . cx . current_expansion . prior_type_ascription = mac. prior_type_ascription ;
705694 let tok_result = expander. expand ( self . cx , span, mac. args . tokens . clone ( ) ) ;
706695 let result = if let Some ( result) = fragment_kind. make_from ( tok_result) {
707696 result
@@ -2027,7 +2016,7 @@ impl<'feat> ExpansionConfig<'feat> {
20272016 crate_name,
20282017 features : None ,
20292018 recursion_limit : Limit :: new ( 1024 ) ,
2030- expansion_growth_limit : Limit :: new ( 6000 ) ,
2019+ expansion_growth_limit : Limit :: new ( 1000000 ) ,
20312020 trace_mac : false ,
20322021 should_test : false ,
20332022 span_debug : false ,
0 commit comments