aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/generics.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-20 17:39:00 +0000
committerGitHub <[email protected]>2019-11-20 17:39:00 +0000
commit7a5fd1f3f3c4a8f64407f9bd08a3d5e7f79417e0 (patch)
tree5a16aa6fbc213909a5d7be3c852fa2a6b9c62299 /crates/ra_hir_def/src/generics.rs
parentc51dcb1c4bdd71f9f17de508bd0d47e3c06ae1d5 (diff)
parentcb642fc578100c0945088accb85acb8f03d2e1fd (diff)
Merge #2328
2328: Move generic_params query to HIR r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/generics.rs')
-rw-r--r--crates/ra_hir_def/src/generics.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 17a5d5f43..f794eefbc 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -5,13 +5,12 @@
5use std::sync::Arc; 5use std::sync::Arc;
6 6
7use hir_expand::name::{self, AsName, Name}; 7use hir_expand::name::{self, AsName, Name};
8
9use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
10 9
11use crate::{ 10use crate::{
12 db::DefDatabase2, 11 db::DefDatabase2,
13 type_ref::{TypeBound, TypeRef}, 12 type_ref::{TypeBound, TypeRef},
14 AdtId, AstItemDef, GenericDefId, HasSource, Lookup, 13 AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup,
15}; 14};
16 15
17/// Data about a generic parameter (to a function, struct, impl, ...). 16/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -43,7 +42,15 @@ pub struct WherePredicate {
43} 42}
44 43
45impl GenericParams { 44impl GenericParams {
46 pub fn new( 45 pub(crate) fn generic_params_query(
46 db: &impl DefDatabase2,
47 def: GenericDefId,
48 ) -> Arc<GenericParams> {
49 let parent_generics = parent_generic_def(db, def).map(|it| db.generic_params(it));
50 Arc::new(GenericParams::new(db, def.into(), parent_generics))
51 }
52
53 fn new(
47 db: &impl DefDatabase2, 54 db: &impl DefDatabase2,
48 def: GenericDefId, 55 def: GenericDefId,
49 parent_params: Option<Arc<GenericParams>>, 56 parent_params: Option<Arc<GenericParams>>,
@@ -161,3 +168,19 @@ impl GenericParams {
161 vec 168 vec
162 } 169 }
163} 170}
171
172fn parent_generic_def(db: &impl DefDatabase2, def: GenericDefId) -> Option<GenericDefId> {
173 let container = match def {
174 GenericDefId::FunctionId(it) => it.lookup(db).container,
175 GenericDefId::TypeAliasId(it) => it.lookup(db).container,
176 GenericDefId::ConstId(it) => it.lookup(db).container,
177 GenericDefId::EnumVariantId(it) => return Some(it.parent.into()),
178 GenericDefId::AdtId(_) | GenericDefId::TraitId(_) | GenericDefId::ImplId(_) => return None,
179 };
180
181 match container {
182 ContainerId::ImplId(it) => Some(it.into()),
183 ContainerId::TraitId(it) => Some(it.into()),
184 ContainerId::ModuleId(_) => None,
185 }
186}