aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src/db.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-10 18:14:17 +0000
committerGitHub <[email protected]>2020-12-10 18:14:17 +0000
commit814e31957ea0e063272132afd15c3e8f4ed54454 (patch)
tree5cda6ebbeb109d3f04ad9f81b5f21344e2a65471 /crates/hir_expand/src/db.rs
parent6095debda842a84904398e410589669dda51cf14 (diff)
parent829d9d36ebd3b86f447b12ba573cf3e6cb5b0373 (diff)
Merge #6804
6804: Bump the macro token limit r=jonas-schievink a=jonas-schievink Should fix https://github.com/rust-analyzer/rust-analyzer/issues/6504 Not entirely sure what the previous limit was based on, but it looks like it does get hit in practice. Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_expand/src/db.rs')
-rw-r--r--crates/hir_expand/src/db.rs12
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..ffb70f723 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.
20const TOKEN_LIMIT: usize = 524288;
21
16#[derive(Debug, Clone, Eq, PartialEq)] 22#[derive(Debug, Clone, Eq, PartialEq)]
17pub enum TokenExpander { 23pub 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, &macro_arg.0); 233 let ExpandResult { value: tt, err } = macro_rules.0.expand(db, lazy_id, &macro_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