aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres/collector.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/nameres/collector.rs')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 6494b653a..d85a86c0a 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -36,6 +36,10 @@ use crate::{
36 TraitLoc, TypeAliasLoc, UnionLoc, 36 TraitLoc, TypeAliasLoc, UnionLoc,
37}; 37};
38 38
39const GLOB_RECURSION_LIMIT: usize = 100;
40const EXPANSION_DEPTH_LIMIT: usize = 128;
41const FIXED_POINT_LIMIT: usize = 8192;
42
39pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 43pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
40 let crate_graph = db.crate_graph(); 44 let crate_graph = db.crate_graph();
41 45
@@ -217,7 +221,7 @@ impl DefCollector<'_> {
217 ReachedFixedPoint::Yes => break, 221 ReachedFixedPoint::Yes => break,
218 ReachedFixedPoint::No => i += 1, 222 ReachedFixedPoint::No => i += 1,
219 } 223 }
220 if i == 10000 { 224 if i == FIXED_POINT_LIMIT {
221 log::error!("name resolution is stuck"); 225 log::error!("name resolution is stuck");
222 break; 226 break;
223 } 227 }
@@ -587,7 +591,7 @@ impl DefCollector<'_> {
587 import_type: ImportType, 591 import_type: ImportType,
588 depth: usize, 592 depth: usize,
589 ) { 593 ) {
590 if depth > 100 { 594 if depth > GLOB_RECURSION_LIMIT {
591 // prevent stack overflows (but this shouldn't be possible) 595 // prevent stack overflows (but this shouldn't be possible)
592 panic!("infinite recursion in glob imports!"); 596 panic!("infinite recursion in glob imports!");
593 } 597 }
@@ -679,10 +683,6 @@ impl DefCollector<'_> {
679 self.unexpanded_attribute_macros = attribute_macros; 683 self.unexpanded_attribute_macros = attribute_macros;
680 684
681 for (module_id, macro_call_id, depth) in resolved { 685 for (module_id, macro_call_id, depth) in resolved {
682 if depth > 1024 {
683 log::debug!("Max macro expansion depth reached");
684 continue;
685 }
686 self.collect_macro_expansion(module_id, macro_call_id, depth); 686 self.collect_macro_expansion(module_id, macro_call_id, depth);
687 } 687 }
688 688
@@ -719,7 +719,7 @@ impl DefCollector<'_> {
719 macro_call_id: MacroCallId, 719 macro_call_id: MacroCallId,
720 depth: usize, 720 depth: usize,
721 ) { 721 ) {
722 if depth > 100 { 722 if depth > EXPANSION_DEPTH_LIMIT {
723 mark::hit!(macro_expansion_overflow); 723 mark::hit!(macro_expansion_overflow);
724 log::warn!("macro expansion is too deep"); 724 log::warn!("macro expansion is too deep");
725 return; 725 return;