Skip to content

Commit 12a3d01

Browse files
committed
Auto merge of rust-lang#17833 - edevil:fix_expansion_limit, r=Veykril
Reuse recursion limit as expansion limit A configurable recursion limit was introduced by looking at the recursion_limit crate attribute. Instead of relying on a global constant we will reuse this value for expansion limit as well. Addresses: rust-lang/rust-analyzer#8640 (comment)
2 parents 3ef56c2 + e6d426e commit 12a3d01

File tree

1 file changed

+8
-2
lines changed
  • src/tools/rust-analyzer/crates/hir-def/src/nameres

1 file changed

+8
-2
lines changed

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use crate::{
5656
};
5757

5858
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
59-
static EXPANSION_DEPTH_LIMIT: Limit = Limit::new(128);
6059
static FIXED_POINT_LIMIT: Limit = Limit::new(8192);
6160

6261
pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeId) -> DefMap {
@@ -1440,7 +1439,14 @@ impl DefCollector<'_> {
14401439
depth: usize,
14411440
container: ItemContainerId,
14421441
) {
1443-
if EXPANSION_DEPTH_LIMIT.check(depth).is_err() {
1442+
let recursion_limit = self.def_map.recursion_limit() as usize;
1443+
let recursion_limit = Limit::new(if cfg!(test) {
1444+
// Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug
1445+
std::cmp::min(32, recursion_limit)
1446+
} else {
1447+
recursion_limit
1448+
});
1449+
if recursion_limit.check(depth).is_err() {
14441450
cov_mark::hit!(macro_expansion_overflow);
14451451
tracing::warn!("macro expansion is too deep");
14461452
return;

0 commit comments

Comments
 (0)