From 63aba76735c387c15230039b9ac7712a18962cb7 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 9 Aug 2023 17:06:52 +0200 Subject: [PATCH] Remove unnecessary ItemTreeId field in ImportSource --- crates/hir-def/src/nameres/collector.rs | 26 ++++++++----------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 9a7e6bdcc8a..92d5cdd09bd 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -144,19 +144,10 @@ fn namespaces(self) -> PerNs { } } -// FIXME: `item_tree_id` can be derived from `id`, look into deduplicating this #[derive(Clone, Debug, Eq, PartialEq)] enum ImportSource { - Use { - item_tree_id: ItemTreeId, - use_tree: Idx, - id: UseId, - is_prelude: bool, - }, - ExternCrate { - item_tree_id: ItemTreeId, - id: ExternCrateId, - }, + Use { use_tree: Idx, id: UseId, is_prelude: bool }, + ExternCrate { id: ExternCrateId }, } #[derive(Debug, Eq, PartialEq)] @@ -184,7 +175,7 @@ fn from_use( alias, visibility: visibility.clone(), kind, - source: ImportSource::Use { item_tree_id, use_tree: idx, id, is_prelude }, + source: ImportSource::Use { use_tree: idx, id, is_prelude }, }); }); } @@ -201,7 +192,7 @@ fn from_extern_crate( alias: it.alias.clone(), visibility: visibility.clone(), kind: ImportKind::Plain, - source: ImportSource::ExternCrate { item_tree_id, id }, + source: ImportSource::ExternCrate { id }, } } } @@ -1469,7 +1460,8 @@ fn finish(mut self) -> DefMap { // heuristic, but it works in practice. let mut diagnosed_extern_crates = FxHashSet::default(); for directive in &self.unresolved_imports { - if let ImportSource::ExternCrate { item_tree_id, id: _ } = directive.import.source { + if let ImportSource::ExternCrate { id } = directive.import.source { + let item_tree_id = self.db.lookup_intern_extern_crate(id).id; let item_tree = item_tree_id.item_tree(self.db); let extern_crate = &item_tree[item_tree_id.value]; @@ -1483,16 +1475,14 @@ fn finish(mut self) -> DefMap { } for directive in &self.unresolved_imports { - if let ImportSource::Use { item_tree_id, use_tree, id: _, is_prelude: _ } = - directive.import.source - { + if let ImportSource::Use { use_tree, id, is_prelude: _ } = directive.import.source { if matches!( (directive.import.path.segments().first(), &directive.import.path.kind), (Some(krate), PathKind::Plain | PathKind::Abs) if diagnosed_extern_crates.contains(krate) ) { continue; } - + let item_tree_id = self.db.lookup_intern_use(id).id; self.def_map.diagnostics.push(DefDiagnostic::unresolved_import( directive.module_id, item_tree_id,