aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def')
-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 81912a454..924046435 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() {
@@ -345,10 +345,24 @@ impl GenericParams {
345 }) 345 })
346 } 346 }
347} 347}
348impl GenericDefId { 348
349 // FIXME: Change HasChildSource's ChildId AssocItem to be a generic parameter instead 349impl HasChildSource<LocalTypeParamId> for GenericDefId {
350 pub fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMaps> { 350 type Value = Either<ast::Trait, ast::TypeParam>;
351 GenericParams::new(db, *self).1 351 fn child_source(
352 &self,
353 db: &dyn DefDatabase,
354 ) -> InFile<ArenaMap<LocalTypeParamId, Self::Value>> {
355 GenericParams::new(db, *self).1.map(|source_maps| source_maps.type_params)
356 }
357}
358
359impl HasChildSource<LocalLifetimeParamId> for GenericDefId {
360 type Value = ast::LifetimeParam;
361 fn child_source(
362 &self,
363 db: &dyn DefDatabase,
364 ) -> InFile<ArenaMap<LocalLifetimeParamId, Self::Value>> {
365 GenericParams::new(db, *self).1.map(|source_maps| source_maps.lifetime_params)
352 } 366 }
353} 367}
354 368
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}