Skip to content

Commit d4a3719

Browse files
committed
Remove ItemTreeId
1 parent 80dd145 commit d4a3719

File tree

4 files changed

+52
-86
lines changed

4 files changed

+52
-86
lines changed

src/tools/rust-analyzer/crates/hir-def/src/attr.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,15 @@ impl AttrsWithOwner {
523523
let mod_data = &def_map[module.local_id];
524524

525525
let raw_attrs = match mod_data.origin {
526-
ModuleOrigin::File { definition, declaration_tree_id, .. } => {
526+
ModuleOrigin::File {
527+
definition,
528+
declaration_tree_id,
529+
file_item_tree_id,
530+
..
531+
} => {
527532
let decl_attrs = declaration_tree_id
528533
.item_tree(db)
529-
.raw_attrs(AttrOwner::ModItem(declaration_tree_id.value.into()))
534+
.raw_attrs(AttrOwner::ModItem(file_item_tree_id.into()))
530535
.clone();
531536
let tree = db.file_item_tree(definition.into());
532537
let def_attrs = tree.raw_attrs(AttrOwner::TopLevel).clone();
@@ -536,10 +541,12 @@ impl AttrsWithOwner {
536541
let tree = db.file_item_tree(definition.into());
537542
tree.raw_attrs(AttrOwner::TopLevel).clone()
538543
}
539-
ModuleOrigin::Inline { definition_tree_id, .. } => definition_tree_id
540-
.item_tree(db)
541-
.raw_attrs(AttrOwner::ModItem(definition_tree_id.value.into()))
542-
.clone(),
544+
ModuleOrigin::Inline { definition_tree_id, file_item_tree_id, .. } => {
545+
definition_tree_id
546+
.item_tree(db)
547+
.raw_attrs(AttrOwner::ModItem(file_item_tree_id.into()))
548+
.clone()
549+
}
543550
ModuleOrigin::BlockExpr { id, .. } => {
544551
let tree = db.block_item_tree(id);
545552
tree.raw_attrs(AttrOwner::TopLevel).clone()

src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -404,59 +404,6 @@ impl TreeId {
404404
}
405405
}
406406

407-
#[derive(Debug)]
408-
pub struct ItemTreeId<N> {
409-
tree: TreeId,
410-
pub value: FileItemTreeId<N>,
411-
}
412-
413-
impl<N> ItemTreeId<N> {
414-
pub fn new(tree: TreeId, idx: FileItemTreeId<N>) -> Self {
415-
Self { tree, value: idx }
416-
}
417-
418-
pub fn file_id(self) -> HirFileId {
419-
self.tree.file
420-
}
421-
422-
pub fn tree_id(self) -> TreeId {
423-
self.tree
424-
}
425-
426-
pub fn item_tree(self, db: &dyn DefDatabase) -> Arc<ItemTree> {
427-
self.tree.item_tree(db)
428-
}
429-
430-
pub fn resolved<R>(self, db: &dyn DefDatabase, cb: impl FnOnce(&N) -> R) -> R
431-
where
432-
ItemTree: Index<FileItemTreeId<N>, Output = N>,
433-
{
434-
cb(&self.tree.item_tree(db)[self.value])
435-
}
436-
}
437-
438-
impl<N> Copy for ItemTreeId<N> {}
439-
impl<N> Clone for ItemTreeId<N> {
440-
fn clone(&self) -> Self {
441-
*self
442-
}
443-
}
444-
445-
impl<N> PartialEq for ItemTreeId<N> {
446-
fn eq(&self, other: &Self) -> bool {
447-
self.tree == other.tree && self.value == other.value
448-
}
449-
}
450-
451-
impl<N> Eq for ItemTreeId<N> {}
452-
453-
impl<N> Hash for ItemTreeId<N> {
454-
fn hash<H: Hasher>(&self, state: &mut H) {
455-
self.tree.hash(state);
456-
self.value.hash(state);
457-
}
458-
}
459-
460407
macro_rules! mod_items {
461408
( $( $typ:ident in $fld:ident -> $ast:ty ),+ $(,)? ) => {
462409
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use crate::{
8080
LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
8181
db::DefDatabase,
8282
item_scope::{BuiltinShadowMode, ItemScope},
83-
item_tree::{ItemTreeId, Mod, TreeId},
83+
item_tree::{FileItemTreeId, Mod, TreeId},
8484
nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode},
8585
per_ns::PerNs,
8686
visibility::{Visibility, VisibilityExplicitness},
@@ -289,11 +289,13 @@ pub enum ModuleOrigin {
289289
File {
290290
is_mod_rs: bool,
291291
declaration: FileAstId<ast::Module>,
292-
declaration_tree_id: ItemTreeId<Mod>,
292+
declaration_tree_id: TreeId,
293+
file_item_tree_id: FileItemTreeId<Mod>,
293294
definition: EditionedFileId,
294295
},
295296
Inline {
296-
definition_tree_id: ItemTreeId<Mod>,
297+
definition_tree_id: TreeId,
298+
file_item_tree_id: FileItemTreeId<Mod>,
297299
definition: FileAstId<ast::Module>,
298300
},
299301
/// Pseudo-module introduced by a block scope (contains only inner items).
@@ -309,7 +311,7 @@ impl ModuleOrigin {
309311
&ModuleOrigin::File { declaration, declaration_tree_id, .. } => {
310312
Some(AstId::new(declaration_tree_id.file_id(), declaration))
311313
}
312-
&ModuleOrigin::Inline { definition, definition_tree_id } => {
314+
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
313315
Some(AstId::new(definition_tree_id.file_id(), definition))
314316
}
315317
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::BlockExpr { .. } => None,
@@ -341,12 +343,14 @@ impl ModuleOrigin {
341343
let sf = db.parse(editioned_file_id).tree();
342344
InFile::new(editioned_file_id.into(), ModuleSource::SourceFile(sf))
343345
}
344-
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
345-
definition_tree_id.file_id(),
346-
ModuleSource::Module(
347-
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
348-
),
349-
),
346+
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
347+
InFile::new(
348+
definition_tree_id.file_id(),
349+
ModuleSource::Module(
350+
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
351+
),
352+
)
353+
}
350354
ModuleOrigin::BlockExpr { block, .. } => {
351355
InFile::new(block.file_id, ModuleSource::BlockExpr(block.to_node(db)))
352356
}
@@ -773,10 +777,12 @@ impl ModuleData {
773777
ErasedAstId::new(definition.into(), ROOT_ERASED_FILE_AST_ID).to_range(db),
774778
)
775779
}
776-
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
777-
definition_tree_id.file_id(),
778-
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
779-
),
780+
&ModuleOrigin::Inline { definition, definition_tree_id, file_item_tree_id: _ } => {
781+
InFile::new(
782+
definition_tree_id.file_id(),
783+
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
784+
)
785+
}
780786
ModuleOrigin::BlockExpr { block, .. } => InFile::new(block.file_id, block.to_range(db)),
781787
}
782788
}

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use crate::{
3535
db::DefDatabase,
3636
item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports},
3737
item_tree::{
38-
self, FieldsShape, FileItemTreeId, ImportAlias, ImportKind, ItemTree, ItemTreeId,
39-
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
38+
self, FieldsShape, FileItemTreeId, ImportAlias, ImportKind, ItemTree, ItemTreeNode, Macro2,
39+
MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
4040
},
4141
macro_call_as_call_id,
4242
nameres::{
@@ -140,7 +140,8 @@ struct ImportSource {
140140
id: UseId,
141141
is_prelude: bool,
142142
kind: ImportKind,
143-
item_tree_id: ItemTreeId<item_tree::Use>,
143+
tree: TreeId,
144+
item: FileItemTreeId<item_tree::Use>,
144145
}
145146

146147
#[derive(Debug, Eq, PartialEq)]
@@ -154,19 +155,20 @@ struct Import {
154155
impl Import {
155156
fn from_use(
156157
tree: &ItemTree,
157-
item_tree_id: ItemTreeId<item_tree::Use>,
158+
tree_id: TreeId,
159+
item: FileItemTreeId<item_tree::Use>,
158160
id: UseId,
159161
is_prelude: bool,
160162
mut cb: impl FnMut(Self),
161163
) {
162-
let it = &tree[item_tree_id.value];
164+
let it = &tree[item];
163165
let visibility = &tree[it.visibility];
164166
it.use_tree.expand(|idx, path, kind, alias| {
165167
cb(Self {
166168
path,
167169
alias,
168170
visibility: visibility.clone(),
169-
source: ImportSource { use_tree: idx, id, is_prelude, kind, item_tree_id },
171+
source: ImportSource { use_tree: idx, id, is_prelude, kind, tree: tree_id, item },
170172
});
171173
});
172174
}
@@ -860,7 +862,8 @@ impl DefCollector<'_> {
860862
kind: kind @ (ImportKind::Plain | ImportKind::TypeOnly),
861863
id,
862864
use_tree,
863-
item_tree_id,
865+
tree,
866+
item,
864867
..
865868
} => {
866869
let name = match &import.alias {
@@ -893,8 +896,8 @@ impl DefCollector<'_> {
893896
let Some(ImportOrExternCrate::ExternCrate(_)) = def.import else {
894897
return false;
895898
};
896-
let item_tree = item_tree_id.item_tree(self.db);
897-
let use_kind = item_tree[item_tree_id.value].use_tree.kind();
899+
let item_tree = tree.item_tree(self.db);
900+
let use_kind = item_tree[item].use_tree.kind();
898901
let UseTreeKind::Single { path, .. } = use_kind else {
899902
return false;
900903
};
@@ -1643,7 +1646,7 @@ impl DefCollector<'_> {
16431646
Import {
16441647
ref path,
16451648
source:
1646-
ImportSource { use_tree, id, is_prelude: _, kind: _, item_tree_id: _ },
1649+
ImportSource { use_tree, id, is_prelude: _, kind: _, tree: _, item: _ },
16471650
..
16481651
},
16491652
..
@@ -1771,7 +1774,8 @@ impl ModCollector<'_, '_> {
17711774
let is_prelude = attrs.by_key(sym::prelude_import).exists();
17721775
Import::from_use(
17731776
self.item_tree,
1774-
ItemTreeId::new(self.tree_id, item_tree_id),
1777+
self.tree_id,
1778+
item_tree_id,
17751779
id,
17761780
is_prelude,
17771781
|import| {
@@ -2207,13 +2211,15 @@ impl ModCollector<'_, '_> {
22072211
let origin = match definition {
22082212
None => ModuleOrigin::Inline {
22092213
definition: declaration,
2210-
definition_tree_id: ItemTreeId::new(self.tree_id, mod_tree_id),
2214+
definition_tree_id: self.tree_id,
2215+
file_item_tree_id: mod_tree_id,
22112216
},
22122217
Some((definition, is_mod_rs)) => ModuleOrigin::File {
22132218
declaration,
22142219
definition,
22152220
is_mod_rs,
2216-
declaration_tree_id: ItemTreeId::new(self.tree_id, mod_tree_id),
2221+
declaration_tree_id: self.tree_id,
2222+
file_item_tree_id: mod_tree_id,
22172223
},
22182224
};
22192225

0 commit comments

Comments
 (0)