mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Move TypeAlias to hir_def
This commit is contained in:
parent
d59bf33b9e
commit
4fc900deb1
6 changed files with 16 additions and 20 deletions
|
@ -937,7 +937,7 @@ impl TypeAlias {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> {
|
pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> {
|
||||||
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 {
|
pub fn ty(self, db: &impl HirDatabase) -> Ty {
|
||||||
|
@ -945,7 +945,7 @@ impl TypeAlias {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(self, db: &impl DefDatabase) -> Name {
|
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||||
db.type_alias_data(self).name.clone()
|
db.type_alias_data(self.id).name.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,16 +16,15 @@ use crate::{
|
||||||
CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef,
|
CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef,
|
||||||
TypeCtor,
|
TypeCtor,
|
||||||
},
|
},
|
||||||
type_alias::TypeAliasData,
|
|
||||||
Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static,
|
Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static,
|
||||||
StructField, Trait, TypeAlias,
|
StructField, Trait,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use hir_def::db::{
|
pub use hir_def::db::{
|
||||||
BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
|
BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
|
||||||
EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase,
|
EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase,
|
||||||
InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery,
|
InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery,
|
||||||
TraitDataQuery,
|
TraitDataQuery, TypeAliasDataQuery,
|
||||||
};
|
};
|
||||||
pub use hir_expand::db::{
|
pub use hir_expand::db::{
|
||||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
||||||
|
@ -39,9 +38,6 @@ pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
|
||||||
#[salsa::invoke(FnData::fn_data_query)]
|
#[salsa::invoke(FnData::fn_data_query)]
|
||||||
fn fn_data(&self, func: Function) -> Arc<FnData>;
|
fn fn_data(&self, func: Function) -> Arc<FnData>;
|
||||||
|
|
||||||
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
|
|
||||||
fn type_alias_data(&self, typ: TypeAlias) -> Arc<TypeAliasData>;
|
|
||||||
|
|
||||||
#[salsa::invoke(ConstData::const_data_query)]
|
#[salsa::invoke(ConstData::const_data_query)]
|
||||||
fn const_data(&self, konst: Const) -> Arc<ConstData>;
|
fn const_data(&self, konst: Const) -> Arc<ConstData>;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ pub mod db;
|
||||||
pub mod source_binder;
|
pub mod source_binder;
|
||||||
|
|
||||||
mod ids;
|
mod ids;
|
||||||
mod type_alias;
|
|
||||||
mod ty;
|
mod ty;
|
||||||
mod impl_block;
|
mod impl_block;
|
||||||
mod expr;
|
mod expr;
|
||||||
|
|
|
@ -15,7 +15,8 @@ use crate::{
|
||||||
CrateDefMap,
|
CrateDefMap,
|
||||||
},
|
},
|
||||||
traits::TraitData,
|
traits::TraitData,
|
||||||
DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId,
|
type_alias::TypeAliasData,
|
||||||
|
DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, TypeAliasId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[salsa::query_group(InternDatabaseStorage)]
|
#[salsa::query_group(InternDatabaseStorage)]
|
||||||
|
@ -64,6 +65,9 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
|
||||||
#[salsa::invoke(TraitData::trait_data_query)]
|
#[salsa::invoke(TraitData::trait_data_query)]
|
||||||
fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
|
fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
|
||||||
|
|
||||||
|
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
|
||||||
|
fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
|
||||||
|
|
||||||
#[salsa::invoke(Body::body_with_source_map_query)]
|
#[salsa::invoke(Body::body_with_source_map_query)]
|
||||||
fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
|
fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ pub mod body;
|
||||||
pub mod generics;
|
pub mod generics;
|
||||||
pub mod traits;
|
pub mod traits;
|
||||||
pub mod resolver;
|
pub mod resolver;
|
||||||
|
pub mod type_alias;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_db;
|
mod test_db;
|
||||||
|
|
|
@ -2,28 +2,24 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use hir_def::type_ref::TypeRef;
|
|
||||||
use hir_expand::name::{AsName, Name};
|
use hir_expand::name::{AsName, Name};
|
||||||
|
|
||||||
use ra_syntax::ast::NameOwner;
|
use ra_syntax::ast::NameOwner;
|
||||||
|
|
||||||
use crate::{
|
use crate::{db::DefDatabase2, type_ref::TypeRef, HasSource, Lookup, TypeAliasId};
|
||||||
db::{AstDatabase, DefDatabase},
|
|
||||||
HasSource, TypeAlias,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct TypeAliasData {
|
pub struct TypeAliasData {
|
||||||
pub(crate) name: Name,
|
pub name: Name,
|
||||||
pub(crate) type_ref: Option<TypeRef>,
|
pub type_ref: Option<TypeRef>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeAliasData {
|
impl TypeAliasData {
|
||||||
pub(crate) fn type_alias_data_query(
|
pub(crate) fn type_alias_data_query(
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &impl DefDatabase2,
|
||||||
typ: TypeAlias,
|
typ: TypeAliasId,
|
||||||
) -> Arc<TypeAliasData> {
|
) -> Arc<TypeAliasData> {
|
||||||
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 name = node.name().map_or_else(Name::missing, |n| n.as_name());
|
||||||
let type_ref = node.type_ref().map(TypeRef::from_ast);
|
let type_ref = node.type_ref().map(TypeRef::from_ast);
|
||||||
Arc::new(TypeAliasData { name, type_ref })
|
Arc::new(TypeAliasData { name, type_ref })
|
Loading…
Reference in a new issue