2394: Implement HasModule for AdtId r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-11-24 19:52:15 +00:00 committed by GitHub
commit 6a5dea778b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -481,6 +481,16 @@ fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
}
}
impl HasModule for AdtId {
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
match self {
AdtId::StructId(it) => it.0.module(db),
AdtId::UnionId(it) => it.0.module(db),
AdtId::EnumId(it) => it.module(db),
}
}
}
impl HasModule for StaticLoc {
fn module(&self, _db: &impl db::DefDatabase) -> ModuleId {
self.container

View File

@ -18,8 +18,8 @@
path::{Path, PathKind},
per_ns::PerNs,
AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
GenericDefId, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId,
TraitId, TypeAliasId,
GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId,
StructId, TraitId, TypeAliasId,
};
#[derive(Debug, Clone, Default)]
@ -503,13 +503,7 @@ fn resolver(self, db: &impl DefDatabase) -> Resolver {
impl<T: Into<AdtId>> HasResolver for T {
fn resolver(self, db: &impl DefDatabase) -> Resolver {
let def = self.into();
let module = match def {
AdtId::StructId(it) => it.0.module(db),
AdtId::UnionId(it) => it.0.module(db),
AdtId::EnumId(it) => it.module(db),
};
module
def.module(db)
.resolver(db)
.push_generic_params_scope(db, def.into())
.push_scope(Scope::AdtScope(def))