diff options
| author | bors <bors@rust-lang.org> | 2024-08-12 08:22:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-12 08:22:55 +0000 |
| commit | 12a3d0112c0301f4c6b6d8e7b927fcd8395834d9 (patch) | |
| tree | 1c72cb6d70bab555d1ad32e73b766e49c34c7b63 | |
| parent | 3ef56c2bb8617df0f789d54ac2bab31a85e1c8e9 (diff) | |
| parent | e6d426e723dcd6fcbe50bb561e7d38564f758477 (diff) | |
| download | rust-12a3d0112c0301f4c6b6d8e7b927fcd8395834d9.tar.gz rust-12a3d0112c0301f4c6b6d8e7b927fcd8395834d9.zip | |
Auto merge of #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: https://github.com/rust-lang/rust-analyzer/issues/8640#issuecomment-2271740272
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs index d970dbac1c2..debc5a44326 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs @@ -56,7 +56,6 @@ use crate::{ }; static GLOB_RECURSION_LIMIT: Limit = Limit::new(100); -static EXPANSION_DEPTH_LIMIT: Limit = Limit::new(128); static FIXED_POINT_LIMIT: Limit = Limit::new(8192); pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeId) -> DefMap { @@ -1440,7 +1439,14 @@ impl DefCollector<'_> { depth: usize, container: ItemContainerId, ) { - if EXPANSION_DEPTH_LIMIT.check(depth).is_err() { + let recursion_limit = self.def_map.recursion_limit() as usize; + let recursion_limit = Limit::new(if cfg!(test) { + // Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug + std::cmp::min(32, recursion_limit) + } else { + recursion_limit + }); + if recursion_limit.check(depth).is_err() { cov_mark::hit!(macro_expansion_overflow); tracing::warn!("macro expansion is too deep"); return; |
