mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 22:24:14 +00:00
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 <jonasschievink@gmail.com>
This commit is contained in:
commit
814e31957e
1 changed files with 9 additions and 3 deletions
|
@ -13,6 +13,12 @@ use crate::{
|
||||||
MacroFile, ProcMacroExpander,
|
MacroFile, ProcMacroExpander,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Total limit on the number of tokens produced by any macro invocation.
|
||||||
|
///
|
||||||
|
/// If an invocation produces more tokens than this limit, it will not be stored in the database and
|
||||||
|
/// an error will be emitted.
|
||||||
|
const TOKEN_LIMIT: usize = 524288;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum TokenExpander {
|
pub enum TokenExpander {
|
||||||
MacroRules(mbe::MacroRules),
|
MacroRules(mbe::MacroRules),
|
||||||
|
@ -227,10 +233,10 @@ fn macro_expand_with_arg(
|
||||||
let ExpandResult { value: tt, err } = macro_rules.0.expand(db, lazy_id, ¯o_arg.0);
|
let ExpandResult { value: tt, err } = macro_rules.0.expand(db, lazy_id, ¯o_arg.0);
|
||||||
// Set a hard limit for the expanded tt
|
// Set a hard limit for the expanded tt
|
||||||
let count = tt.count();
|
let count = tt.count();
|
||||||
if count > 262144 {
|
if count > TOKEN_LIMIT {
|
||||||
return ExpandResult::str_err(format!(
|
return ExpandResult::str_err(format!(
|
||||||
"Total tokens count exceed limit : count = {}",
|
"macro invocation exceeds token limit: produced {} tokens, limit is {}",
|
||||||
count
|
count, TOKEN_LIMIT,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue