diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-18 01:25:27 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-18 01:25:27 +0000 |
commit | 37e5f19373d6e4d639d0ee1125741f7b5c5c5b1a (patch) | |
tree | d60fc981c2dcc2fe5b78d73ac419c65a5574d027 /crates/hir_def/src/item_tree | |
parent | a4e17a5a96d3a8c15c91e90adce9d9b8cdc48a46 (diff) | |
parent | 4f07d8dd587c24bca8622ee8c39e5a1e156825b4 (diff) |
Merge #6924
6924: Refactor attributes API to allow handling cfg_attr later r=jonas-schievink a=jonas-schievink
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/item_tree')
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 7de385ee8..c8f090c22 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -10,7 +10,6 @@ use syntax::{ | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | attr::Attrs, | ||
14 | generics::{GenericParams, TypeParamData, TypeParamProvenance}, | 13 | generics::{GenericParams, TypeParamData, TypeParamProvenance}, |
15 | type_ref::LifetimeRef, | 14 | type_ref::LifetimeRef, |
16 | }; | 15 | }; |
@@ -105,7 +104,7 @@ impl Ctx { | |||
105 | | ast::Item::MacroDef(_) => {} | 104 | | ast::Item::MacroDef(_) => {} |
106 | }; | 105 | }; |
107 | 106 | ||
108 | let attrs = Attrs::new(item, &self.hygiene); | 107 | let attrs = RawAttrs::new(item, &self.hygiene); |
109 | let items = match item { | 108 | let items = match item { |
110 | ast::Item::Struct(ast) => self.lower_struct(ast).map(Into::into), | 109 | ast::Item::Struct(ast) => self.lower_struct(ast).map(Into::into), |
111 | ast::Item::Union(ast) => self.lower_union(ast).map(Into::into), | 110 | ast::Item::Union(ast) => self.lower_union(ast).map(Into::into), |
@@ -138,7 +137,7 @@ impl Ctx { | |||
138 | items | 137 | items |
139 | } | 138 | } |
140 | 139 | ||
141 | fn add_attrs(&mut self, item: AttrOwner, attrs: Attrs) { | 140 | fn add_attrs(&mut self, item: AttrOwner, attrs: RawAttrs) { |
142 | match self.tree.attrs.entry(item) { | 141 | match self.tree.attrs.entry(item) { |
143 | Entry::Occupied(mut entry) => { | 142 | Entry::Occupied(mut entry) => { |
144 | *entry.get_mut() = entry.get().merge(attrs); | 143 | *entry.get_mut() = entry.get().merge(attrs); |
@@ -205,7 +204,7 @@ impl Ctx { | |||
205 | for field in fields.fields() { | 204 | for field in fields.fields() { |
206 | if let Some(data) = self.lower_record_field(&field) { | 205 | if let Some(data) = self.lower_record_field(&field) { |
207 | let idx = self.data().fields.alloc(data); | 206 | let idx = self.data().fields.alloc(data); |
208 | self.add_attrs(idx.into(), Attrs::new(&field, &self.hygiene)); | 207 | self.add_attrs(idx.into(), RawAttrs::new(&field, &self.hygiene)); |
209 | } | 208 | } |
210 | } | 209 | } |
211 | let end = self.next_field_idx(); | 210 | let end = self.next_field_idx(); |
@@ -225,7 +224,7 @@ impl Ctx { | |||
225 | for (i, field) in fields.fields().enumerate() { | 224 | for (i, field) in fields.fields().enumerate() { |
226 | let data = self.lower_tuple_field(i, &field); | 225 | let data = self.lower_tuple_field(i, &field); |
227 | let idx = self.data().fields.alloc(data); | 226 | let idx = self.data().fields.alloc(data); |
228 | self.add_attrs(idx.into(), Attrs::new(&field, &self.hygiene)); | 227 | self.add_attrs(idx.into(), RawAttrs::new(&field, &self.hygiene)); |
229 | } | 228 | } |
230 | let end = self.next_field_idx(); | 229 | let end = self.next_field_idx(); |
231 | IdRange::new(start..end) | 230 | IdRange::new(start..end) |
@@ -270,7 +269,7 @@ impl Ctx { | |||
270 | for variant in variants.variants() { | 269 | for variant in variants.variants() { |
271 | if let Some(data) = self.lower_variant(&variant) { | 270 | if let Some(data) = self.lower_variant(&variant) { |
272 | let idx = self.data().variants.alloc(data); | 271 | let idx = self.data().variants.alloc(data); |
273 | self.add_attrs(idx.into(), Attrs::new(&variant, &self.hygiene)); | 272 | self.add_attrs(idx.into(), RawAttrs::new(&variant, &self.hygiene)); |
274 | } | 273 | } |
275 | } | 274 | } |
276 | let end = self.next_variant_idx(); | 275 | let end = self.next_variant_idx(); |
@@ -438,7 +437,7 @@ impl Ctx { | |||
438 | self.with_inherited_visibility(visibility, |this| { | 437 | self.with_inherited_visibility(visibility, |this| { |
439 | list.assoc_items() | 438 | list.assoc_items() |
440 | .filter_map(|item| { | 439 | .filter_map(|item| { |
441 | let attrs = Attrs::new(&item, &this.hygiene); | 440 | let attrs = RawAttrs::new(&item, &this.hygiene); |
442 | this.collect_inner_items(item.syntax()); | 441 | this.collect_inner_items(item.syntax()); |
443 | this.lower_assoc_item(&item).map(|item| { | 442 | this.lower_assoc_item(&item).map(|item| { |
444 | this.add_attrs(ModItem::from(item).into(), attrs); | 443 | this.add_attrs(ModItem::from(item).into(), attrs); |
@@ -475,7 +474,7 @@ impl Ctx { | |||
475 | .filter_map(|item| { | 474 | .filter_map(|item| { |
476 | self.collect_inner_items(item.syntax()); | 475 | self.collect_inner_items(item.syntax()); |
477 | let assoc = self.lower_assoc_item(&item)?; | 476 | let assoc = self.lower_assoc_item(&item)?; |
478 | let attrs = Attrs::new(&item, &self.hygiene); | 477 | let attrs = RawAttrs::new(&item, &self.hygiene); |
479 | self.add_attrs(ModItem::from(assoc).into(), attrs); | 478 | self.add_attrs(ModItem::from(assoc).into(), attrs); |
480 | Some(assoc) | 479 | Some(assoc) |
481 | }) | 480 | }) |
@@ -560,7 +559,7 @@ impl Ctx { | |||
560 | list.extern_items() | 559 | list.extern_items() |
561 | .filter_map(|item| { | 560 | .filter_map(|item| { |
562 | self.collect_inner_items(item.syntax()); | 561 | self.collect_inner_items(item.syntax()); |
563 | let attrs = Attrs::new(&item, &self.hygiene); | 562 | let attrs = RawAttrs::new(&item, &self.hygiene); |
564 | let id: ModItem = match item { | 563 | let id: ModItem = match item { |
565 | ast::ExternItem::Fn(ast) => { | 564 | ast::ExternItem::Fn(ast) => { |
566 | let func_id = self.lower_function(&ast)?; | 565 | let func_id = self.lower_function(&ast)?; |