diff options
Diffstat (limited to 'crates/ra_hir/src/impl_block.rs')
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 4d8bdf33a..7ecf8c368 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -13,7 +13,7 @@ use crate::{ | |||
13 | type_ref::TypeRef, | 13 | type_ref::TypeRef, |
14 | ids::LocationCtx, | 14 | ids::LocationCtx, |
15 | resolve::Resolver, | 15 | resolve::Resolver, |
16 | ty::Ty, | 16 | ty::Ty, generics::GenericParams |
17 | }; | 17 | }; |
18 | 18 | ||
19 | use crate::code_model_api::{Module, ModuleSource}; | 19 | use crate::code_model_api::{Module, ModuleSource}; |
@@ -38,7 +38,7 @@ impl ImplSourceMap { | |||
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 41 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
42 | pub struct ImplBlock { | 42 | pub struct ImplBlock { |
43 | module: Module, | 43 | module: Module, |
44 | impl_id: ImplId, | 44 | impl_id: ImplId, |
@@ -58,7 +58,7 @@ impl ImplBlock { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | /// Returns the syntax of the impl block | 60 | /// Returns the syntax of the impl block |
61 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) { | 61 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) { |
62 | let source_map = db.impls_in_module_source_map(self.module); | 62 | let source_map = db.impls_in_module_source_map(self.module); |
63 | let (file_id, source) = self.module.definition_source(db); | 63 | let (file_id, source) = self.module.definition_source(db); |
64 | (file_id, source_map.get(&source, self.impl_id)) | 64 | (file_id, source_map.get(&source, self.impl_id)) |
@@ -72,11 +72,11 @@ impl ImplBlock { | |||
72 | self.module | 72 | self.module |
73 | } | 73 | } |
74 | 74 | ||
75 | pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TypeRef> { | 75 | pub fn target_trait_ref(&self, db: &impl PersistentHirDatabase) -> Option<TypeRef> { |
76 | db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned() | 76 | db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned() |
77 | } | 77 | } |
78 | 78 | ||
79 | pub fn target_type(&self, db: &impl HirDatabase) -> TypeRef { | 79 | pub fn target_type(&self, db: &impl PersistentHirDatabase) -> TypeRef { |
80 | db.impls_in_module(self.module).impls[self.impl_id].target_type().clone() | 80 | db.impls_in_module(self.module).impls[self.impl_id].target_type().clone() |
81 | } | 81 | } |
82 | 82 | ||
@@ -96,13 +96,19 @@ impl ImplBlock { | |||
96 | None | 96 | None |
97 | } | 97 | } |
98 | 98 | ||
99 | pub fn items(&self, db: &impl HirDatabase) -> Vec<ImplItem> { | 99 | pub fn items(&self, db: &impl PersistentHirDatabase) -> Vec<ImplItem> { |
100 | db.impls_in_module(self.module).impls[self.impl_id].items().to_vec() | 100 | db.impls_in_module(self.module).impls[self.impl_id].items().to_vec() |
101 | } | 101 | } |
102 | 102 | ||
103 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | ||
104 | db.generic_params((*self).into()) | ||
105 | } | ||
106 | |||
103 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { | 107 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { |
104 | let r = self.module().resolver(db); | 108 | let r = self.module().resolver(db); |
105 | // TODO: add generics | 109 | // add generic params, if present |
110 | let p = self.generic_params(db); | ||
111 | let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; | ||
106 | let r = r.push_impl_block_scope(self.clone()); | 112 | let r = r.push_impl_block_scope(self.clone()); |
107 | r | 113 | r |
108 | } | 114 | } |