mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Auto merge of #14184 - lowr:feat/trait-alias-def, r=Veykril
Handle trait alias definitions Part of #2773 This PR adds a bunch of structs and enum variants for trait aliases. Trait aliases should be handled as an independent item because they are semantically distinct from traits. I basically started by adding `TraitAlias{Id, Loc}` to `hir_def::item_tree` and iterated adding necessary stuffs until compiler stopped complaining what's missing. Let me know if there's still anything I need to add. I'm opening up this PR for early review and stuff. I'm planning to add tests for IDE functionalities in this PR, but not type-related support, for which I put FIXME notes.
This commit is contained in:
commit
6756294aa0
63 changed files with 623 additions and 206 deletions
|
@ -22,7 +22,8 @@ use crate::{
|
|||
AdtId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId,
|
||||
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
|
||||
LocalModuleId, Lookup, Macro2Id, MacroId, MacroRulesId, ModuleDefId, ModuleId, ProcMacroId,
|
||||
StaticId, StructId, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, VariantId,
|
||||
StaticId, StructId, TraitAliasId, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId,
|
||||
VariantId,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -74,6 +75,7 @@ pub enum TypeNs {
|
|||
TypeAliasId(TypeAliasId),
|
||||
BuiltinType(BuiltinType),
|
||||
TraitId(TraitId),
|
||||
TraitAliasId(TraitAliasId),
|
||||
// Module belong to type ns, but the resolver is used when all module paths
|
||||
// are fully resolved.
|
||||
// ModuleId(ModuleId)
|
||||
|
@ -402,6 +404,8 @@ impl Resolver {
|
|||
}
|
||||
|
||||
pub fn traits_in_scope(&self, db: &dyn DefDatabase) -> FxHashSet<TraitId> {
|
||||
// FIXME(trait_alias): Trait alias brings aliased traits in scope! Note that supertraits of
|
||||
// aliased traits are NOT brought in scope (unless also aliased).
|
||||
let mut traits = FxHashSet::default();
|
||||
|
||||
for scope in self.scopes() {
|
||||
|
@ -650,6 +654,7 @@ impl ModuleItemMap {
|
|||
let ty = match module_def.take_types()? {
|
||||
ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
|
||||
ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
|
||||
ModuleDefId::TraitAliasId(it) => TypeNs::TraitAliasId(it),
|
||||
ModuleDefId::TypeAliasId(it) => TypeNs::TypeAliasId(it),
|
||||
ModuleDefId::BuiltinType(it) => TypeNs::BuiltinType(it),
|
||||
|
||||
|
@ -687,6 +692,7 @@ fn to_value_ns(per_ns: PerNs) -> Option<ValueNs> {
|
|||
|
||||
ModuleDefId::AdtId(AdtId::EnumId(_) | AdtId::UnionId(_))
|
||||
| ModuleDefId::TraitId(_)
|
||||
| ModuleDefId::TraitAliasId(_)
|
||||
| ModuleDefId::TypeAliasId(_)
|
||||
| ModuleDefId::BuiltinType(_)
|
||||
| ModuleDefId::MacroId(_)
|
||||
|
@ -704,6 +710,7 @@ fn to_type_ns(per_ns: PerNs) -> Option<TypeNs> {
|
|||
ModuleDefId::BuiltinType(it) => TypeNs::BuiltinType(it),
|
||||
|
||||
ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
|
||||
ModuleDefId::TraitAliasId(it) => TypeNs::TraitAliasId(it),
|
||||
|
||||
ModuleDefId::FunctionId(_)
|
||||
| ModuleDefId::ConstId(_)
|
||||
|
@ -788,6 +795,12 @@ impl HasResolver for TraitId {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasResolver for TraitAliasId {
|
||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
||||
self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<AdtId> + Copy> HasResolver for T {
|
||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
||||
let def = self.into();
|
||||
|
@ -867,6 +880,7 @@ impl HasResolver for GenericDefId {
|
|||
GenericDefId::FunctionId(inner) => inner.resolver(db),
|
||||
GenericDefId::AdtId(adt) => adt.resolver(db),
|
||||
GenericDefId::TraitId(inner) => inner.resolver(db),
|
||||
GenericDefId::TraitAliasId(inner) => inner.resolver(db),
|
||||
GenericDefId::TypeAliasId(inner) => inner.resolver(db),
|
||||
GenericDefId::ImplId(inner) => inner.resolver(db),
|
||||
GenericDefId::EnumVariantId(inner) => inner.parent.resolver(db),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue