diff options
Diffstat (limited to 'crates/hir_expand/src/db.rs')
-rw-r--r-- | crates/hir_expand/src/db.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index 842a177db..3c0ee284e 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs | |||
@@ -13,6 +13,12 @@ use crate::{ | |||
13 | MacroFile, ProcMacroExpander, | 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 | #[derive(Debug, Clone, Eq, PartialEq)] | 22 | #[derive(Debug, Clone, Eq, PartialEq)] |
17 | pub enum TokenExpander { | 23 | pub enum TokenExpander { |
18 | MacroRules(mbe::MacroRules), | 24 | MacroRules(mbe::MacroRules), |
@@ -227,10 +233,10 @@ fn macro_expand_with_arg( | |||
227 | let ExpandResult { value: tt, err } = macro_rules.0.expand(db, lazy_id, ¯o_arg.0); | 233 | let ExpandResult { value: tt, err } = macro_rules.0.expand(db, lazy_id, ¯o_arg.0); |
228 | // Set a hard limit for the expanded tt | 234 | // Set a hard limit for the expanded tt |
229 | let count = tt.count(); | 235 | let count = tt.count(); |
230 | if count > 262144 { | 236 | if count > TOKEN_LIMIT { |
231 | return ExpandResult::str_err(format!( | 237 | return ExpandResult::str_err(format!( |
232 | "Total tokens count exceed limit : count = {}", | 238 | "macro invocation exceeds token limit: produced {} tokens, limit is {}", |
233 | count | 239 | count, TOKEN_LIMIT, |
234 | )); | 240 | )); |
235 | } | 241 | } |
236 | 242 | ||