diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 5690040a757..72c9b466f7d 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -937,7 +937,7 @@ pub fn container(self, db: &impl DefDatabase) -> Option { } pub fn type_ref(self, db: &impl DefDatabase) -> Option { - db.type_alias_data(self).type_ref.clone() + db.type_alias_data(self.id).type_ref.clone() } pub fn ty(self, db: &impl HirDatabase) -> Ty { @@ -945,7 +945,7 @@ pub fn ty(self, db: &impl HirDatabase) -> Ty { } pub fn name(self, db: &impl DefDatabase) -> Name { - db.type_alias_data(self).name.clone() + db.type_alias_data(self.id).name.clone() } } diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index ed0d680011e..68987433178 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -16,16 +16,15 @@ CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, TypeCtor, }, - type_alias::TypeAliasData, Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static, - StructField, Trait, TypeAlias, + StructField, Trait, }; pub use hir_def::db::{ BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, - TraitDataQuery, + TraitDataQuery, TypeAliasDataQuery, }; pub use hir_expand::db::{ AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, @@ -39,9 +38,6 @@ pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { #[salsa::invoke(FnData::fn_data_query)] fn fn_data(&self, func: Function) -> Arc; - #[salsa::invoke(TypeAliasData::type_alias_data_query)] - fn type_alias_data(&self, typ: TypeAlias) -> Arc; - #[salsa::invoke(ConstData::const_data_query)] fn const_data(&self, konst: Const) -> Arc; diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 8c6834392df..8e532c36c69 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -32,7 +32,6 @@ fn from(it: $sv) -> $e { pub mod source_binder; mod ids; -mod type_alias; mod ty; mod impl_block; mod expr; diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 844f8bbe88b..5bbdaa4b20a 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs @@ -15,7 +15,8 @@ CrateDefMap, }, traits::TraitData, - DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, + type_alias::TypeAliasData, + DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, TypeAliasId, }; #[salsa::query_group(InternDatabaseStorage)] @@ -64,6 +65,9 @@ fn raw_items_with_source_map( #[salsa::invoke(TraitData::trait_data_query)] fn trait_data(&self, e: TraitId) -> Arc; + #[salsa::invoke(TypeAliasData::type_alias_data_query)] + fn type_alias_data(&self, e: TypeAliasId) -> Arc; + #[salsa::invoke(Body::body_with_source_map_query)] fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc, Arc); diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index d579f5c7ea5..26814446296 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -20,6 +20,7 @@ pub mod generics; pub mod traits; pub mod resolver; +pub mod type_alias; #[cfg(test)] mod test_db; diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir_def/src/type_alias.rs similarity index 63% rename from crates/ra_hir/src/type_alias.rs rename to crates/ra_hir_def/src/type_alias.rs index 392f244cf17..c0b49aa7cc7 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir_def/src/type_alias.rs @@ -2,28 +2,24 @@ use std::sync::Arc; -use hir_def::type_ref::TypeRef; use hir_expand::name::{AsName, Name}; use ra_syntax::ast::NameOwner; -use crate::{ - db::{AstDatabase, DefDatabase}, - HasSource, TypeAlias, -}; +use crate::{db::DefDatabase2, type_ref::TypeRef, HasSource, Lookup, TypeAliasId}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct TypeAliasData { - pub(crate) name: Name, - pub(crate) type_ref: Option, + pub name: Name, + pub type_ref: Option, } impl TypeAliasData { pub(crate) fn type_alias_data_query( - db: &(impl DefDatabase + AstDatabase), - typ: TypeAlias, + db: &impl DefDatabase2, + typ: TypeAliasId, ) -> Arc { - let node = typ.source(db).value; + let node = typ.lookup(db).source(db).value; let name = node.name().map_or_else(Name::missing, |n| n.as_name()); let type_ref = node.type_ref().map(TypeRef::from_ast); Arc::new(TypeAliasData { name, type_ref })