mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Use crate_limits
query in macro expansion
This commit is contained in:
parent
c932ca5f1c
commit
81211f538c
1 changed files with 12 additions and 7 deletions
|
@ -54,12 +54,6 @@ pub struct Expander {
|
|||
recursion_limit: usize,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
static EXPANSION_RECURSION_LIMIT: Limit = Limit::new(32);
|
||||
|
||||
#[cfg(not(test))]
|
||||
static EXPANSION_RECURSION_LIMIT: Limit = Limit::new(128);
|
||||
|
||||
impl CfgExpander {
|
||||
pub(crate) fn new(
|
||||
db: &dyn DefDatabase,
|
||||
|
@ -101,7 +95,7 @@ impl Expander {
|
|||
db: &dyn DefDatabase,
|
||||
macro_call: ast::MacroCall,
|
||||
) -> Result<ExpandResult<Option<(Mark, T)>>, UnresolvedMacro> {
|
||||
if EXPANSION_RECURSION_LIMIT.check(self.recursion_limit + 1).is_err() {
|
||||
if self.recursion_limit(db).check(self.recursion_limit + 1).is_err() {
|
||||
cov_mark::hit!(your_stack_belongs_to_me);
|
||||
return Ok(ExpandResult::str_err(
|
||||
"reached recursion limit during macro expansion".into(),
|
||||
|
@ -222,6 +216,17 @@ impl Expander {
|
|||
let file_local_id = self.ast_id_map.ast_id(item);
|
||||
AstId::new(self.current_file_id, file_local_id)
|
||||
}
|
||||
|
||||
fn recursion_limit(&self, db: &dyn DefDatabase) -> Limit {
|
||||
let limit = db.crate_limits(self.cfg_expander.krate).recursion_limit as _;
|
||||
|
||||
#[cfg(not(test))]
|
||||
return Limit::new(limit);
|
||||
|
||||
// Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug
|
||||
#[cfg(test)]
|
||||
return Limit::new(std::cmp::min(32, limit));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Reference in a new issue