File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -54,12 +54,6 @@ pub struct Expander {
5454 recursion_limit : usize ,
5555}
5656
57- #[ cfg( test) ]
58- static EXPANSION_RECURSION_LIMIT : Limit = Limit :: new ( 32 ) ;
59-
60- #[ cfg( not( test) ) ]
61- static EXPANSION_RECURSION_LIMIT : Limit = Limit :: new ( 128 ) ;
62-
6357impl CfgExpander {
6458 pub ( crate ) fn new (
6559 db : & dyn DefDatabase ,
@@ -101,7 +95,7 @@ impl Expander {
10195 db : & dyn DefDatabase ,
10296 macro_call : ast:: MacroCall ,
10397 ) -> Result < ExpandResult < Option < ( Mark , T ) > > , UnresolvedMacro > {
104- if EXPANSION_RECURSION_LIMIT . check ( self . recursion_limit + 1 ) . is_err ( ) {
98+ if self . recursion_limit ( db ) . check ( self . recursion_limit + 1 ) . is_err ( ) {
10599 cov_mark:: hit!( your_stack_belongs_to_me) ;
106100 return Ok ( ExpandResult :: str_err (
107101 "reached recursion limit during macro expansion" . into ( ) ,
@@ -222,6 +216,17 @@ impl Expander {
222216 let file_local_id = self . ast_id_map . ast_id ( item) ;
223217 AstId :: new ( self . current_file_id , file_local_id)
224218 }
219+
220+ fn recursion_limit ( & self , db : & dyn DefDatabase ) -> Limit {
221+ let limit = db. crate_limits ( self . cfg_expander . krate ) . recursion_limit as _ ;
222+
223+ #[ cfg( not( test) ) ]
224+ return Limit :: new ( limit) ;
225+
226+ // Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug
227+ #[ cfg( test) ]
228+ return Limit :: new ( std:: cmp:: min ( 32 , limit) ) ;
229+ }
225230}
226231
227232#[ derive( Debug ) ]
You can’t perform that action at this time.
0 commit comments