From b06214d16408e0b699f9d6051ba244e5fe766578 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 25 Jun 2020 16:42:59 +0200 Subject: Generalize FieldIds -> IdRange --- crates/ra_hir_def/src/item_tree.rs | 17 +++++++++-------- crates/ra_hir_def/src/item_tree/lower.rs | 10 +++++----- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'crates/ra_hir_def/src') 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 { } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct FieldIds { +pub struct IdRange { range: Range, + _p: PhantomData, } -impl FieldIds { - fn new(range: Range>) -> Self { - Self { range: range.start.into_raw().into()..range.end.into_raw().into() } +impl IdRange { + fn new(range: Range>) -> Self { + Self { range: range.start.into_raw().into()..range.end.into_raw().into(), _p: PhantomData } } } -impl Iterator for FieldIds { - type Item = Idx; +impl Iterator for IdRange { + type Item = Idx; fn next(&mut self) -> Option { self.range.next().map(|raw| Idx::from_raw(raw.into())) } @@ -718,8 +719,8 @@ impl Iterator for FieldIds { #[derive(Debug, Clone, PartialEq, Eq)] pub enum Fields { - Record(FieldIds), - Tuple(FieldIds), + Record(IdRange), + Tuple(IdRange), Unit, } 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 { } } - fn lower_record_fields(&mut self, fields: &ast::RecordFieldDefList) -> FieldIds { + fn lower_record_fields(&mut self, fields: &ast::RecordFieldDefList) -> IdRange { let start = self.next_field_idx(); for field in fields.fields() { if let Some(data) = self.lower_record_field(&field) { @@ -205,7 +205,7 @@ impl Ctx { } } let end = self.next_field_idx(); - FieldIds::new(start..end) + IdRange::new(start..end) } fn lower_record_field(&mut self, field: &ast::RecordFieldDef) -> Option { @@ -216,7 +216,7 @@ impl Ctx { Some(res) } - fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> FieldIds { + fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> IdRange { let start = self.next_field_idx(); for (i, field) in fields.fields().enumerate() { if let Some(data) = self.lower_tuple_field(i, &field) { @@ -225,7 +225,7 @@ impl Ctx { } } let end = self.next_field_idx(); - FieldIds::new(start..end) + IdRange::new(start..end) } fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleFieldDef) -> Option { @@ -244,7 +244,7 @@ impl Ctx { Some(record_field_def_list) => { self.lower_fields(&StructKind::Record(record_field_def_list)) } - None => Fields::Record(FieldIds::new(self.next_field_idx()..self.next_field_idx())), + None => Fields::Record(IdRange::new(self.next_field_idx()..self.next_field_idx())), }; let ast_id = self.source_ast_id_map.ast_id(union); let res = Union { name, visibility, generic_params, fields, ast_id }; -- cgit v1.2.3