Merge #2539
2539: Remove old location infra r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
c213c3b36b
@ -11,7 +11,7 @@ use hir_def::{
|
||||
per_ns::PerNs,
|
||||
resolver::HasResolver,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId,
|
||||
AdtId, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId,
|
||||
LocalEnumVariantId, LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId,
|
||||
StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId,
|
||||
};
|
||||
@ -269,7 +269,7 @@ pub struct Struct {
|
||||
|
||||
impl Struct {
|
||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||
Module { id: self.id.module(db) }
|
||||
Module { id: self.id.lookup(db).container }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
|
||||
@ -290,7 +290,7 @@ impl Struct {
|
||||
}
|
||||
|
||||
pub fn ty(self, db: &impl HirDatabase) -> Type {
|
||||
Type::from_def(db, self.id.module(db).krate, self.id)
|
||||
Type::from_def(db, self.id.lookup(db).container.krate, self.id)
|
||||
}
|
||||
|
||||
fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
|
||||
@ -309,11 +309,11 @@ impl Union {
|
||||
}
|
||||
|
||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||
Module { id: self.id.module(db) }
|
||||
Module { id: self.id.lookup(db).container }
|
||||
}
|
||||
|
||||
pub fn ty(self, db: &impl HirDatabase) -> Type {
|
||||
Type::from_def(db, self.id.module(db).krate, self.id)
|
||||
Type::from_def(db, self.id.lookup(db).container.krate, self.id)
|
||||
}
|
||||
|
||||
pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
|
||||
@ -337,7 +337,7 @@ pub struct Enum {
|
||||
|
||||
impl Enum {
|
||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||
Module { id: self.id.module(db) }
|
||||
Module { id: self.id.lookup(db).container }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
|
||||
@ -357,7 +357,7 @@ impl Enum {
|
||||
}
|
||||
|
||||
pub fn ty(self, db: &impl HirDatabase) -> Type {
|
||||
Type::from_def(db, self.id.module(db).krate, self.id)
|
||||
Type::from_def(db, self.id.lookup(db).container.krate, self.id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,7 +577,7 @@ pub struct Trait {
|
||||
|
||||
impl Trait {
|
||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||
Module { id: self.id.module(db) }
|
||||
Module { id: self.id.lookup(db).container }
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! FIXME: write short doc here
|
||||
use hir_def::{
|
||||
child_by_source::ChildBySource, dyn_map::DynMap, keys, nameres::ModuleSource, AstItemDef,
|
||||
EnumVariantId, GenericDefId, LocationCtx, ModuleId, VariantId,
|
||||
child_by_source::ChildBySource, dyn_map::DynMap, keys, nameres::ModuleSource, EnumVariantId,
|
||||
GenericDefId, ModuleId, VariantId,
|
||||
};
|
||||
use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
|
||||
use ra_syntax::{
|
||||
@ -23,35 +23,43 @@ pub trait FromSource: Sized {
|
||||
impl FromSource for Struct {
|
||||
type Ast = ast::StructDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Struct { id })
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::STRUCT]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(Struct::from)
|
||||
}
|
||||
}
|
||||
impl FromSource for Union {
|
||||
type Ast = ast::UnionDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Union { id })
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::UNION]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(Union::from)
|
||||
}
|
||||
}
|
||||
impl FromSource for Enum {
|
||||
type Ast = ast::EnumDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Enum { id })
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::ENUM]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(Enum::from)
|
||||
}
|
||||
}
|
||||
impl FromSource for Trait {
|
||||
type Ast = ast::TraitDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Trait { id })
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::TRAIT]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(Trait::from)
|
||||
}
|
||||
}
|
||||
impl FromSource for Function {
|
||||
type Ast = ast::FnDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
Container::find(db, src.as_ref().map(|it| it.syntax()))?.child_by_source(db)[keys::FUNCTION]
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::FUNCTION]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(Function::from)
|
||||
@ -61,7 +69,7 @@ impl FromSource for Function {
|
||||
impl FromSource for Const {
|
||||
type Ast = ast::ConstDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
Container::find(db, src.as_ref().map(|it| it.syntax()))?.child_by_source(db)[keys::CONST]
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::CONST]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(Const::from)
|
||||
@ -70,7 +78,7 @@ impl FromSource for Const {
|
||||
impl FromSource for Static {
|
||||
type Ast = ast::StaticDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
Container::find(db, src.as_ref().map(|it| it.syntax()))?.child_by_source(db)[keys::STATIC]
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::STATIC]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(Static::from)
|
||||
@ -80,8 +88,7 @@ impl FromSource for Static {
|
||||
impl FromSource for TypeAlias {
|
||||
type Ast = ast::TypeAliasDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
Container::find(db, src.as_ref().map(|it| it.syntax()))?.child_by_source(db)
|
||||
[keys::TYPE_ALIAS]
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::TYPE_ALIAS]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(TypeAlias::from)
|
||||
@ -107,10 +114,10 @@ impl FromSource for MacroDef {
|
||||
impl FromSource for ImplBlock {
|
||||
type Ast = ast::ImplBlock;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
// XXX: use `.parent()` to avoid finding ourselves
|
||||
let parent = src.value.syntax().parent()?;
|
||||
let container = Container::find(db, src.with_value(parent).as_ref())?;
|
||||
container.child_by_source(db)[keys::IMPL].get(&src).copied().map(ImplBlock::from)
|
||||
analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::IMPL]
|
||||
.get(&src)
|
||||
.copied()
|
||||
.map(ImplBlock::from)
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,57 +254,30 @@ impl Module {
|
||||
}
|
||||
}
|
||||
|
||||
fn from_source<N, DEF>(db: &(impl DefDatabase + AstDatabase), src: InFile<N>) -> Option<DEF>
|
||||
where
|
||||
N: AstNode,
|
||||
DEF: AstItemDef<N>,
|
||||
{
|
||||
let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
|
||||
let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?;
|
||||
let ctx = LocationCtx::new(db, module.id, src.file_id);
|
||||
let items = db.ast_id_map(src.file_id);
|
||||
let item_id = items.ast_id(&src.value);
|
||||
Some(DEF::from_ast_id(ctx, item_id))
|
||||
fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap {
|
||||
_analyze_container(db, src).unwrap_or_default()
|
||||
}
|
||||
|
||||
enum Container {
|
||||
Trait(Trait),
|
||||
ImplBlock(ImplBlock),
|
||||
Module(Module),
|
||||
}
|
||||
|
||||
impl Container {
|
||||
fn find(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<Container> {
|
||||
// FIXME: this doesn't try to handle nested declarations
|
||||
for container in src.value.ancestors() {
|
||||
let res = match_ast! {
|
||||
match container {
|
||||
ast::TraitDef(it) => {
|
||||
let c = Trait::from_source(db, src.with_value(it))?;
|
||||
Container::Trait(c)
|
||||
},
|
||||
ast::ImplBlock(it) => {
|
||||
let c = ImplBlock::from_source(db, src.with_value(it))?;
|
||||
Container::ImplBlock(c)
|
||||
},
|
||||
_ => { continue },
|
||||
}
|
||||
};
|
||||
return Some(res);
|
||||
}
|
||||
|
||||
let module_source = ModuleSource::from_child_node(db, src);
|
||||
let c = Module::from_definition(db, src.with_value(module_source))?;
|
||||
Some(Container::Module(c))
|
||||
fn _analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> {
|
||||
// FIXME: this doesn't try to handle nested declarations
|
||||
for container in src.value.ancestors().skip(1) {
|
||||
let res = match_ast! {
|
||||
match container {
|
||||
ast::TraitDef(it) => {
|
||||
let c = Trait::from_source(db, src.with_value(it))?;
|
||||
c.id.child_by_source(db)
|
||||
},
|
||||
ast::ImplBlock(it) => {
|
||||
let c = ImplBlock::from_source(db, src.with_value(it))?;
|
||||
c.id.child_by_source(db)
|
||||
},
|
||||
_ => { continue },
|
||||
}
|
||||
};
|
||||
return Some(res);
|
||||
}
|
||||
}
|
||||
|
||||
impl ChildBySource for Container {
|
||||
fn child_by_source(&self, db: &impl DefDatabase) -> DynMap {
|
||||
match self {
|
||||
Container::Trait(it) => it.id.child_by_source(db),
|
||||
Container::ImplBlock(it) => it.id.child_by_source(db),
|
||||
Container::Module(it) => it.id.child_by_source(db),
|
||||
}
|
||||
}
|
||||
let module_source = ModuleSource::from_child_node(db, src);
|
||||
let c = Module::from_definition(db, src.with_value(module_source))?;
|
||||
Some(c.id.child_by_source(db))
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use either::Either;
|
||||
use hir_def::{
|
||||
nameres::ModuleSource,
|
||||
src::{HasChildSource, HasSource as _},
|
||||
AstItemDef, Lookup, VariantId,
|
||||
Lookup, VariantId,
|
||||
};
|
||||
use ra_syntax::ast;
|
||||
|
||||
@ -51,19 +51,19 @@ impl HasSource for StructField {
|
||||
impl HasSource for Struct {
|
||||
type Ast = ast::StructDef;
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::StructDef> {
|
||||
self.id.source(db)
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for Union {
|
||||
type Ast = ast::UnionDef;
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::UnionDef> {
|
||||
self.id.source(db)
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for Enum {
|
||||
type Ast = ast::EnumDef;
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::EnumDef> {
|
||||
self.id.source(db)
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for EnumVariant {
|
||||
@ -93,7 +93,7 @@ impl HasSource for Static {
|
||||
impl HasSource for Trait {
|
||||
type Ast = ast::TraitDef;
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::TraitDef> {
|
||||
self.id.source(db)
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for TypeAlias {
|
||||
|
@ -11,8 +11,8 @@ use ra_arena::{map::ArenaMap, Arena};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase, src::HasChildSource, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId,
|
||||
LocalEnumVariantId, LocalStructFieldId, StructId, UnionId, VariantId,
|
||||
db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, type_ref::TypeRef, EnumId,
|
||||
LocalEnumVariantId, LocalStructFieldId, Lookup, StructId, UnionId, VariantId,
|
||||
};
|
||||
|
||||
/// Note that we use `StructData` for unions as well!
|
||||
@ -50,14 +50,14 @@ pub struct StructFieldData {
|
||||
|
||||
impl StructData {
|
||||
pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructId) -> Arc<StructData> {
|
||||
let src = id.source(db);
|
||||
let src = id.lookup(db).source(db);
|
||||
let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
|
||||
let variant_data = VariantData::new(src.value.kind());
|
||||
let variant_data = Arc::new(variant_data);
|
||||
Arc::new(StructData { name, variant_data })
|
||||
}
|
||||
pub(crate) fn union_data_query(db: &impl DefDatabase, id: UnionId) -> Arc<StructData> {
|
||||
let src = id.source(db);
|
||||
let src = id.lookup(db).source(db);
|
||||
let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
|
||||
let variant_data = VariantData::new(
|
||||
src.value
|
||||
@ -72,7 +72,7 @@ impl StructData {
|
||||
|
||||
impl EnumData {
|
||||
pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> {
|
||||
let src = e.source(db);
|
||||
let src = e.lookup(db).source(db);
|
||||
let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
|
||||
let mut trace = Trace::new_for_arena();
|
||||
lower_enum(&mut trace, &src.value);
|
||||
@ -89,7 +89,7 @@ impl HasChildSource for EnumId {
|
||||
type ChildId = LocalEnumVariantId;
|
||||
type Value = ast::EnumVariant;
|
||||
fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
let src = self.source(db);
|
||||
let src = self.lookup(db).source(db);
|
||||
let mut trace = Trace::new_for_map();
|
||||
lower_enum(&mut trace, &src.value);
|
||||
src.with_value(trace.into_map())
|
||||
@ -153,8 +153,8 @@ impl HasChildSource for VariantId {
|
||||
let src = it.parent.child_source(db);
|
||||
src.map(|map| map[it.local_id].kind())
|
||||
}
|
||||
VariantId::StructId(it) => it.source(db).map(|it| it.kind()),
|
||||
VariantId::UnionId(it) => it.source(db).map(|it| {
|
||||
VariantId::StructId(it) => it.lookup(db).source(db).map(|it| it.kind()),
|
||||
VariantId::UnionId(it) => it.lookup(db).source(db).map(|it| {
|
||||
it.record_field_def_list()
|
||||
.map(ast::StructKind::Record)
|
||||
.unwrap_or(ast::StructKind::Unit)
|
||||
|
@ -12,8 +12,7 @@ use ra_syntax::{
|
||||
use tt::Subtree;
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase, path::Path, src::HasChildSource, src::HasSource, AdtId, AstItemDef, AttrDefId,
|
||||
Lookup,
|
||||
db::DefDatabase, path::Path, src::HasChildSource, src::HasSource, AdtId, AttrDefId, Lookup,
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||
@ -56,11 +55,11 @@ impl Attrs {
|
||||
Attrs::from_attrs_owner(db, src.map(|it| it as &dyn AttrsOwner))
|
||||
}
|
||||
AttrDefId::AdtId(it) => match it {
|
||||
AdtId::StructId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
|
||||
AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
|
||||
AdtId::UnionId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
|
||||
AdtId::StructId(it) => attrs_from_loc(it.lookup(db), db),
|
||||
AdtId::EnumId(it) => attrs_from_loc(it.lookup(db), db),
|
||||
AdtId::UnionId(it) => attrs_from_loc(it.lookup(db), db),
|
||||
},
|
||||
AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
|
||||
AttrDefId::TraitId(it) => attrs_from_loc(it.lookup(db), db),
|
||||
AttrDefId::MacroDefId(it) => {
|
||||
it.ast_id.map_or_else(Default::default, |ast_id| attrs_from_ast(ast_id, db))
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ use crate::{
|
||||
dyn_map::DynMap,
|
||||
keys,
|
||||
src::{HasChildSource, HasSource},
|
||||
AssocItemId, EnumId, EnumVariantId, ImplId, Lookup, ModuleDefId, ModuleId, StructFieldId,
|
||||
TraitId, VariantId,
|
||||
AdtId, AssocItemId, EnumId, EnumVariantId, ImplId, Lookup, ModuleDefId, ModuleId,
|
||||
StructFieldId, TraitId, VariantId,
|
||||
};
|
||||
|
||||
pub trait ChildBySource {
|
||||
@ -94,6 +94,24 @@ impl ChildBySource for ModuleId {
|
||||
let src = ty.lookup(db).source(db);
|
||||
res[keys::TYPE_ALIAS].insert(src, ty)
|
||||
}
|
||||
ModuleDefId::TraitId(trait_) => {
|
||||
let src = trait_.lookup(db).source(db);
|
||||
res[keys::TRAIT].insert(src, trait_)
|
||||
}
|
||||
ModuleDefId::AdtId(adt) => match adt {
|
||||
AdtId::StructId(strukt) => {
|
||||
let src = strukt.lookup(db).source(db);
|
||||
res[keys::STRUCT].insert(src, strukt)
|
||||
}
|
||||
AdtId::UnionId(union_) => {
|
||||
let src = union_.lookup(db).source(db);
|
||||
res[keys::UNION].insert(src, union_)
|
||||
}
|
||||
AdtId::EnumId(enum_) => {
|
||||
let src = enum_.lookup(db).source(db);
|
||||
res[keys::ENUM].insert(src, enum_)
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ use crate::{
|
||||
db::DefDatabase,
|
||||
src::HasSource,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId,
|
||||
Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||
AssocItemId, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId, Intern, Lookup,
|
||||
StaticId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@ -94,7 +94,7 @@ pub struct TraitData {
|
||||
|
||||
impl TraitData {
|
||||
pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc<TraitData> {
|
||||
let src = tr.source(db);
|
||||
let src = tr.lookup(db).source(db);
|
||||
let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
|
||||
let auto = src.value.is_auto();
|
||||
let ast_id_map = db.ast_id_map(src.file_id);
|
||||
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
|
||||
use hir_expand::{db::AstDatabase, HirFileId};
|
||||
use ra_db::{salsa, CrateId, SourceDatabase};
|
||||
use ra_syntax::{ast, SmolStr};
|
||||
use ra_syntax::SmolStr;
|
||||
|
||||
use crate::{
|
||||
adt::{EnumData, StructData},
|
||||
@ -17,9 +17,9 @@ use crate::{
|
||||
raw::{ImportSourceMap, RawItems},
|
||||
CrateDefMap,
|
||||
},
|
||||
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, FunctionId, FunctionLoc, GenericDefId,
|
||||
ImplId, ImplLoc, ItemLoc, ModuleId, StaticId, StaticLoc, StructId, TraitId, TypeAliasId,
|
||||
TypeAliasLoc, UnionId,
|
||||
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
|
||||
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
|
||||
TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
|
||||
};
|
||||
|
||||
#[salsa::query_group(InternDatabaseStorage)]
|
||||
@ -27,17 +27,17 @@ pub trait InternDatabase: SourceDatabase {
|
||||
#[salsa::interned]
|
||||
fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
|
||||
#[salsa::interned]
|
||||
fn intern_struct(&self, loc: ItemLoc<ast::StructDef>) -> StructId;
|
||||
fn intern_struct(&self, loc: StructLoc) -> StructId;
|
||||
#[salsa::interned]
|
||||
fn intern_union(&self, loc: ItemLoc<ast::UnionDef>) -> UnionId;
|
||||
fn intern_union(&self, loc: UnionLoc) -> UnionId;
|
||||
#[salsa::interned]
|
||||
fn intern_enum(&self, loc: ItemLoc<ast::EnumDef>) -> EnumId;
|
||||
fn intern_enum(&self, loc: EnumLoc) -> EnumId;
|
||||
#[salsa::interned]
|
||||
fn intern_const(&self, loc: ConstLoc) -> ConstId;
|
||||
#[salsa::interned]
|
||||
fn intern_static(&self, loc: StaticLoc) -> StaticId;
|
||||
#[salsa::interned]
|
||||
fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> TraitId;
|
||||
fn intern_trait(&self, loc: TraitLoc) -> TraitId;
|
||||
#[salsa::interned]
|
||||
fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
|
||||
#[salsa::interned]
|
||||
|
@ -11,7 +11,7 @@ use ra_syntax::ast;
|
||||
use crate::{
|
||||
db::DefDatabase,
|
||||
src::{HasChildSource, HasSource},
|
||||
AdtId, AstItemDef, AttrDefId, Lookup,
|
||||
AdtId, AttrDefId, Lookup,
|
||||
};
|
||||
|
||||
/// Holds documentation
|
||||
@ -51,15 +51,15 @@ impl Documentation {
|
||||
}
|
||||
}
|
||||
AttrDefId::AdtId(it) => match it {
|
||||
AdtId::StructId(it) => docs_from_ast(&it.source(db).value),
|
||||
AdtId::EnumId(it) => docs_from_ast(&it.source(db).value),
|
||||
AdtId::UnionId(it) => docs_from_ast(&it.source(db).value),
|
||||
AdtId::StructId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
AdtId::EnumId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
AdtId::UnionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
},
|
||||
AttrDefId::EnumVariantId(it) => {
|
||||
let src = it.parent.child_source(db);
|
||||
docs_from_ast(&src.value[it.local_id])
|
||||
}
|
||||
AttrDefId::TraitId(it) => docs_from_ast(&it.source(db).value),
|
||||
AttrDefId::TraitId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id?.to_node(db)),
|
||||
AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
||||
|
@ -21,7 +21,7 @@ use crate::{
|
||||
src::HasChildSource,
|
||||
src::HasSource,
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
AdtId, AstItemDef, GenericDefId, LocalTypeParamId, Lookup, TypeParamId,
|
||||
AdtId, GenericDefId, LocalTypeParamId, Lookup, TypeParamId,
|
||||
};
|
||||
|
||||
/// Data about a generic parameter (to a function, struct, impl, ...).
|
||||
@ -71,22 +71,22 @@ impl GenericParams {
|
||||
src.file_id
|
||||
}
|
||||
GenericDefId::AdtId(AdtId::StructId(it)) => {
|
||||
let src = it.source(db);
|
||||
let src = it.lookup(db).source(db);
|
||||
generics.fill(&mut sm, &src.value);
|
||||
src.file_id
|
||||
}
|
||||
GenericDefId::AdtId(AdtId::UnionId(it)) => {
|
||||
let src = it.source(db);
|
||||
let src = it.lookup(db).source(db);
|
||||
generics.fill(&mut sm, &src.value);
|
||||
src.file_id
|
||||
}
|
||||
GenericDefId::AdtId(AdtId::EnumId(it)) => {
|
||||
let src = it.source(db);
|
||||
let src = it.lookup(db).source(db);
|
||||
generics.fill(&mut sm, &src.value);
|
||||
src.file_id
|
||||
}
|
||||
GenericDefId::TraitId(it) => {
|
||||
let src = it.source(db);
|
||||
let src = it.lookup(db).source(db);
|
||||
|
||||
// traits get the Self type as an implicit first type parameter
|
||||
let self_param_id =
|
||||
|
@ -8,7 +8,8 @@ use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
dyn_map::{DynMap, Policy},
|
||||
ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, TypeAliasId, TypeParamId,
|
||||
ConstId, EnumId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId,
|
||||
TypeAliasId, TypeParamId, UnionId,
|
||||
};
|
||||
|
||||
type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>;
|
||||
@ -18,6 +19,10 @@ pub const CONST: Key<ast::ConstDef, ConstId> = Key::new();
|
||||
pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new();
|
||||
pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new();
|
||||
pub const IMPL: Key<ast::ImplBlock, ImplId> = Key::new();
|
||||
pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new();
|
||||
pub const STRUCT: Key<ast::StructDef, StructId> = Key::new();
|
||||
pub const UNION: Key<ast::UnionDef, UnionId> = Key::new();
|
||||
pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new();
|
||||
|
||||
pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();
|
||||
pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new();
|
||||
|
@ -40,14 +40,14 @@ mod test_db;
|
||||
#[cfg(test)]
|
||||
mod marks;
|
||||
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::hash::Hash;
|
||||
|
||||
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
|
||||
use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId};
|
||||
use ra_arena::{impl_arena_id, RawId};
|
||||
use ra_db::{impl_intern_key, salsa, CrateId};
|
||||
use ra_syntax::{ast, AstNode};
|
||||
use ra_syntax::ast;
|
||||
|
||||
use crate::{builtin_type::BuiltinType, db::InternDatabase};
|
||||
use crate::builtin_type::BuiltinType;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct LocalImportId(RawId);
|
||||
@ -65,63 +65,6 @@ pub struct ModuleId {
|
||||
pub struct LocalModuleId(RawId);
|
||||
impl_arena_id!(LocalModuleId);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ItemLoc<N: AstNode> {
|
||||
pub(crate) module: ModuleId,
|
||||
ast_id: AstId<N>,
|
||||
}
|
||||
|
||||
impl<N: AstNode> PartialEq for ItemLoc<N> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.module == other.module && self.ast_id == other.ast_id
|
||||
}
|
||||
}
|
||||
impl<N: AstNode> Eq for ItemLoc<N> {}
|
||||
impl<N: AstNode> Hash for ItemLoc<N> {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
self.module.hash(hasher);
|
||||
self.ast_id.hash(hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: AstNode> Clone for ItemLoc<N> {
|
||||
fn clone(&self) -> ItemLoc<N> {
|
||||
ItemLoc { module: self.module, ast_id: self.ast_id }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct LocationCtx<DB> {
|
||||
db: DB,
|
||||
module: ModuleId,
|
||||
file_id: HirFileId,
|
||||
}
|
||||
|
||||
impl<'a, DB> LocationCtx<&'a DB> {
|
||||
pub fn new(db: &'a DB, module: ModuleId, file_id: HirFileId) -> LocationCtx<&'a DB> {
|
||||
LocationCtx { db, module, file_id }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
|
||||
fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self;
|
||||
fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>;
|
||||
|
||||
fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self {
|
||||
let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
|
||||
Self::intern(ctx.db, loc)
|
||||
}
|
||||
fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile<N> {
|
||||
let loc = self.lookup_intern(db);
|
||||
let value = loc.ast_id.to_node(db);
|
||||
InFile { file_id: loc.ast_id.file_id, value }
|
||||
}
|
||||
fn module(self, db: &impl InternDatabase) -> ModuleId {
|
||||
let loc = self.lookup_intern(db);
|
||||
loc.module
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct FunctionId(salsa::InternId);
|
||||
impl_intern_key!(FunctionId);
|
||||
@ -149,36 +92,72 @@ impl Lookup for FunctionId {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct StructId(salsa::InternId);
|
||||
impl_intern_key!(StructId);
|
||||
impl AstItemDef<ast::StructDef> for StructId {
|
||||
fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self {
|
||||
db.intern_struct(loc)
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct StructLoc {
|
||||
pub container: ModuleId,
|
||||
pub ast_id: AstId<ast::StructDef>,
|
||||
}
|
||||
|
||||
impl Intern for StructLoc {
|
||||
type ID = StructId;
|
||||
fn intern(self, db: &impl db::DefDatabase) -> StructId {
|
||||
db.intern_struct(self)
|
||||
}
|
||||
fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> {
|
||||
db.lookup_intern_struct(self)
|
||||
}
|
||||
|
||||
impl Lookup for StructId {
|
||||
type Data = StructLoc;
|
||||
fn lookup(&self, db: &impl db::DefDatabase) -> StructLoc {
|
||||
db.lookup_intern_struct(*self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct UnionId(salsa::InternId);
|
||||
impl_intern_key!(UnionId);
|
||||
impl AstItemDef<ast::UnionDef> for UnionId {
|
||||
fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::UnionDef>) -> Self {
|
||||
db.intern_union(loc)
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct UnionLoc {
|
||||
pub container: ModuleId,
|
||||
pub ast_id: AstId<ast::UnionDef>,
|
||||
}
|
||||
|
||||
impl Intern for UnionLoc {
|
||||
type ID = UnionId;
|
||||
fn intern(self, db: &impl db::DefDatabase) -> UnionId {
|
||||
db.intern_union(self)
|
||||
}
|
||||
fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::UnionDef> {
|
||||
db.lookup_intern_union(self)
|
||||
}
|
||||
|
||||
impl Lookup for UnionId {
|
||||
type Data = UnionLoc;
|
||||
fn lookup(&self, db: &impl db::DefDatabase) -> UnionLoc {
|
||||
db.lookup_intern_union(*self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct EnumId(salsa::InternId);
|
||||
impl_intern_key!(EnumId);
|
||||
impl AstItemDef<ast::EnumDef> for EnumId {
|
||||
fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::EnumDef>) -> Self {
|
||||
db.intern_enum(loc)
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct EnumLoc {
|
||||
pub container: ModuleId,
|
||||
pub ast_id: AstId<ast::EnumDef>,
|
||||
}
|
||||
|
||||
impl Intern for EnumLoc {
|
||||
type ID = EnumId;
|
||||
fn intern(self, db: &impl db::DefDatabase) -> EnumId {
|
||||
db.intern_enum(self)
|
||||
}
|
||||
fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::EnumDef> {
|
||||
db.lookup_intern_enum(self)
|
||||
}
|
||||
|
||||
impl Lookup for EnumId {
|
||||
type Data = EnumLoc;
|
||||
fn lookup(&self, db: &impl db::DefDatabase) -> EnumLoc {
|
||||
db.lookup_intern_enum(*self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,12 +232,24 @@ impl Lookup for StaticId {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct TraitId(salsa::InternId);
|
||||
impl_intern_key!(TraitId);
|
||||
impl AstItemDef<ast::TraitDef> for TraitId {
|
||||
fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TraitDef>) -> Self {
|
||||
db.intern_trait(loc)
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TraitLoc {
|
||||
pub container: ModuleId,
|
||||
pub ast_id: AstId<ast::TraitDef>,
|
||||
}
|
||||
|
||||
impl Intern for TraitLoc {
|
||||
type ID = TraitId;
|
||||
fn intern(self, db: &impl db::DefDatabase) -> TraitId {
|
||||
db.intern_trait(self)
|
||||
}
|
||||
fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TraitDef> {
|
||||
db.lookup_intern_trait(self)
|
||||
}
|
||||
|
||||
impl Lookup for TraitId {
|
||||
type Data = TraitLoc;
|
||||
fn lookup(&self, db: &impl db::DefDatabase) -> TraitLoc {
|
||||
db.lookup_intern_trait(*self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -492,7 +483,7 @@ impl HasModule for FunctionLoc {
|
||||
match self.container {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
||||
ContainerId::TraitId(it) => it.module(db),
|
||||
ContainerId::TraitId(it) => it.lookup(db).container,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,7 +493,7 @@ impl HasModule for TypeAliasLoc {
|
||||
match self.container {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
||||
ContainerId::TraitId(it) => it.module(db),
|
||||
ContainerId::TraitId(it) => it.lookup(db).container,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -512,7 +503,7 @@ impl HasModule for ConstLoc {
|
||||
match self.container {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
||||
ContainerId::TraitId(it) => it.module(db),
|
||||
ContainerId::TraitId(it) => it.lookup(db).container,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -520,9 +511,9 @@ impl HasModule for ConstLoc {
|
||||
impl HasModule for AdtId {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
AdtId::StructId(it) => it.module(db),
|
||||
AdtId::UnionId(it) => it.module(db),
|
||||
AdtId::EnumId(it) => it.module(db),
|
||||
AdtId::StructId(it) => it.lookup(db).container,
|
||||
AdtId::UnionId(it) => it.lookup(db).container,
|
||||
AdtId::EnumId(it) => it.lookup(db).container,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -542,10 +533,10 @@ impl HasModule for GenericDefId {
|
||||
match self {
|
||||
GenericDefId::FunctionId(it) => it.lookup(db).module(db),
|
||||
GenericDefId::AdtId(it) => it.module(db),
|
||||
GenericDefId::TraitId(it) => it.module(db),
|
||||
GenericDefId::TraitId(it) => it.lookup(db).container,
|
||||
GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
|
||||
GenericDefId::ImplId(it) => it.lookup(db).container,
|
||||
GenericDefId::EnumVariantId(it) => it.parent.module(db),
|
||||
GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container,
|
||||
GenericDefId::ConstId(it) => it.lookup(db).module(db),
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ use crate::{
|
||||
},
|
||||
path::{Path, PathKind},
|
||||
per_ns::PerNs,
|
||||
AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplLoc,
|
||||
Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId,
|
||||
TraitId, TypeAliasLoc, UnionId,
|
||||
AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
|
||||
LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc,
|
||||
TypeAliasLoc, UnionLoc,
|
||||
};
|
||||
|
||||
pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
|
||||
@ -753,8 +753,6 @@ where
|
||||
|
||||
fn define_def(&mut self, def: &raw::DefData, attrs: &Attrs) {
|
||||
let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
|
||||
let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id);
|
||||
|
||||
// FIXME: check attrs to see if this is an attribute macro invocation;
|
||||
// in which case we don't add the invocation, just a single attribute
|
||||
// macro invocation
|
||||
@ -773,14 +771,20 @@ where
|
||||
PerNs::values(def.into())
|
||||
}
|
||||
raw::DefKind::Struct(ast_id) => {
|
||||
let id = StructId::from_ast_id(ctx, ast_id).into();
|
||||
PerNs::both(id, id)
|
||||
let def = StructLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
|
||||
.intern(self.def_collector.db);
|
||||
PerNs::both(def.into(), def.into())
|
||||
}
|
||||
raw::DefKind::Union(ast_id) => {
|
||||
let id = UnionId::from_ast_id(ctx, ast_id).into();
|
||||
PerNs::both(id, id)
|
||||
let def = UnionLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
|
||||
.intern(self.def_collector.db);
|
||||
PerNs::both(def.into(), def.into())
|
||||
}
|
||||
raw::DefKind::Enum(ast_id) => {
|
||||
let def = EnumLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
|
||||
.intern(self.def_collector.db);
|
||||
PerNs::types(def.into())
|
||||
}
|
||||
raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()),
|
||||
raw::DefKind::Const(ast_id) => {
|
||||
let def = ConstLoc {
|
||||
container: ContainerId::ModuleId(module),
|
||||
@ -796,7 +800,12 @@ where
|
||||
|
||||
PerNs::values(def.into())
|
||||
}
|
||||
raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()),
|
||||
raw::DefKind::Trait(ast_id) => {
|
||||
let def = TraitLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
|
||||
.intern(self.def_collector.db);
|
||||
|
||||
PerNs::types(def.into())
|
||||
}
|
||||
raw::DefKind::TypeAlias(ast_id) => {
|
||||
let def = TypeAliasLoc {
|
||||
container: ContainerId::ModuleId(module),
|
||||
|
@ -17,9 +17,9 @@ use crate::{
|
||||
nameres::{BuiltinShadowMode, CrateDefMap},
|
||||
path::{Path, PathKind},
|
||||
per_ns::PerNs,
|
||||
AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
|
||||
GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId,
|
||||
StructId, TraitId, TypeAliasId, TypeParamId, VariantId,
|
||||
AdtId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId,
|
||||
HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId,
|
||||
TypeAliasId, TypeParamId, VariantId,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@ -524,7 +524,7 @@ impl HasResolver for ModuleId {
|
||||
|
||||
impl HasResolver for TraitId {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
self.module(db).resolver(db).push_generic_params_scope(db, self.into())
|
||||
self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,10 @@ use hir_expand::InFile;
|
||||
use ra_arena::map::ArenaMap;
|
||||
use ra_syntax::ast;
|
||||
|
||||
use crate::{db::DefDatabase, ConstLoc, FunctionLoc, ImplLoc, StaticLoc, TypeAliasLoc};
|
||||
use crate::{
|
||||
db::DefDatabase, ConstLoc, EnumLoc, FunctionLoc, ImplLoc, StaticLoc, StructLoc, TraitLoc,
|
||||
TypeAliasLoc, UnionLoc,
|
||||
};
|
||||
|
||||
pub trait HasSource {
|
||||
type Value;
|
||||
@ -56,6 +59,42 @@ impl HasSource for ImplLoc {
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSource for TraitLoc {
|
||||
type Value = ast::TraitDef;
|
||||
|
||||
fn source(&self, db: &impl DefDatabase) -> InFile<ast::TraitDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
InFile::new(self.ast_id.file_id, node)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSource for StructLoc {
|
||||
type Value = ast::StructDef;
|
||||
|
||||
fn source(&self, db: &impl DefDatabase) -> InFile<ast::StructDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
InFile::new(self.ast_id.file_id, node)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSource for UnionLoc {
|
||||
type Value = ast::UnionDef;
|
||||
|
||||
fn source(&self, db: &impl DefDatabase) -> InFile<ast::UnionDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
InFile::new(self.ast_id.file_id, node)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSource for EnumLoc {
|
||||
type Value = ast::EnumDef;
|
||||
|
||||
fn source(&self, db: &impl DefDatabase) -> InFile<ast::EnumDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
InFile::new(self.ast_id.file_id, node)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasChildSource {
|
||||
type ChildId;
|
||||
type Value;
|
||||
|
@ -367,6 +367,9 @@ mod tests {
|
||||
BuiltinFnLikeExpander::FormatArgs,
|
||||
);
|
||||
|
||||
assert_eq!(expanded, r#"std::fmt::Arguments::new_v1(&[] ,&[std::fmt::ArgumentV1::new(&(arg1(a,b,c)),std::fmt::Display::fmt),std::fmt::ArgumentV1::new(&(arg2),std::fmt::Display::fmt),])"#);
|
||||
assert_eq!(
|
||||
expanded,
|
||||
r#"std::fmt::Arguments::new_v1(&[] ,&[std::fmt::ArgumentV1::new(&(arg1(a,b,c)),std::fmt::Display::fmt),std::fmt::ArgumentV1::new(&(arg2),std::fmt::Display::fmt),])"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use hir_def::{
|
||||
path::{GenericArg, Path, PathKind, PathSegment},
|
||||
resolver::{HasResolver, Resolver, TypeNs},
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
AdtId, AstItemDef, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId,
|
||||
AdtId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId,
|
||||
LocalStructFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId,
|
||||
};
|
||||
use ra_arena::map::ArenaMap;
|
||||
@ -698,10 +698,11 @@ impl_froms!(CallableDef: FunctionId, StructId, EnumVariantId);
|
||||
impl CallableDef {
|
||||
pub fn krate(self, db: &impl HirDatabase) -> CrateId {
|
||||
match self {
|
||||
CallableDef::FunctionId(f) => f.lookup(db).module(db).krate,
|
||||
CallableDef::StructId(s) => s.module(db).krate,
|
||||
CallableDef::EnumVariantId(e) => e.parent.module(db).krate,
|
||||
CallableDef::FunctionId(f) => f.lookup(db).module(db),
|
||||
CallableDef::StructId(s) => s.lookup(db).container,
|
||||
CallableDef::EnumVariantId(e) => e.parent.lookup(db).container,
|
||||
}
|
||||
.krate
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,7 @@ use chalk_ir::{
|
||||
};
|
||||
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
|
||||
|
||||
use hir_def::{
|
||||
AssocItemId, AstItemDef, ContainerId, GenericDefId, ImplId, Lookup, TraitId, TypeAliasId,
|
||||
};
|
||||
use hir_def::{AssocItemId, ContainerId, GenericDefId, ImplId, Lookup, TraitId, TypeAliasId};
|
||||
use ra_db::{
|
||||
salsa::{InternId, InternKey},
|
||||
CrateId,
|
||||
@ -593,7 +591,7 @@ pub(crate) fn trait_datum_query(
|
||||
let bound_vars = Substs::bound_vars(&generic_params);
|
||||
let flags = chalk_rust_ir::TraitFlags {
|
||||
auto: trait_data.auto,
|
||||
upstream: trait_.module(db).krate != krate,
|
||||
upstream: trait_.lookup(db).container.krate != krate,
|
||||
non_enumerable: true,
|
||||
coinductive: false, // only relevant for Chalk testing
|
||||
// FIXME set these flags correctly
|
||||
|
Loading…
x
Reference in New Issue
Block a user