@@ -31,18 +31,20 @@ where
3131 }
3232}
3333
34- pub ( super ) struct Ctx {
34+ pub ( super ) struct Ctx < ' a > {
35+ db : & ' a dyn DefDatabase ,
3536 tree : ItemTree ,
3637 hygiene : Hygiene ,
3738 file : HirFileId ,
3839 source_ast_id_map : Arc < AstIdMap > ,
39- body_ctx : crate :: body:: LowerCtx ,
40+ body_ctx : crate :: body:: LowerCtx < ' a > ,
4041 forced_visibility : Option < RawVisibilityId > ,
4142}
4243
43- impl Ctx {
44- pub ( super ) fn new ( db : & dyn DefDatabase , hygiene : Hygiene , file : HirFileId ) -> Self {
44+ impl < ' a > Ctx < ' a > {
45+ pub ( super ) fn new ( db : & ' a dyn DefDatabase , hygiene : Hygiene , file : HirFileId ) -> Self {
4546 Self {
47+ db,
4648 tree : ItemTree :: default ( ) ,
4749 hygiene,
4850 file,
@@ -126,7 +128,7 @@ impl Ctx {
126128 | ast:: Item :: MacroDef ( _) => { }
127129 } ;
128130
129- let attrs = RawAttrs :: new ( item, & self . hygiene ) ;
131+ let attrs = RawAttrs :: new ( self . db , item, & self . hygiene ) ;
130132 let items = match item {
131133 ast:: Item :: Struct ( ast) => self . lower_struct ( ast) . map ( Into :: into) ,
132134 ast:: Item :: Union ( ast) => self . lower_union ( ast) . map ( Into :: into) ,
@@ -256,7 +258,7 @@ impl Ctx {
256258 for field in fields. fields ( ) {
257259 if let Some ( data) = self . lower_record_field ( & field) {
258260 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 ) ) ;
260262 }
261263 }
262264 let end = self . next_field_idx ( ) ;
@@ -276,7 +278,7 @@ impl Ctx {
276278 for ( i, field) in fields. fields ( ) . enumerate ( ) {
277279 let data = self . lower_tuple_field ( i, & field) ;
278280 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 ) ) ;
280282 }
281283 let end = self . next_field_idx ( ) ;
282284 IdRange :: new ( start..end)
@@ -321,7 +323,7 @@ impl Ctx {
321323 for variant in variants. variants ( ) {
322324 if let Some ( data) = self . lower_variant ( & variant) {
323325 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 ) ) ;
325327 }
326328 }
327329 let end = self . next_variant_idx ( ) ;
@@ -364,7 +366,7 @@ impl Ctx {
364366 } ;
365367 let ty = Interned :: new ( self_type) ;
366368 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 ) ) ;
368370 has_self_param = true ;
369371 }
370372 for param in param_list. params ( ) {
@@ -376,7 +378,7 @@ impl Ctx {
376378 self . data ( ) . params . alloc ( Param :: Normal ( ty) )
377379 }
378380 } ;
379- self . add_attrs ( idx. into ( ) , RawAttrs :: new ( & param, & self . hygiene ) ) ;
381+ self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & param, & self . hygiene ) ) ;
380382 }
381383 }
382384 let end_param = self . next_param_idx ( ) ;
@@ -522,10 +524,11 @@ impl Ctx {
522524 let is_unsafe = trait_def. unsafe_token ( ) . is_some ( ) ;
523525 let bounds = self . lower_type_bounds ( trait_def) ;
524526 let items = trait_def. assoc_item_list ( ) . map ( |list| {
527+ let db = self . db ;
525528 self . with_inherited_visibility ( visibility, |this| {
526529 list. assoc_items ( )
527530 . filter_map ( |item| {
528- let attrs = RawAttrs :: new ( & item, & this. hygiene ) ;
531+ let attrs = RawAttrs :: new ( db , & item, & this. hygiene ) ;
529532 this. collect_inner_items ( item. syntax ( ) ) ;
530533 this. lower_assoc_item ( & item) . map ( |item| {
531534 this. add_attrs ( ModItem :: from ( item) . into ( ) , attrs) ;
@@ -567,7 +570,7 @@ impl Ctx {
567570 . filter_map ( |item| {
568571 self . collect_inner_items ( item. syntax ( ) ) ;
569572 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 ) ;
571574 self . add_attrs ( ModItem :: from ( assoc) . into ( ) , attrs) ;
572575 Some ( assoc)
573576 } )
@@ -585,6 +588,7 @@ impl Ctx {
585588 let mut imports = Vec :: new ( ) ;
586589 let tree = self . tree . data_mut ( ) ;
587590 ModPath :: expand_use_item (
591+ self . db ,
588592 InFile :: new ( self . file , use_item. clone ( ) ) ,
589593 & self . hygiene ,
590594 |path, _use_tree, is_glob, alias| {
@@ -618,7 +622,7 @@ impl Ctx {
618622 }
619623
620624 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 ) ?) ;
622626 let ast_id = self . source_ast_id_map . ast_id ( m) ;
623627 let res = MacroCall { path, ast_id } ;
624628 Some ( id ( self . data ( ) . macro_calls . alloc ( res) ) )
@@ -647,7 +651,7 @@ impl Ctx {
647651 list. extern_items ( )
648652 . filter_map ( |item| {
649653 self . collect_inner_items ( item. syntax ( ) ) ;
650- let attrs = RawAttrs :: new ( & item, & self . hygiene ) ;
654+ let attrs = RawAttrs :: new ( self . db , & item, & self . hygiene ) ;
651655 let id: ModItem = match item {
652656 ast:: ExternItem :: Fn ( ast) => {
653657 let func_id = self . lower_function ( & ast) ?;
@@ -755,7 +759,7 @@ impl Ctx {
755759 fn lower_visibility ( & mut self , item : & impl ast:: VisibilityOwner ) -> RawVisibilityId {
756760 let vis = match self . forced_visibility {
757761 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 ) ,
759763 } ;
760764
761765 self . data ( ) . vis . alloc ( vis)
0 commit comments