aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/generics.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-20 13:03:59 +0000
committerAleksey Kladov <[email protected]>2019-11-20 13:22:58 +0000
commitcebeedc66fc40097eae20bf1767a285d00269966 (patch)
treee54c306ac0512e3610430574dc8bea39e4b50218 /crates/ra_hir_def/src/generics.rs
parent06fa3d8389c833b01f482bf35b0f850e627612b9 (diff)
Next gen IDs for functions
The current system with AstIds has two primaraly drawbacks: * It is possible to manufacture IDs out of thin air. For example, it's possible to create IDs for items which are not considered in CrateDefMap due to cfg. Or it is possible to mixup structs and unions, because they share ID space. * Getting the ID of a parent requires a secondary index. Instead, the plan is to pursue the more traditional approach, where each items stores the id of the parent declaration. This makes `FromSource` more awkward, but also more correct: now, to get from an AST to HIR, we first do this recursively for the parent item, and the just search the children of the parent for the matching def
Diffstat (limited to 'crates/ra_hir_def/src/generics.rs')
-rw-r--r--crates/ra_hir_def/src/generics.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 4adfc16bb..11dd2a948 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -11,7 +11,7 @@ use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
11use crate::{ 11use crate::{
12 db::DefDatabase2, 12 db::DefDatabase2,
13 type_ref::{TypeBound, TypeRef}, 13 type_ref::{TypeBound, TypeRef},
14 AdtId, AstItemDef, GenericDefId, 14 AdtId, AstItemDef, GenericDefId, HasSource, Lookup,
15}; 15};
16 16
17/// Data about a generic parameter (to a function, struct, impl, ...). 17/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -53,7 +53,7 @@ impl GenericParams {
53 let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32; 53 let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32;
54 // FIXME: add `: Sized` bound for everything except for `Self` in traits 54 // FIXME: add `: Sized` bound for everything except for `Self` in traits
55 match def { 55 match def {
56 GenericDefId::FunctionId(it) => generics.fill(&it.source(db).value, start), 56 GenericDefId::FunctionId(it) => generics.fill(&it.lookup(db).source(db).value, start),
57 GenericDefId::AdtId(AdtId::StructId(it)) => { 57 GenericDefId::AdtId(AdtId::StructId(it)) => {
58 generics.fill(&it.0.source(db).value, start) 58 generics.fill(&it.0.source(db).value, start)
59 } 59 }