Implement HasResolver and HasModule for FieldId

This commit is contained in:
Shoyu Vanilla 2025-01-27 00:47:31 +09:00
parent b4d4d02db8
commit ce9da90630
2 changed files with 20 additions and 19 deletions

View file

@ -1357,6 +1357,12 @@ impl HasModule for VariantId {
}
}
impl HasModule for FieldId {
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
self.parent.module(db)
}
}
impl HasModule for MacroId {
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
match *self {
@ -1380,11 +1386,7 @@ impl HasModule for TypeOwnerId {
TypeOwnerId::ImplId(it) => it.module(db),
TypeOwnerId::EnumVariantId(it) => it.module(db),
TypeOwnerId::InTypeConstId(it) => it.lookup(db).owner.module(db),
TypeOwnerId::FieldId(it) => match it.parent {
VariantId::EnumVariantId(it) => it.module(db),
VariantId::StructId(it) => it.module(db),
VariantId::UnionId(it) => it.module(db),
},
TypeOwnerId::FieldId(it) => it.module(db),
}
}
}

View file

@ -27,10 +27,11 @@ use crate::{
type_ref::{LifetimeRef, TypesMap},
visibility::{RawVisibility, Visibility},
AdtId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId,
ExternBlockId, ExternCrateId, FunctionId, FxIndexMap, GenericDefId, GenericParamId, HasModule,
ImplId, ItemContainerId, ItemTreeLoc, LifetimeParamId, LocalModuleId, Lookup, Macro2Id,
MacroId, MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId,
TraitId, TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, UseId, VariantId,
ExternBlockId, ExternCrateId, FieldId, FunctionId, FxIndexMap, GenericDefId, GenericParamId,
HasModule, ImplId, ItemContainerId, ItemTreeLoc, LifetimeParamId, LocalModuleId, Lookup,
Macro2Id, MacroId, MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId,
TraitAliasId, TraitId, TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, UseId,
VariantId,
};
#[derive(Debug, Clone)]
@ -1227,11 +1228,7 @@ impl HasResolver for TypeOwnerId {
TypeOwnerId::TypeAliasId(it) => it.resolver(db),
TypeOwnerId::ImplId(it) => it.resolver(db),
TypeOwnerId::EnumVariantId(it) => it.resolver(db),
TypeOwnerId::FieldId(it) => match it.parent {
VariantId::EnumVariantId(it) => it.resolver(db),
VariantId::StructId(it) => it.resolver(db),
VariantId::UnionId(it) => it.resolver(db),
},
TypeOwnerId::FieldId(it) => it.resolver(db),
}
}
}
@ -1244,11 +1241,7 @@ impl HasResolver for DefWithBodyId {
DefWithBodyId::StaticId(s) => s.resolver(db),
DefWithBodyId::VariantId(v) => v.resolver(db),
DefWithBodyId::InTypeConstId(c) => c.lookup(db).owner.resolver(db),
DefWithBodyId::FieldId(f) => match f.parent {
VariantId::EnumVariantId(it) => it.resolver(db),
VariantId::StructId(it) => it.resolver(db),
VariantId::UnionId(it) => it.resolver(db),
},
DefWithBodyId::FieldId(f) => f.resolver(db),
}
}
}
@ -1295,6 +1288,12 @@ impl HasResolver for VariantId {
}
}
impl HasResolver for FieldId {
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
self.parent.resolver(db)
}
}
impl HasResolver for MacroId {
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
match self {