Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/collector.rs')
| -rw-r--r-- | crates/hir-def/src/nameres/collector.rs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 06276335b7..16f3fd56eb 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -19,7 +19,6 @@ use hir_expand::{ use intern::{sym, Interned}; use itertools::{izip, Itertools}; use la_arena::Idx; -use limit::Limit; use rustc_hash::{FxHashMap, FxHashSet}; use span::{Edition, EditionedFileId, FileAstId, SyntaxContextId}; use syntax::ast; @@ -55,8 +54,8 @@ use crate::{ UnresolvedMacro, UseId, UseLoc, }; -static GLOB_RECURSION_LIMIT: Limit = Limit::new(100); -static FIXED_POINT_LIMIT: Limit = Limit::new(8192); +const GLOB_RECURSION_LIMIT: usize = 100; +const FIXED_POINT_LIMIT: usize = 8192; pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeId) -> DefMap { let crate_graph = db.crate_graph(); @@ -393,7 +392,7 @@ impl DefCollector<'_> { } i += 1; - if FIXED_POINT_LIMIT.check(i).is_err() { + if i > FIXED_POINT_LIMIT { tracing::error!("name resolution is stuck"); break 'resolve_attr; } @@ -993,7 +992,7 @@ impl DefCollector<'_> { import: Option<ImportOrExternCrate>, depth: usize, ) { - if GLOB_RECURSION_LIMIT.check(depth).is_err() { + if depth > GLOB_RECURSION_LIMIT { // prevent stack overflows (but this shouldn't be possible) panic!("infinite recursion in glob imports!"); } @@ -1470,8 +1469,7 @@ impl DefCollector<'_> { depth: usize, container: ItemContainerId, ) { - let recursion_limit = Limit::new(self.def_map.recursion_limit() as usize); - if recursion_limit.check(depth).is_err() { + if depth > self.def_map.recursion_limit() as usize { cov_mark::hit!(macro_expansion_overflow); tracing::warn!("macro expansion is too deep"); return; @@ -1499,7 +1497,6 @@ impl DefCollector<'_> { fn finish(mut self) -> DefMap { // Emit diagnostics for all remaining unexpanded macros. - let _p = tracing::info_span!("DefCollector::finish").entered(); for directive in &self.unresolved_macros { @@ -1759,16 +1756,20 @@ impl ModCollector<'_, '_> { ); } } - ModItem::ExternBlock(block) => self.collect( - &self.item_tree[block].children, - ItemContainerId::ExternBlockId( - ExternBlockLoc { - container: module, - id: ItemTreeId::new(self.tree_id, block), - } - .intern(db), - ), - ), + ModItem::ExternBlock(block) => { + let extern_block_id = ExternBlockLoc { + container: module, + id: ItemTreeId::new(self.tree_id, block), + } + .intern(db); + self.def_collector.def_map.modules[self.module_id] + .scope + .define_extern_block(extern_block_id); + self.collect( + &self.item_tree[block].children, + ItemContainerId::ExternBlockId(extern_block_id), + ) + } ModItem::MacroCall(mac) => self.collect_macro_call(&self.item_tree[mac], container), ModItem::MacroRules(id) => self.collect_macro_rules(id, module), ModItem::Macro2(id) => self.collect_macro_def(id, module), |