diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/generics.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 16 |
2 files changed, 14 insertions, 8 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index c72360f44..6ae0ead1b 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -7,7 +7,7 @@ use std::sync::Arc; | |||
7 | 7 | ||
8 | use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; | 8 | use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; |
9 | 9 | ||
10 | use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type}; | 10 | use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type, ImplBlock}; |
11 | 11 | ||
12 | /// Data about a generic parameter (to a function, struct, impl, ...). | 12 | /// Data about a generic parameter (to a function, struct, impl, ...). |
13 | #[derive(Clone, PartialEq, Eq, Debug)] | 13 | #[derive(Clone, PartialEq, Eq, Debug)] |
@@ -30,8 +30,9 @@ pub enum GenericDef { | |||
30 | Enum(Enum), | 30 | Enum(Enum), |
31 | Trait(Trait), | 31 | Trait(Trait), |
32 | Type(Type), | 32 | Type(Type), |
33 | ImplBlock(ImplBlock), | ||
33 | } | 34 | } |
34 | impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type); | 35 | impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type, ImplBlock); |
35 | 36 | ||
36 | impl GenericParams { | 37 | impl GenericParams { |
37 | pub(crate) fn generic_params_query( | 38 | pub(crate) fn generic_params_query( |
@@ -45,6 +46,7 @@ impl GenericParams { | |||
45 | GenericDef::Enum(it) => generics.fill(&*it.source(db).1), | 46 | GenericDef::Enum(it) => generics.fill(&*it.source(db).1), |
46 | GenericDef::Trait(it) => generics.fill(&*it.source(db).1), | 47 | GenericDef::Trait(it) => generics.fill(&*it.source(db).1), |
47 | GenericDef::Type(it) => generics.fill(&*it.source(db).1), | 48 | GenericDef::Type(it) => generics.fill(&*it.source(db).1), |
49 | GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1), | ||
48 | } | 50 | } |
49 | 51 | ||
50 | Arc::new(generics) | 52 | Arc::new(generics) |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 4d8bdf33a..7d862882d 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,10 +96,14 @@ 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 | // TODO: add generics |