File tree 1 file changed +12
-7
lines changed
1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -54,12 +54,6 @@ pub struct Expander {
54
54
recursion_limit : usize ,
55
55
}
56
56
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
-
63
57
impl CfgExpander {
64
58
pub ( crate ) fn new (
65
59
db : & dyn DefDatabase ,
@@ -101,7 +95,7 @@ impl Expander {
101
95
db : & dyn DefDatabase ,
102
96
macro_call : ast:: MacroCall ,
103
97
) -> 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 ( ) {
105
99
cov_mark:: hit!( your_stack_belongs_to_me) ;
106
100
return Ok ( ExpandResult :: str_err (
107
101
"reached recursion limit during macro expansion" . into ( ) ,
@@ -222,6 +216,17 @@ impl Expander {
222
216
let file_local_id = self . ast_id_map . ast_id ( item) ;
223
217
AstId :: new ( self . current_file_id , file_local_id)
224
218
}
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
+ }
225
230
}
226
231
227
232
#[ derive( Debug ) ]
You can’t perform that action at this time.
0 commit comments