File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ use crate::{
13
13
MacroFile , ProcMacroExpander ,
14
14
} ;
15
15
16
+ /// Total limit on the number of tokens produced by any macro invocation.
17
+ ///
18
+ /// If an invocation produces more tokens than this limit, it will not be stored in the database and
19
+ /// an error will be emitted.
20
+ const TOKEN_LIMIT : usize = 262144 ;
21
+
16
22
#[ derive( Debug , Clone , Eq , PartialEq ) ]
17
23
pub enum TokenExpander {
18
24
MacroRules ( mbe:: MacroRules ) ,
@@ -227,10 +233,10 @@ fn macro_expand_with_arg(
227
233
let ExpandResult { value : tt, err } = macro_rules. 0 . expand ( db, lazy_id, & macro_arg. 0 ) ;
228
234
// Set a hard limit for the expanded tt
229
235
let count = tt. count ( ) ;
230
- if count > 262144 {
236
+ if count > TOKEN_LIMIT {
231
237
return ExpandResult :: str_err ( format ! (
232
- "Total tokens count exceed limit : count = {}" ,
233
- count
238
+ "macro invocation exceeds token limit: produced {} tokens, limit is {}" ,
239
+ count, TOKEN_LIMIT ,
234
240
) ) ;
235
241
}
236
242
You can’t perform that action at this time.
0 commit comments