aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_tree
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/item_tree')
-rw-r--r--crates/hir_def/src/item_tree/lower.rs34
1 files changed, 19 insertions, 15 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 45b099cf3..5743b3386 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -31,18 +31,20 @@ where
31 } 31 }
32} 32}
33 33
34pub(super) struct Ctx { 34pub(super) struct Ctx<'a> {
35 db: &'a dyn DefDatabase,
35 tree: ItemTree, 36 tree: ItemTree,
36 hygiene: Hygiene, 37 hygiene: Hygiene,
37 file: HirFileId, 38 file: HirFileId,
38 source_ast_id_map: Arc<AstIdMap>, 39 source_ast_id_map: Arc<AstIdMap>,
39 body_ctx: crate::body::LowerCtx, 40 body_ctx: crate::body::LowerCtx<'a>,
40 forced_visibility: Option<RawVisibilityId>, 41 forced_visibility: Option<RawVisibilityId>,
41} 42}
42 43
43impl Ctx { 44impl<'a> Ctx<'a> {
44 pub(super) fn new(db: &dyn DefDatabase, hygiene: Hygiene, file: HirFileId) -> Self { 45 pub(super) fn new(db: &'a dyn DefDatabase, hygiene: Hygiene, file: HirFileId) -> Self {
45 Self { 46 Self {
47 db,
46 tree: ItemTree::default(), 48 tree: ItemTree::default(),
47 hygiene, 49 hygiene,
48 file, 50 file,
@@ -126,7 +128,7 @@ impl Ctx {
126 | ast::Item::MacroDef(_) => {} 128 | ast::Item::MacroDef(_) => {}
127 }; 129 };
128 130
129 let attrs = RawAttrs::new(item, &self.hygiene); 131 let attrs = RawAttrs::new(self.db, item, &self.hygiene);
130 let items = match item { 132 let items = match item {
131 ast::Item::Struct(ast) => self.lower_struct(ast).map(Into::into), 133 ast::Item::Struct(ast) => self.lower_struct(ast).map(Into::into),
132 ast::Item::Union(ast) => self.lower_union(ast).map(Into::into), 134 ast::Item::Union(ast) => self.lower_union(ast).map(Into::into),
@@ -256,7 +258,7 @@ impl Ctx {
256 for field in fields.fields() { 258 for field in fields.fields() {
257 if let Some(data) = self.lower_record_field(&field) { 259 if let Some(data) = self.lower_record_field(&field) {
258 let idx = self.data().fields.alloc(data); 260 let idx = self.data().fields.alloc(data);
259 self.add_attrs(idx.into(), RawAttrs::new(&field, &self.hygiene)); 261 self.add_attrs(idx.into(), RawAttrs::new(self.db, &field, &self.hygiene));
260 } 262 }
261 } 263 }
262 let end = self.next_field_idx(); 264 let end = self.next_field_idx();
@@ -276,7 +278,7 @@ impl Ctx {
276 for (i, field) in fields.fields().enumerate() { 278 for (i, field) in fields.fields().enumerate() {
277 let data = self.lower_tuple_field(i, &field); 279 let data = self.lower_tuple_field(i, &field);
278 let idx = self.data().fields.alloc(data); 280 let idx = self.data().fields.alloc(data);
279 self.add_attrs(idx.into(), RawAttrs::new(&field, &self.hygiene)); 281 self.add_attrs(idx.into(), RawAttrs::new(self.db, &field, &self.hygiene));
280 } 282 }
281 let end = self.next_field_idx(); 283 let end = self.next_field_idx();
282 IdRange::new(start..end) 284 IdRange::new(start..end)
@@ -321,7 +323,7 @@ impl Ctx {
321 for variant in variants.variants() { 323 for variant in variants.variants() {
322 if let Some(data) = self.lower_variant(&variant) { 324 if let Some(data) = self.lower_variant(&variant) {
323 let idx = self.data().variants.alloc(data); 325 let idx = self.data().variants.alloc(data);
324 self.add_attrs(idx.into(), RawAttrs::new(&variant, &self.hygiene)); 326 self.add_attrs(idx.into(), RawAttrs::new(self.db, &variant, &self.hygiene));
325 } 327 }
326 } 328 }
327 let end = self.next_variant_idx(); 329 let end = self.next_variant_idx();
@@ -364,7 +366,7 @@ impl Ctx {
364 }; 366 };
365 let ty = Interned::new(self_type); 367 let ty = Interned::new(self_type);
366 let idx = self.data().params.alloc(Param::Normal(ty)); 368 let idx = self.data().params.alloc(Param::Normal(ty));
367 self.add_attrs(idx.into(), RawAttrs::new(&self_param, &self.hygiene)); 369 self.add_attrs(idx.into(), RawAttrs::new(self.db, &self_param, &self.hygiene));
368 has_self_param = true; 370 has_self_param = true;
369 } 371 }
370 for param in param_list.params() { 372 for param in param_list.params() {
@@ -376,7 +378,7 @@ impl Ctx {
376 self.data().params.alloc(Param::Normal(ty)) 378 self.data().params.alloc(Param::Normal(ty))
377 } 379 }
378 }; 380 };
379 self.add_attrs(idx.into(), RawAttrs::new(&param, &self.hygiene)); 381 self.add_attrs(idx.into(), RawAttrs::new(self.db, &param, &self.hygiene));
380 } 382 }
381 } 383 }
382 let end_param = self.next_param_idx(); 384 let end_param = self.next_param_idx();
@@ -522,10 +524,11 @@ impl Ctx {
522 let is_unsafe = trait_def.unsafe_token().is_some(); 524 let is_unsafe = trait_def.unsafe_token().is_some();
523 let bounds = self.lower_type_bounds(trait_def); 525 let bounds = self.lower_type_bounds(trait_def);
524 let items = trait_def.assoc_item_list().map(|list| { 526 let items = trait_def.assoc_item_list().map(|list| {
527 let db = self.db;
525 self.with_inherited_visibility(visibility, |this| { 528 self.with_inherited_visibility(visibility, |this| {
526 list.assoc_items() 529 list.assoc_items()
527 .filter_map(|item| { 530 .filter_map(|item| {
528 let attrs = RawAttrs::new(&item, &this.hygiene); 531 let attrs = RawAttrs::new(db, &item, &this.hygiene);
529 this.collect_inner_items(item.syntax()); 532 this.collect_inner_items(item.syntax());
530 this.lower_assoc_item(&item).map(|item| { 533 this.lower_assoc_item(&item).map(|item| {
531 this.add_attrs(ModItem::from(item).into(), attrs); 534 this.add_attrs(ModItem::from(item).into(), attrs);
@@ -567,7 +570,7 @@ impl Ctx {
567 .filter_map(|item| { 570 .filter_map(|item| {
568 self.collect_inner_items(item.syntax()); 571 self.collect_inner_items(item.syntax());
569 let assoc = self.lower_assoc_item(&item)?; 572 let assoc = self.lower_assoc_item(&item)?;
570 let attrs = RawAttrs::new(&item, &self.hygiene); 573 let attrs = RawAttrs::new(self.db, &item, &self.hygiene);
571 self.add_attrs(ModItem::from(assoc).into(), attrs); 574 self.add_attrs(ModItem::from(assoc).into(), attrs);
572 Some(assoc) 575 Some(assoc)
573 }) 576 })
@@ -585,6 +588,7 @@ impl Ctx {
585 let mut imports = Vec::new(); 588 let mut imports = Vec::new();
586 let tree = self.tree.data_mut(); 589 let tree = self.tree.data_mut();
587 ModPath::expand_use_item( 590 ModPath::expand_use_item(
591 self.db,
588 InFile::new(self.file, use_item.clone()), 592 InFile::new(self.file, use_item.clone()),
589 &self.hygiene, 593 &self.hygiene,
590 |path, _use_tree, is_glob, alias| { 594 |path, _use_tree, is_glob, alias| {
@@ -618,7 +622,7 @@ impl Ctx {
618 } 622 }
619 623
620 fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> { 624 fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> {
621 let path = Interned::new(ModPath::from_src(m.path()?, &self.hygiene)?); 625 let path = Interned::new(ModPath::from_src(self.db, m.path()?, &self.hygiene)?);
622 let ast_id = self.source_ast_id_map.ast_id(m); 626 let ast_id = self.source_ast_id_map.ast_id(m);
623 let res = MacroCall { path, ast_id }; 627 let res = MacroCall { path, ast_id };
624 Some(id(self.data().macro_calls.alloc(res))) 628 Some(id(self.data().macro_calls.alloc(res)))
@@ -647,7 +651,7 @@ impl Ctx {
647 list.extern_items() 651 list.extern_items()
648 .filter_map(|item| { 652 .filter_map(|item| {
649 self.collect_inner_items(item.syntax()); 653 self.collect_inner_items(item.syntax());
650 let attrs = RawAttrs::new(&item, &self.hygiene); 654 let attrs = RawAttrs::new(self.db, &item, &self.hygiene);
651 let id: ModItem = match item { 655 let id: ModItem = match item {
652 ast::ExternItem::Fn(ast) => { 656 ast::ExternItem::Fn(ast) => {
653 let func_id = self.lower_function(&ast)?; 657 let func_id = self.lower_function(&ast)?;
@@ -755,7 +759,7 @@ impl Ctx {
755 fn lower_visibility(&mut self, item: &impl ast::VisibilityOwner) -> RawVisibilityId { 759 fn lower_visibility(&mut self, item: &impl ast::VisibilityOwner) -> RawVisibilityId {
756 let vis = match self.forced_visibility { 760 let vis = match self.forced_visibility {
757 Some(vis) => return vis, 761 Some(vis) => return vis,
758 None => RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene), 762 None => RawVisibility::from_ast_with_hygiene(self.db, item.visibility(), &self.hygiene),
759 }; 763 };
760 764
761 self.data().vis.alloc(vis) 765 self.data().vis.alloc(vis)