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::{
1313 MacroFile , ProcMacroExpander ,
1414} ;
1515
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+
1622#[ derive( Debug , Clone , Eq , PartialEq ) ]
1723pub enum TokenExpander {
1824 MacroRules ( mbe:: MacroRules ) ,
@@ -227,10 +233,10 @@ fn macro_expand_with_arg(
227233 let ExpandResult { value : tt, err } = macro_rules. 0 . expand ( db, lazy_id, & macro_arg. 0 ) ;
228234 // Set a hard limit for the expanded tt
229235 let count = tt. count ( ) ;
230- if count > 262144 {
236+ if count > TOKEN_LIMIT {
231237 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 ,
234240 ) ) ;
235241 }
236242
You can’t perform that action at this time.
0 commit comments