aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/adt.rs13
-rw-r--r--crates/hir_def/src/generics.rs38
-rw-r--r--crates/hir_def/src/src.rs5
3 files changed, 35 insertions, 21 deletions
diff --git a/crates/hir_def/src/adt.rs b/crates/hir_def/src/adt.rs
index 6539959c3..eafa3abb6 100644
--- a/crates/hir_def/src/adt.rs
+++ b/crates/hir_def/src/adt.rs
@@ -145,10 +145,12 @@ impl EnumData {
145 } 145 }
146} 146}
147 147
148impl HasChildSource for EnumId { 148impl HasChildSource<LocalEnumVariantId> for EnumId {
149 type ChildId = LocalEnumVariantId;
150 type Value = ast::Variant; 149 type Value = ast::Variant;
151 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 150 fn child_source(
151 &self,
152 db: &dyn DefDatabase,
153 ) -> InFile<ArenaMap<LocalEnumVariantId, Self::Value>> {
152 let src = self.lookup(db).source(db); 154 let src = self.lookup(db).source(db);
153 let mut trace = Trace::new_for_map(); 155 let mut trace = Trace::new_for_map();
154 lower_enum(db, &mut trace, &src, self.lookup(db).container.module(db)); 156 lower_enum(db, &mut trace, &src, self.lookup(db).container.module(db));
@@ -212,11 +214,10 @@ impl VariantData {
212 } 214 }
213} 215}
214 216
215impl HasChildSource for VariantId { 217impl HasChildSource<LocalFieldId> for VariantId {
216 type ChildId = LocalFieldId;
217 type Value = Either<ast::TupleField, ast::RecordField>; 218 type Value = Either<ast::TupleField, ast::RecordField>;
218 219
219 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 220 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<LocalFieldId, Self::Value>> {
220 let (src, module_id) = match self { 221 let (src, module_id) = match self {
221 VariantId::EnumVariantId(it) => { 222 VariantId::EnumVariantId(it) => {
222 // I don't really like the fact that we call into parent source 223 // I don't really like the fact that we call into parent source
diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs
index bc0125f0b..41134d23b 100644
--- a/crates/hir_def/src/generics.rs
+++ b/crates/hir_def/src/generics.rs
@@ -19,7 +19,7 @@ use crate::{
19 db::DefDatabase, 19 db::DefDatabase,
20 dyn_map::DynMap, 20 dyn_map::DynMap,
21 keys, 21 keys,
22 src::HasSource, 22 src::{HasChildSource, HasSource},
23 type_ref::{LifetimeRef, TypeBound, TypeRef}, 23 type_ref::{LifetimeRef, TypeBound, TypeRef},
24 AdtId, GenericDefId, LifetimeParamId, LocalLifetimeParamId, LocalTypeParamId, Lookup, 24 AdtId, GenericDefId, LifetimeParamId, LocalLifetimeParamId, LocalTypeParamId, Lookup,
25 TypeParamId, 25 TypeParamId,
@@ -73,9 +73,9 @@ pub enum WherePredicateTypeTarget {
73} 73}
74 74
75#[derive(Default)] 75#[derive(Default)]
76pub struct SourceMaps { 76pub(crate) struct SourceMap {
77 pub type_params: ArenaMap<LocalTypeParamId, Either<ast::Trait, ast::TypeParam>>, 77 pub(crate) type_params: ArenaMap<LocalTypeParamId, Either<ast::Trait, ast::TypeParam>>,
78 pub lifetime_params: ArenaMap<LocalLifetimeParamId, ast::LifetimeParam>, 78 lifetime_params: ArenaMap<LocalLifetimeParamId, ast::LifetimeParam>,
79} 79}
80 80
81impl GenericParams { 81impl GenericParams {
@@ -133,9 +133,9 @@ impl GenericParams {
133 Arc::new(generics) 133 Arc::new(generics)
134 } 134 }
135 135
136 fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMaps>) { 136 fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) {
137 let mut generics = GenericParams::default(); 137 let mut generics = GenericParams::default();
138 let mut sm = SourceMaps::default(); 138 let mut sm = SourceMap::default();
139 139
140 // FIXME: add `: Sized` bound for everything except for `Self` in traits 140 // FIXME: add `: Sized` bound for everything except for `Self` in traits
141 let file_id = match def { 141 let file_id = match def {
@@ -214,7 +214,7 @@ impl GenericParams {
214 pub(crate) fn fill( 214 pub(crate) fn fill(
215 &mut self, 215 &mut self,
216 lower_ctx: &LowerCtx, 216 lower_ctx: &LowerCtx,
217 sm: &mut SourceMaps, 217 sm: &mut SourceMap,
218 node: &dyn GenericParamsOwner, 218 node: &dyn GenericParamsOwner,
219 ) { 219 ) {
220 if let Some(params) = node.generic_param_list() { 220 if let Some(params) = node.generic_param_list() {
@@ -241,7 +241,7 @@ impl GenericParams {
241 fn fill_params( 241 fn fill_params(
242 &mut self, 242 &mut self,
243 lower_ctx: &LowerCtx, 243 lower_ctx: &LowerCtx,
244 sm: &mut SourceMaps, 244 sm: &mut SourceMap,
245 params: ast::GenericParamList, 245 params: ast::GenericParamList,
246 ) { 246 ) {
247 for type_param in params.type_params() { 247 for type_param in params.type_params() {
@@ -344,10 +344,24 @@ impl GenericParams {
344 }) 344 })
345 } 345 }
346} 346}
347impl GenericDefId { 347
348 // FIXME: Change HasChildSource's ChildId AssocItem to be a generic parameter instead 348impl HasChildSource<LocalTypeParamId> for GenericDefId {
349 pub fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMaps> { 349 type Value = Either<ast::Trait, ast::TypeParam>;
350 GenericParams::new(db, *self).1 350 fn child_source(
351 &self,
352 db: &dyn DefDatabase,
353 ) -> InFile<ArenaMap<LocalTypeParamId, Self::Value>> {
354 GenericParams::new(db, *self).1.map(|source_maps| source_maps.type_params)
355 }
356}
357
358impl HasChildSource<LocalLifetimeParamId> for GenericDefId {
359 type Value = ast::LifetimeParam;
360 fn child_source(
361 &self,
362 db: &dyn DefDatabase,
363 ) -> InFile<ArenaMap<LocalLifetimeParamId, Self::Value>> {
364 GenericParams::new(db, *self).1.map(|source_maps| source_maps.lifetime_params)
351 } 365 }
352} 366}
353 367
diff --git a/crates/hir_def/src/src.rs b/crates/hir_def/src/src.rs
index 7a79b0314..f67244b46 100644
--- a/crates/hir_def/src/src.rs
+++ b/crates/hir_def/src/src.rs
@@ -36,8 +36,7 @@ impl<N: ItemTreeNode> HasSource for ItemLoc<N> {
36 } 36 }
37} 37}
38 38
39pub trait HasChildSource { 39pub trait HasChildSource<ChildId> {
40 type ChildId;
41 type Value; 40 type Value;
42 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>; 41 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<ChildId, Self::Value>>;
43} 42}