From 4fc900deb121539a5311059e1ebb83ef73b190df Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 12:57:40 +0300 Subject: Move TypeAlias to hir_def --- crates/ra_hir/src/code_model.rs | 4 ++-- crates/ra_hir/src/db.rs | 8 ++------ crates/ra_hir/src/lib.rs | 1 - crates/ra_hir/src/type_alias.rs | 31 ------------------------------- crates/ra_hir_def/src/db.rs | 6 +++++- crates/ra_hir_def/src/lib.rs | 1 + crates/ra_hir_def/src/type_alias.rs | 27 +++++++++++++++++++++++++++ 7 files changed, 37 insertions(+), 41 deletions(-) delete mode 100644 crates/ra_hir/src/type_alias.rs create mode 100644 crates/ra_hir_def/src/type_alias.rs (limited to 'crates') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 5690040a7..72c9b466f 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -937,7 +937,7 @@ impl TypeAlias { } 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 @@ impl TypeAlias { } 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 ed0d68001..689874331 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -16,16 +16,15 @@ use crate::{ 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 8c6834392..8e532c36c 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -32,7 +32,6 @@ pub mod db; pub mod source_binder; mod ids; -mod type_alias; mod ty; mod impl_block; mod expr; diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs deleted file mode 100644 index 392f244cf..000000000 --- a/crates/ra_hir/src/type_alias.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! HIR for type aliases (i.e. the `type` keyword). - -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, -}; - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct TypeAliasData { - pub(crate) name: Name, - pub(crate) type_ref: Option, -} - -impl TypeAliasData { - pub(crate) fn type_alias_data_query( - db: &(impl DefDatabase + AstDatabase), - typ: TypeAlias, - ) -> Arc { - let node = typ.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 }) - } -} diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 844f8bbe8..5bbdaa4b2 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs @@ -15,7 +15,8 @@ use crate::{ 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 @@ pub trait DefDatabase2: InternDatabase + AstDatabase { #[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 d579f5c7e..268144462 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -20,6 +20,7 @@ pub mod body; pub mod generics; pub mod traits; pub mod resolver; +pub mod type_alias; #[cfg(test)] mod test_db; diff --git a/crates/ra_hir_def/src/type_alias.rs b/crates/ra_hir_def/src/type_alias.rs new file mode 100644 index 000000000..c0b49aa7c --- /dev/null +++ b/crates/ra_hir_def/src/type_alias.rs @@ -0,0 +1,27 @@ +//! HIR for type aliases (i.e. the `type` keyword). + +use std::sync::Arc; + +use hir_expand::name::{AsName, Name}; + +use ra_syntax::ast::NameOwner; + +use crate::{db::DefDatabase2, type_ref::TypeRef, HasSource, Lookup, TypeAliasId}; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct TypeAliasData { + pub name: Name, + pub type_ref: Option, +} + +impl TypeAliasData { + pub(crate) fn type_alias_data_query( + db: &impl DefDatabase2, + typ: TypeAliasId, + ) -> Arc { + 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 }) + } +} -- cgit v1.2.3