From a0e1dbb45038440ddfe0c53c99d16b7f50c2d2a3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 22:47:58 +0300 Subject: Implement HasModule for AdtId --- crates/ra_hir_def/src/lib.rs | 10 ++++++++++ crates/ra_hir_def/src/resolver.rs | 12 +++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index f63c3dd64..5bc9ffc0d 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -481,6 +481,16 @@ impl HasModule for ConstLoc { } } +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 diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 1f8887c6b..95b3c926d 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs @@ -18,8 +18,8 @@ use crate::{ 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 @@ impl HasResolver for TraitId { impl> 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)) -- cgit v1.2.3