diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-15 17:22:03 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-15 17:22:03 +0000 |
commit | eb9ba457b0126bd45c45ef751e92ccfdc5fdc206 (patch) | |
tree | 5af185ffaa39f285ce85aaccb2eb6bb5f532e26c | |
parent | bd4c352831662762ee7a66da77ec9adf623b0a0a (diff) | |
parent | 2c67a4abe47ead6a00ce1b33ccc3d3bfcaaf0983 (diff) |
Merge #6879
6879: Change HasChildSource::ChildId assoc item to generic param r=matklad a=Veykril
Co-authored-by: Lukas Wirth <[email protected]>
-rw-r--r-- | crates/hir/src/has_source.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/adt.rs | 13 | ||||
-rw-r--r-- | crates/hir_def/src/generics.rs | 38 | ||||
-rw-r--r-- | crates/hir_def/src/src.rs | 5 |
4 files changed, 37 insertions, 23 deletions
diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 107ad0690..04845037f 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs | |||
@@ -129,7 +129,7 @@ impl HasSource for TypeParam { | |||
129 | type Ast = Either<ast::Trait, ast::TypeParam>; | 129 | type Ast = Either<ast::Trait, ast::TypeParam>; |
130 | fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> { | 130 | fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> { |
131 | let child_source = self.id.parent.child_source(db.upcast()); | 131 | let child_source = self.id.parent.child_source(db.upcast()); |
132 | child_source.map(|it| it.type_params[self.id.local_id].clone()) | 132 | child_source.map(|it| it[self.id.local_id].clone()) |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
@@ -137,6 +137,6 @@ impl HasSource for LifetimeParam { | |||
137 | type Ast = ast::LifetimeParam; | 137 | type Ast = ast::LifetimeParam; |
138 | fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> { | 138 | fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> { |
139 | let child_source = self.id.parent.child_source(db.upcast()); | 139 | let child_source = self.id.parent.child_source(db.upcast()); |
140 | child_source.map(|it| it.lifetime_params[self.id.local_id].clone()) | 140 | child_source.map(|it| it[self.id.local_id].clone()) |
141 | } | 141 | } |
142 | } | 142 | } |
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 | ||
148 | impl HasChildSource for EnumId { | 148 | impl 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 | ||
215 | impl HasChildSource for VariantId { | 217 | impl 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)] |
76 | pub struct SourceMaps { | 76 | pub(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 | ||
81 | impl GenericParams { | 81 | impl 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 | } |
348 | impl GenericDefId { | 348 | |
349 | // FIXME: Change HasChildSource's ChildId AssocItem to be a generic parameter instead | 349 | impl 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 | |||
359 | impl 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 | ||
39 | pub trait HasChildSource { | 39 | pub 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 | } |