Simplify
This commit is contained in:
parent
bfad781a77
commit
9adff006e8
@ -68,7 +68,7 @@
|
|||||||
path::{path, AssociatedTypeBinding, GenericArgs, ImportAlias, ModPath, Path, PathKind},
|
path::{path, AssociatedTypeBinding, GenericArgs, ImportAlias, ModPath, Path, PathKind},
|
||||||
type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
|
type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
|
||||||
visibility::RawVisibility,
|
visibility::RawVisibility,
|
||||||
BlockId,
|
BlockId, Lookup,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
@ -144,7 +144,7 @@ pub(crate) fn file_item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn block_item_tree_query(db: &dyn DefDatabase, block: BlockId) -> Arc<ItemTree> {
|
pub(crate) fn block_item_tree_query(db: &dyn DefDatabase, block: BlockId) -> Arc<ItemTree> {
|
||||||
let loc = db.lookup_intern_block(block);
|
let loc = block.lookup(db);
|
||||||
let block = loc.ast_id.to_node(db.upcast());
|
let block = loc.ast_id.to_node(db.upcast());
|
||||||
|
|
||||||
let ctx = lower::Ctx::new(db, loc.ast_id.file_id);
|
let ctx = lower::Ctx::new(db, loc.ast_id.file_id);
|
||||||
|
@ -320,9 +320,7 @@ pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<D
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn block_def_map_query(db: &dyn DefDatabase, block_id: BlockId) -> Arc<DefMap> {
|
pub(crate) fn block_def_map_query(db: &dyn DefDatabase, block_id: BlockId) -> Arc<DefMap> {
|
||||||
let block: BlockLoc = db.lookup_intern_block(block_id);
|
let block: BlockLoc = block_id.lookup(db);
|
||||||
|
|
||||||
let tree_id = TreeId::new(block.ast_id.file_id, Some(block_id));
|
|
||||||
|
|
||||||
let parent_map = block.module.def_map(db);
|
let parent_map = block.module.def_map(db);
|
||||||
let krate = block.module.krate;
|
let krate = block.module.krate;
|
||||||
@ -346,7 +344,8 @@ pub(crate) fn block_def_map_query(db: &dyn DefDatabase, block_id: BlockId) -> Ar
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let def_map = collector::collect_defs(db, def_map, tree_id);
|
let def_map =
|
||||||
|
collector::collect_defs(db, def_map, TreeId::new(block.ast_id.file_id, Some(block_id)));
|
||||||
Arc::new(def_map)
|
Arc::new(def_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +53,9 @@
|
|||||||
visibility::{RawVisibility, Visibility},
|
visibility::{RawVisibility, Visibility},
|
||||||
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId,
|
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId,
|
||||||
ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, Intern,
|
ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, Intern,
|
||||||
ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId,
|
ItemContainerId, LocalModuleId, Lookup, Macro2Id, Macro2Loc, MacroExpander, MacroId,
|
||||||
MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc,
|
MacroRulesId, MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc,
|
||||||
TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro, UseId, UseLoc,
|
StructLoc, TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro, UseId, UseLoc,
|
||||||
};
|
};
|
||||||
|
|
||||||
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
|
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
|
||||||
@ -1461,7 +1461,7 @@ fn finish(mut self) -> DefMap {
|
|||||||
let mut diagnosed_extern_crates = FxHashSet::default();
|
let mut diagnosed_extern_crates = FxHashSet::default();
|
||||||
for directive in &self.unresolved_imports {
|
for directive in &self.unresolved_imports {
|
||||||
if let ImportSource::ExternCrate { 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_id = id.lookup(self.db).id;
|
||||||
let item_tree = item_tree_id.item_tree(self.db);
|
let item_tree = item_tree_id.item_tree(self.db);
|
||||||
let extern_crate = &item_tree[item_tree_id.value];
|
let extern_crate = &item_tree[item_tree_id.value];
|
||||||
|
|
||||||
@ -1482,7 +1482,7 @@ fn finish(mut self) -> DefMap {
|
|||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let item_tree_id = self.db.lookup_intern_use(id).id;
|
let item_tree_id = id.lookup(self.db).id;
|
||||||
self.def_map.diagnostics.push(DefDiagnostic::unresolved_import(
|
self.def_map.diagnostics.push(DefDiagnostic::unresolved_import(
|
||||||
directive.module_id,
|
directive.module_id,
|
||||||
item_tree_id,
|
item_tree_id,
|
||||||
|
@ -544,7 +544,7 @@ pub fn original_call_range(self, db: &dyn db::ExpandDatabase) -> FileRange {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let range = match kind {
|
let range = match kind {
|
||||||
MacroCallKind::FnLike { ast_id, .. } => ast_id.to_node(db).syntax().text_range(),
|
MacroCallKind::FnLike { ast_id, .. } => ast_id.to_ptr(db).text_range(),
|
||||||
MacroCallKind::Derive { ast_id, derive_attr_index, .. } => {
|
MacroCallKind::Derive { ast_id, derive_attr_index, .. } => {
|
||||||
// FIXME: should be the range of the macro name, not the whole derive
|
// FIXME: should be the range of the macro name, not the whole derive
|
||||||
// FIXME: handle `cfg_attr`
|
// FIXME: handle `cfg_attr`
|
||||||
@ -840,9 +840,6 @@ pub fn to_ptr(&self, db: &dyn db::ExpandDatabase) -> AstPtr<N> {
|
|||||||
pub type ErasedAstId = InFile<ErasedFileAstId>;
|
pub type ErasedAstId = InFile<ErasedFileAstId>;
|
||||||
|
|
||||||
impl ErasedAstId {
|
impl ErasedAstId {
|
||||||
pub fn to_node(&self, db: &dyn db::ExpandDatabase) -> SyntaxNode {
|
|
||||||
self.to_ptr(db).to_node(&db.parse_or_expand(self.file_id))
|
|
||||||
}
|
|
||||||
pub fn to_ptr(&self, db: &dyn db::ExpandDatabase) -> SyntaxNodePtr {
|
pub fn to_ptr(&self, db: &dyn db::ExpandDatabase) -> SyntaxNodePtr {
|
||||||
db.ast_id_map(self.file_id).get_raw(self.value)
|
db.ast_id_map(self.file_id).get_raw(self.value)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
path::Path,
|
path::Path,
|
||||||
resolver::{resolver_for_expr, HasResolver, ResolveValueResult, ValueNs},
|
resolver::{resolver_for_expr, HasResolver, ResolveValueResult, ValueNs},
|
||||||
AdtId, DefWithBodyId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId,
|
AdtId, DefWithBodyId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId,
|
||||||
TraitId, TypeOrConstParamId,
|
Lookup, TraitId, TypeOrConstParamId,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use la_arena::ArenaMap;
|
use la_arena::ArenaMap;
|
||||||
@ -372,7 +372,7 @@ fn lower_expr_to_place_without_adjust(
|
|||||||
match &self.body.exprs[expr_id] {
|
match &self.body.exprs[expr_id] {
|
||||||
Expr::Missing => {
|
Expr::Missing => {
|
||||||
if let DefWithBodyId::FunctionId(f) = self.owner {
|
if let DefWithBodyId::FunctionId(f) = self.owner {
|
||||||
let assoc = self.db.lookup_intern_function(f);
|
let assoc = f.lookup(self.db.upcast());
|
||||||
if let ItemContainerId::TraitId(t) = assoc.container {
|
if let ItemContainerId::TraitId(t) = assoc.container {
|
||||||
let name = &self.db.function_data(f).name;
|
let name = &self.db.function_data(f).name;
|
||||||
return Err(MirLowerError::TraitFunctionDefinition(t, name.clone()));
|
return Err(MirLowerError::TraitFunctionDefinition(t, name.clone()));
|
||||||
|
@ -719,20 +719,18 @@ fn emit_def_diagnostic_(
|
|||||||
) {
|
) {
|
||||||
match diag {
|
match diag {
|
||||||
DefDiagnosticKind::UnresolvedModule { ast: declaration, candidates } => {
|
DefDiagnosticKind::UnresolvedModule { ast: declaration, candidates } => {
|
||||||
let decl = declaration.to_node(db.upcast());
|
let decl = declaration.to_ptr(db.upcast());
|
||||||
acc.push(
|
acc.push(
|
||||||
UnresolvedModule {
|
UnresolvedModule {
|
||||||
decl: InFile::new(declaration.file_id, AstPtr::new(&decl)),
|
decl: InFile::new(declaration.file_id, decl),
|
||||||
candidates: candidates.clone(),
|
candidates: candidates.clone(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
DefDiagnosticKind::UnresolvedExternCrate { ast } => {
|
DefDiagnosticKind::UnresolvedExternCrate { ast } => {
|
||||||
let item = ast.to_node(db.upcast());
|
let item = ast.to_ptr(db.upcast());
|
||||||
acc.push(
|
acc.push(UnresolvedExternCrate { decl: InFile::new(ast.file_id, item) }.into());
|
||||||
UnresolvedExternCrate { decl: InFile::new(ast.file_id, AstPtr::new(&item)) }.into(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DefDiagnosticKind::UnresolvedImport { id, index } => {
|
DefDiagnosticKind::UnresolvedImport { id, index } => {
|
||||||
@ -747,13 +745,9 @@ fn emit_def_diagnostic_(
|
|||||||
}
|
}
|
||||||
|
|
||||||
DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } => {
|
DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } => {
|
||||||
let item = ast.to_node(db.upcast());
|
let item = ast.to_ptr(db.upcast());
|
||||||
acc.push(
|
acc.push(
|
||||||
InactiveCode {
|
InactiveCode { node: ast.with_value(item), cfg: cfg.clone(), opts: opts.clone() }
|
||||||
node: ast.with_value(SyntaxNodePtr::new(&item).into()),
|
|
||||||
cfg: cfg.clone(),
|
|
||||||
opts: opts.clone(),
|
|
||||||
}
|
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user