Skip to content

Commit 9adff00

Browse files
committed
Simplify
1 parent bfad781 commit 9adff00

File tree

6 files changed

+20
-30
lines changed

6 files changed

+20
-30
lines changed

crates/hir-def/src/item_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use crate::{
6868
path::{path, AssociatedTypeBinding, GenericArgs, ImportAlias, ModPath, Path, PathKind},
6969
type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
7070
visibility::RawVisibility,
71-
BlockId,
71+
BlockId, Lookup,
7272
};
7373

7474
#[derive(Copy, Clone, Eq, PartialEq)]
@@ -144,7 +144,7 @@ impl ItemTree {
144144
}
145145

146146
pub(crate) fn block_item_tree_query(db: &dyn DefDatabase, block: BlockId) -> Arc<ItemTree> {
147-
let loc = db.lookup_intern_block(block);
147+
let loc = block.lookup(db);
148148
let block = loc.ast_id.to_node(db.upcast());
149149

150150
let ctx = lower::Ctx::new(db, loc.ast_id.file_id);

crates/hir-def/src/nameres.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ impl DefMap {
320320
}
321321

322322
pub(crate) fn block_def_map_query(db: &dyn DefDatabase, block_id: BlockId) -> Arc<DefMap> {
323-
let block: BlockLoc = db.lookup_intern_block(block_id);
324-
325-
let tree_id = TreeId::new(block.ast_id.file_id, Some(block_id));
323+
let block: BlockLoc = block_id.lookup(db);
326324

327325
let parent_map = block.module.def_map(db);
328326
let krate = block.module.krate;
@@ -346,7 +344,8 @@ impl DefMap {
346344
},
347345
});
348346

349-
let def_map = collector::collect_defs(db, def_map, tree_id);
347+
let def_map =
348+
collector::collect_defs(db, def_map, TreeId::new(block.ast_id.file_id, Some(block_id)));
350349
Arc::new(def_map)
351350
}
352351

crates/hir-def/src/nameres/collector.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ use crate::{
5353
visibility::{RawVisibility, Visibility},
5454
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId,
5555
ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, Intern,
56-
ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId,
57-
MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc,
58-
TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro, UseId, UseLoc,
56+
ItemContainerId, LocalModuleId, Lookup, Macro2Id, Macro2Loc, MacroExpander, MacroId,
57+
MacroRulesId, MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc,
58+
StructLoc, TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro, UseId, UseLoc,
5959
};
6060

6161
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
@@ -1461,7 +1461,7 @@ impl DefCollector<'_> {
14611461
let mut diagnosed_extern_crates = FxHashSet::default();
14621462
for directive in &self.unresolved_imports {
14631463
if let ImportSource::ExternCrate { id } = directive.import.source {
1464-
let item_tree_id = self.db.lookup_intern_extern_crate(id).id;
1464+
let item_tree_id = id.lookup(self.db).id;
14651465
let item_tree = item_tree_id.item_tree(self.db);
14661466
let extern_crate = &item_tree[item_tree_id.value];
14671467

@@ -1482,7 +1482,7 @@ impl DefCollector<'_> {
14821482
) {
14831483
continue;
14841484
}
1485-
let item_tree_id = self.db.lookup_intern_use(id).id;
1485+
let item_tree_id = id.lookup(self.db).id;
14861486
self.def_map.diagnostics.push(DefDiagnostic::unresolved_import(
14871487
directive.module_id,
14881488
item_tree_id,

crates/hir-expand/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl MacroCallKind {
544544
};
545545

546546
let range = match kind {
547-
MacroCallKind::FnLike { ast_id, .. } => ast_id.to_node(db).syntax().text_range(),
547+
MacroCallKind::FnLike { ast_id, .. } => ast_id.to_ptr(db).text_range(),
548548
MacroCallKind::Derive { ast_id, derive_attr_index, .. } => {
549549
// FIXME: should be the range of the macro name, not the whole derive
550550
// FIXME: handle `cfg_attr`
@@ -840,9 +840,6 @@ impl<N: AstIdNode> AstId<N> {
840840
pub type ErasedAstId = InFile<ErasedFileAstId>;
841841

842842
impl ErasedAstId {
843-
pub fn to_node(&self, db: &dyn db::ExpandDatabase) -> SyntaxNode {
844-
self.to_ptr(db).to_node(&db.parse_or_expand(self.file_id))
845-
}
846843
pub fn to_ptr(&self, db: &dyn db::ExpandDatabase) -> SyntaxNodePtr {
847844
db.ast_id_map(self.file_id).get_raw(self.value)
848845
}

crates/hir-ty/src/mir/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use hir_def::{
1515
path::Path,
1616
resolver::{resolver_for_expr, HasResolver, ResolveValueResult, ValueNs},
1717
AdtId, DefWithBodyId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId,
18-
TraitId, TypeOrConstParamId,
18+
Lookup, TraitId, TypeOrConstParamId,
1919
};
2020
use hir_expand::name::Name;
2121
use la_arena::ArenaMap;
@@ -372,7 +372,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
372372
match &self.body.exprs[expr_id] {
373373
Expr::Missing => {
374374
if let DefWithBodyId::FunctionId(f) = self.owner {
375-
let assoc = self.db.lookup_intern_function(f);
375+
let assoc = f.lookup(self.db.upcast());
376376
if let ItemContainerId::TraitId(t) = assoc.container {
377377
let name = &self.db.function_data(f).name;
378378
return Err(MirLowerError::TraitFunctionDefinition(t, name.clone()));

crates/hir/src/lib.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -719,20 +719,18 @@ fn emit_def_diagnostic_(
719719
) {
720720
match diag {
721721
DefDiagnosticKind::UnresolvedModule { ast: declaration, candidates } => {
722-
let decl = declaration.to_node(db.upcast());
722+
let decl = declaration.to_ptr(db.upcast());
723723
acc.push(
724724
UnresolvedModule {
725-
decl: InFile::new(declaration.file_id, AstPtr::new(&decl)),
725+
decl: InFile::new(declaration.file_id, decl),
726726
candidates: candidates.clone(),
727727
}
728728
.into(),
729729
)
730730
}
731731
DefDiagnosticKind::UnresolvedExternCrate { ast } => {
732-
let item = ast.to_node(db.upcast());
733-
acc.push(
734-
UnresolvedExternCrate { decl: InFile::new(ast.file_id, AstPtr::new(&item)) }.into(),
735-
);
732+
let item = ast.to_ptr(db.upcast());
733+
acc.push(UnresolvedExternCrate { decl: InFile::new(ast.file_id, item) }.into());
736734
}
737735

738736
DefDiagnosticKind::UnresolvedImport { id, index } => {
@@ -747,14 +745,10 @@ fn emit_def_diagnostic_(
747745
}
748746

749747
DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } => {
750-
let item = ast.to_node(db.upcast());
748+
let item = ast.to_ptr(db.upcast());
751749
acc.push(
752-
InactiveCode {
753-
node: ast.with_value(SyntaxNodePtr::new(&item).into()),
754-
cfg: cfg.clone(),
755-
opts: opts.clone(),
756-
}
757-
.into(),
750+
InactiveCode { node: ast.with_value(item), cfg: cfg.clone(), opts: opts.clone() }
751+
.into(),
758752
);
759753
}
760754
DefDiagnosticKind::UnresolvedProcMacro { ast, krate } => {

0 commit comments

Comments
 (0)