diff options
Diffstat (limited to 'crates/ra_hir_def/src/item_tree/lower.rs')
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index f10ad25f7..5149dd141 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs | |||
@@ -126,15 +126,15 @@ impl Ctx { | |||
126 | 126 | ||
127 | if !attrs.is_empty() { | 127 | if !attrs.is_empty() { |
128 | for item in items.iter().flat_map(|items| &items.0) { | 128 | for item in items.iter().flat_map(|items| &items.0) { |
129 | self.add_attrs(*item, attrs.clone()); | 129 | self.add_attrs((*item).into(), attrs.clone()); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | items | 133 | items |
134 | } | 134 | } |
135 | 135 | ||
136 | fn add_attrs(&mut self, item: ModItem, attrs: Attrs) { | 136 | fn add_attrs(&mut self, item: AttrOwner, attrs: Attrs) { |
137 | match self.tree.attrs.entry(AttrOwner::ModItem(item)) { | 137 | match self.tree.attrs.entry(item) { |
138 | Entry::Occupied(mut entry) => { | 138 | Entry::Occupied(mut entry) => { |
139 | *entry.get_mut() = entry.get().merge(attrs); | 139 | *entry.get_mut() = entry.get().merge(attrs); |
140 | } | 140 | } |
@@ -196,15 +196,16 @@ impl Ctx { | |||
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | fn lower_record_fields(&mut self, fields: &ast::RecordFieldDefList) -> Range<Idx<Field>> { | 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) { |
203 | self.data().fields.alloc(data); | 203 | let idx = self.data().fields.alloc(data); |
204 | self.add_attrs(idx.into(), Attrs::new(&field, &self.hygiene)); | ||
204 | } | 205 | } |
205 | } | 206 | } |
206 | let end = self.next_field_idx(); | 207 | let end = self.next_field_idx(); |
207 | start..end | 208 | IdRange::new(start..end) |
208 | } | 209 | } |
209 | 210 | ||
210 | fn lower_record_field(&mut self, field: &ast::RecordFieldDef) -> Option<Field> { | 211 | fn lower_record_field(&mut self, field: &ast::RecordFieldDef) -> Option<Field> { |
@@ -215,15 +216,16 @@ impl Ctx { | |||
215 | Some(res) | 216 | Some(res) |
216 | } | 217 | } |
217 | 218 | ||
218 | fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> Range<Idx<Field>> { | 219 | fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> IdRange<Field> { |
219 | let start = self.next_field_idx(); | 220 | let start = self.next_field_idx(); |
220 | for (i, field) in fields.fields().enumerate() { | 221 | for (i, field) in fields.fields().enumerate() { |
221 | if let Some(data) = self.lower_tuple_field(i, &field) { | 222 | if let Some(data) = self.lower_tuple_field(i, &field) { |
222 | self.data().fields.alloc(data); | 223 | let idx = self.data().fields.alloc(data); |
224 | self.add_attrs(idx.into(), Attrs::new(&field, &self.hygiene)); | ||
223 | } | 225 | } |
224 | } | 226 | } |
225 | let end = self.next_field_idx(); | 227 | let end = self.next_field_idx(); |
226 | start..end | 228 | IdRange::new(start..end) |
227 | } | 229 | } |
228 | 230 | ||
229 | 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> { |
@@ -242,7 +244,7 @@ impl Ctx { | |||
242 | Some(record_field_def_list) => { | 244 | Some(record_field_def_list) => { |
243 | self.lower_fields(&StructKind::Record(record_field_def_list)) | 245 | self.lower_fields(&StructKind::Record(record_field_def_list)) |
244 | } | 246 | } |
245 | None => Fields::Record(self.next_field_idx()..self.next_field_idx()), | 247 | None => Fields::Record(IdRange::new(self.next_field_idx()..self.next_field_idx())), |
246 | }; | 248 | }; |
247 | let ast_id = self.source_ast_id_map.ast_id(union); | 249 | let ast_id = self.source_ast_id_map.ast_id(union); |
248 | let res = Union { name, visibility, generic_params, fields, ast_id }; | 250 | let res = Union { name, visibility, generic_params, fields, ast_id }; |
@@ -255,22 +257,23 @@ impl Ctx { | |||
255 | let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_); | 257 | let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_); |
256 | let variants = match &enum_.variant_list() { | 258 | let variants = match &enum_.variant_list() { |
257 | Some(variant_list) => self.lower_variants(variant_list), | 259 | Some(variant_list) => self.lower_variants(variant_list), |
258 | None => self.next_variant_idx()..self.next_variant_idx(), | 260 | None => IdRange::new(self.next_variant_idx()..self.next_variant_idx()), |
259 | }; | 261 | }; |
260 | let ast_id = self.source_ast_id_map.ast_id(enum_); | 262 | let ast_id = self.source_ast_id_map.ast_id(enum_); |
261 | let res = Enum { name, visibility, generic_params, variants, ast_id }; | 263 | let res = Enum { name, visibility, generic_params, variants, ast_id }; |
262 | Some(id(self.data().enums.alloc(res))) | 264 | Some(id(self.data().enums.alloc(res))) |
263 | } | 265 | } |
264 | 266 | ||
265 | fn lower_variants(&mut self, variants: &ast::EnumVariantList) -> Range<Idx<Variant>> { | 267 | fn lower_variants(&mut self, variants: &ast::EnumVariantList) -> IdRange<Variant> { |
266 | let start = self.next_variant_idx(); | 268 | let start = self.next_variant_idx(); |
267 | for variant in variants.variants() { | 269 | for variant in variants.variants() { |
268 | if let Some(data) = self.lower_variant(&variant) { | 270 | if let Some(data) = self.lower_variant(&variant) { |
269 | self.data().variants.alloc(data); | 271 | let idx = self.data().variants.alloc(data); |
272 | self.add_attrs(idx.into(), Attrs::new(&variant, &self.hygiene)); | ||
270 | } | 273 | } |
271 | } | 274 | } |
272 | let end = self.next_variant_idx(); | 275 | let end = self.next_variant_idx(); |
273 | start..end | 276 | IdRange::new(start..end) |
274 | } | 277 | } |
275 | 278 | ||
276 | fn lower_variant(&mut self, variant: &ast::EnumVariant) -> Option<Variant> { | 279 | fn lower_variant(&mut self, variant: &ast::EnumVariant) -> Option<Variant> { |
@@ -419,7 +422,7 @@ impl Ctx { | |||
419 | let attrs = Attrs::new(&item, &this.hygiene); | 422 | let attrs = Attrs::new(&item, &this.hygiene); |
420 | this.collect_inner_items(item.syntax()); | 423 | this.collect_inner_items(item.syntax()); |
421 | this.lower_assoc_item(&item).map(|item| { | 424 | this.lower_assoc_item(&item).map(|item| { |
422 | this.add_attrs(item.into(), attrs); | 425 | this.add_attrs(ModItem::from(item).into(), attrs); |
423 | item | 426 | item |
424 | }) | 427 | }) |
425 | }) | 428 | }) |
@@ -453,7 +456,7 @@ impl Ctx { | |||
453 | self.collect_inner_items(item.syntax()); | 456 | self.collect_inner_items(item.syntax()); |
454 | let assoc = self.lower_assoc_item(&item)?; | 457 | let assoc = self.lower_assoc_item(&item)?; |
455 | let attrs = Attrs::new(&item, &self.hygiene); | 458 | let attrs = Attrs::new(&item, &self.hygiene); |
456 | self.add_attrs(assoc.into(), attrs); | 459 | self.add_attrs(ModItem::from(assoc).into(), attrs); |
457 | Some(assoc) | 460 | Some(assoc) |
458 | }) | 461 | }) |
459 | .collect(); | 462 | .collect(); |
@@ -539,7 +542,7 @@ impl Ctx { | |||
539 | .filter_map(|item| { | 542 | .filter_map(|item| { |
540 | self.collect_inner_items(item.syntax()); | 543 | self.collect_inner_items(item.syntax()); |
541 | let attrs = Attrs::new(&item, &self.hygiene); | 544 | let attrs = Attrs::new(&item, &self.hygiene); |
542 | let id = match item { | 545 | let id: ModItem = match item { |
543 | ast::ExternItem::FnDef(ast) => { | 546 | ast::ExternItem::FnDef(ast) => { |
544 | let func = self.lower_function(&ast)?; | 547 | let func = self.lower_function(&ast)?; |
545 | func.into() | 548 | func.into() |
@@ -549,7 +552,7 @@ impl Ctx { | |||
549 | statik.into() | 552 | statik.into() |
550 | } | 553 | } |
551 | }; | 554 | }; |
552 | self.add_attrs(id, attrs); | 555 | self.add_attrs(id.into(), attrs); |
553 | Some(id) | 556 | Some(id) |
554 | }) | 557 | }) |
555 | .collect() | 558 | .collect() |