diff options
author | Jonas Schievink <[email protected]> | 2020-06-25 15:42:59 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-06-25 15:42:59 +0100 |
commit | b06214d16408e0b699f9d6051ba244e5fe766578 (patch) | |
tree | 0bf8eb18ca876b4b31395c486d20ed6320df836b | |
parent | 2a8fc9e6829c15a54e9094b940312e9485c6b79a (diff) |
Generalize FieldIds -> IdRange<T>
-rw-r--r-- | crates/ra_hir_def/src/item_tree.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 10 |
2 files changed, 14 insertions, 13 deletions
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index fd874750e..8c93e3adf 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs | |||
@@ -699,18 +699,19 @@ pub struct Variant { | |||
699 | } | 699 | } |
700 | 700 | ||
701 | #[derive(Debug, Clone, PartialEq, Eq)] | 701 | #[derive(Debug, Clone, PartialEq, Eq)] |
702 | pub struct FieldIds { | 702 | pub struct IdRange<T> { |
703 | range: Range<u32>, | 703 | range: Range<u32>, |
704 | _p: PhantomData<T>, | ||
704 | } | 705 | } |
705 | 706 | ||
706 | impl FieldIds { | 707 | impl<T> IdRange<T> { |
707 | fn new(range: Range<Idx<Field>>) -> Self { | 708 | fn new(range: Range<Idx<T>>) -> Self { |
708 | Self { range: range.start.into_raw().into()..range.end.into_raw().into() } | 709 | Self { range: range.start.into_raw().into()..range.end.into_raw().into(), _p: PhantomData } |
709 | } | 710 | } |
710 | } | 711 | } |
711 | 712 | ||
712 | impl Iterator for FieldIds { | 713 | impl<T> Iterator for IdRange<T> { |
713 | type Item = Idx<Field>; | 714 | type Item = Idx<T>; |
714 | fn next(&mut self) -> Option<Self::Item> { | 715 | fn next(&mut self) -> Option<Self::Item> { |
715 | self.range.next().map(|raw| Idx::from_raw(raw.into())) | 716 | self.range.next().map(|raw| Idx::from_raw(raw.into())) |
716 | } | 717 | } |
@@ -718,8 +719,8 @@ impl Iterator for FieldIds { | |||
718 | 719 | ||
719 | #[derive(Debug, Clone, PartialEq, Eq)] | 720 | #[derive(Debug, Clone, PartialEq, Eq)] |
720 | pub enum Fields { | 721 | pub enum Fields { |
721 | Record(FieldIds), | 722 | Record(IdRange<Field>), |
722 | Tuple(FieldIds), | 723 | Tuple(IdRange<Field>), |
723 | Unit, | 724 | Unit, |
724 | } | 725 | } |
725 | 726 | ||
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index 230e1f768..93e8cc0c8 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs | |||
@@ -196,7 +196,7 @@ impl Ctx { | |||
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | fn lower_record_fields(&mut self, fields: &ast::RecordFieldDefList) -> FieldIds { | 199 | fn lower_record_fields(&mut self, fields: &ast::RecordFieldDefList) -> IdRange<Field> { |
200 | let start = self.next_field_idx(); | 200 | let start = self.next_field_idx(); |
201 | for field in fields.fields() { | 201 | for field in fields.fields() { |
202 | if let Some(data) = self.lower_record_field(&field) { | 202 | if let Some(data) = self.lower_record_field(&field) { |
@@ -205,7 +205,7 @@ impl Ctx { | |||
205 | } | 205 | } |
206 | } | 206 | } |
207 | let end = self.next_field_idx(); | 207 | let end = self.next_field_idx(); |
208 | FieldIds::new(start..end) | 208 | IdRange::new(start..end) |
209 | } | 209 | } |
210 | 210 | ||
211 | fn lower_record_field(&mut self, field: &ast::RecordFieldDef) -> Option<Field> { | 211 | fn lower_record_field(&mut self, field: &ast::RecordFieldDef) -> Option<Field> { |
@@ -216,7 +216,7 @@ impl Ctx { | |||
216 | Some(res) | 216 | Some(res) |
217 | } | 217 | } |
218 | 218 | ||
219 | fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> FieldIds { | 219 | fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> IdRange<Field> { |
220 | let start = self.next_field_idx(); | 220 | let start = self.next_field_idx(); |
221 | for (i, field) in fields.fields().enumerate() { | 221 | for (i, field) in fields.fields().enumerate() { |
222 | if let Some(data) = self.lower_tuple_field(i, &field) { | 222 | if let Some(data) = self.lower_tuple_field(i, &field) { |
@@ -225,7 +225,7 @@ impl Ctx { | |||
225 | } | 225 | } |
226 | } | 226 | } |
227 | let end = self.next_field_idx(); | 227 | let end = self.next_field_idx(); |
228 | FieldIds::new(start..end) | 228 | IdRange::new(start..end) |
229 | } | 229 | } |
230 | 230 | ||
231 | fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleFieldDef) -> Option<Field> { | 231 | fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleFieldDef) -> Option<Field> { |
@@ -244,7 +244,7 @@ impl Ctx { | |||
244 | Some(record_field_def_list) => { | 244 | Some(record_field_def_list) => { |
245 | self.lower_fields(&StructKind::Record(record_field_def_list)) | 245 | self.lower_fields(&StructKind::Record(record_field_def_list)) |
246 | } | 246 | } |
247 | None => Fields::Record(FieldIds::new(self.next_field_idx()..self.next_field_idx())), | 247 | None => Fields::Record(IdRange::new(self.next_field_idx()..self.next_field_idx())), |
248 | }; | 248 | }; |
249 | let ast_id = self.source_ast_id_map.ast_id(union); | 249 | let ast_id = self.source_ast_id_map.ast_id(union); |
250 | let res = Union { name, visibility, generic_params, fields, ast_id }; | 250 | let res = Union { name, visibility, generic_params, fields, ast_id }; |