mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Lower and handle trait aliases in HIR
This commit is contained in:
parent
e2ec3a6561
commit
29c957f973
47 changed files with 334 additions and 75 deletions
|
@ -93,7 +93,7 @@ use hir_def::{
|
|||
keys::{self, Key},
|
||||
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId,
|
||||
GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId, StructId,
|
||||
TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
||||
TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
||||
};
|
||||
use hir_expand::{attrs::AttrId, name::AsName, HirFileId, MacroCallId};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
@ -159,6 +159,12 @@ impl SourceToDefCtx<'_, '_> {
|
|||
pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
|
||||
self.to_def(src, keys::TRAIT)
|
||||
}
|
||||
pub(super) fn trait_alias_to_def(
|
||||
&mut self,
|
||||
src: InFile<ast::TraitAlias>,
|
||||
) -> Option<TraitAliasId> {
|
||||
self.to_def(src, keys::TRAIT_ALIAS)
|
||||
}
|
||||
pub(super) fn impl_to_def(&mut self, src: InFile<ast::Impl>) -> Option<ImplId> {
|
||||
self.to_def(src, keys::IMPL)
|
||||
}
|
||||
|
@ -353,6 +359,9 @@ impl SourceToDefCtx<'_, '_> {
|
|||
match item {
|
||||
ast::Item::Module(it) => self.module_to_def(container.with_value(it))?.into(),
|
||||
ast::Item::Trait(it) => self.trait_to_def(container.with_value(it))?.into(),
|
||||
ast::Item::TraitAlias(it) => {
|
||||
self.trait_alias_to_def(container.with_value(it))?.into()
|
||||
}
|
||||
ast::Item::Impl(it) => self.impl_to_def(container.with_value(it))?.into(),
|
||||
ast::Item::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
|
||||
ast::Item::TypeAlias(it) => {
|
||||
|
@ -400,6 +409,9 @@ impl SourceToDefCtx<'_, '_> {
|
|||
ast::Item::Struct(it) => self.struct_to_def(InFile::new(file_id, it))?.into(),
|
||||
ast::Item::Enum(it) => self.enum_to_def(InFile::new(file_id, it))?.into(),
|
||||
ast::Item::Trait(it) => self.trait_to_def(InFile::new(file_id, it))?.into(),
|
||||
ast::Item::TraitAlias(it) => {
|
||||
self.trait_alias_to_def(InFile::new(file_id, it))?.into()
|
||||
}
|
||||
ast::Item::TypeAlias(it) => {
|
||||
self.type_alias_to_def(InFile::new(file_id, it))?.into()
|
||||
}
|
||||
|
@ -435,6 +447,7 @@ pub(crate) enum ChildContainer {
|
|||
DefWithBodyId(DefWithBodyId),
|
||||
ModuleId(ModuleId),
|
||||
TraitId(TraitId),
|
||||
TraitAliasId(TraitAliasId),
|
||||
ImplId(ImplId),
|
||||
EnumId(EnumId),
|
||||
VariantId(VariantId),
|
||||
|
@ -447,6 +460,7 @@ impl_from! {
|
|||
DefWithBodyId,
|
||||
ModuleId,
|
||||
TraitId,
|
||||
TraitAliasId,
|
||||
ImplId,
|
||||
EnumId,
|
||||
VariantId,
|
||||
|
@ -462,6 +476,7 @@ impl ChildContainer {
|
|||
ChildContainer::DefWithBodyId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::ModuleId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::TraitId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::TraitAliasId(_) => DynMap::default(),
|
||||
ChildContainer::ImplId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::EnumId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::VariantId(it) => it.child_by_source(db, file_id),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue