@@ -19,24 +19,26 @@ fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
19
19
pub ( super ) struct Ctx < ' a > {
20
20
db : & ' a dyn DefDatabase ,
21
21
tree : ItemTree ,
22
- hygiene : Hygiene ,
23
22
source_ast_id_map : Arc < AstIdMap > ,
24
23
body_ctx : crate :: body:: LowerCtx < ' a > ,
25
24
forced_visibility : Option < RawVisibilityId > ,
26
25
}
27
26
28
27
impl < ' a > Ctx < ' a > {
29
- pub ( super ) fn new ( db : & ' a dyn DefDatabase , hygiene : Hygiene , file : HirFileId ) -> Self {
28
+ pub ( super ) fn new ( db : & ' a dyn DefDatabase , file : HirFileId ) -> Self {
30
29
Self {
31
30
db,
32
31
tree : ItemTree :: default ( ) ,
33
- hygiene,
34
32
source_ast_id_map : db. ast_id_map ( file) ,
35
33
body_ctx : crate :: body:: LowerCtx :: new ( db, file) ,
36
34
forced_visibility : None ,
37
35
}
38
36
}
39
37
38
+ pub ( super ) fn hygiene ( & self ) -> & Hygiene {
39
+ self . body_ctx . hygiene ( )
40
+ }
41
+
40
42
pub ( super ) fn lower_module_items ( mut self , item_owner : & dyn HasModuleItem ) -> ItemTree {
41
43
self . tree . top_level =
42
44
item_owner. items ( ) . flat_map ( |item| self . lower_mod_item ( & item) ) . collect ( ) ;
@@ -88,7 +90,7 @@ impl<'a> Ctx<'a> {
88
90
}
89
91
90
92
fn lower_mod_item ( & mut self , item : & ast:: Item ) -> Option < ModItem > {
91
- let attrs = RawAttrs :: new ( self . db , item, & self . hygiene ) ;
93
+ let attrs = RawAttrs :: new ( self . db , item, self . hygiene ( ) ) ;
92
94
let item: ModItem = match item {
93
95
ast:: Item :: Struct ( ast) => self . lower_struct ( ast) ?. into ( ) ,
94
96
ast:: Item :: Union ( ast) => self . lower_union ( ast) ?. into ( ) ,
@@ -162,7 +164,7 @@ impl<'a> Ctx<'a> {
162
164
for field in fields. fields ( ) {
163
165
if let Some ( data) = self . lower_record_field ( & field) {
164
166
let idx = self . data ( ) . fields . alloc ( data) ;
165
- self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & field, & self . hygiene ) ) ;
167
+ self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & field, self . hygiene ( ) ) ) ;
166
168
}
167
169
}
168
170
let end = self . next_field_idx ( ) ;
@@ -182,7 +184,7 @@ impl<'a> Ctx<'a> {
182
184
for ( i, field) in fields. fields ( ) . enumerate ( ) {
183
185
let data = self . lower_tuple_field ( i, & field) ;
184
186
let idx = self . data ( ) . fields . alloc ( data) ;
185
- self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & field, & self . hygiene ) ) ;
187
+ self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & field, self . hygiene ( ) ) ) ;
186
188
}
187
189
let end = self . next_field_idx ( ) ;
188
190
IdxRange :: new ( start..end)
@@ -227,7 +229,7 @@ impl<'a> Ctx<'a> {
227
229
for variant in variants. variants ( ) {
228
230
if let Some ( data) = self . lower_variant ( & variant) {
229
231
let idx = self . data ( ) . variants . alloc ( data) ;
230
- self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & variant, & self . hygiene ) ) ;
232
+ self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & variant, self . hygiene ( ) ) ) ;
231
233
}
232
234
}
233
235
let end = self . next_variant_idx ( ) ;
@@ -270,7 +272,7 @@ impl<'a> Ctx<'a> {
270
272
} ;
271
273
let ty = Interned :: new ( self_type) ;
272
274
let idx = self . data ( ) . params . alloc ( Param :: Normal ( None , ty) ) ;
273
- self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & self_param, & self . hygiene ) ) ;
275
+ self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & self_param, self . hygiene ( ) ) ) ;
274
276
has_self_param = true ;
275
277
}
276
278
for param in param_list. params ( ) {
@@ -294,7 +296,7 @@ impl<'a> Ctx<'a> {
294
296
self . data ( ) . params . alloc ( Param :: Normal ( name, ty) )
295
297
}
296
298
} ;
297
- self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & param, & self . hygiene ) ) ;
299
+ self . add_attrs ( idx. into ( ) , RawAttrs :: new ( self . db , & param, self . hygiene ( ) ) ) ;
298
300
}
299
301
}
300
302
let end_param = self . next_param_idx ( ) ;
@@ -427,7 +429,7 @@ impl<'a> Ctx<'a> {
427
429
self . with_inherited_visibility ( visibility, |this| {
428
430
list. assoc_items ( )
429
431
. filter_map ( |item| {
430
- let attrs = RawAttrs :: new ( db, & item, & this. hygiene ) ;
432
+ let attrs = RawAttrs :: new ( db, & item, this. hygiene ( ) ) ;
431
433
this. lower_assoc_item ( & item) . map ( |item| {
432
434
this. add_attrs ( ModItem :: from ( item) . into ( ) , attrs) ;
433
435
item
@@ -465,7 +467,7 @@ impl<'a> Ctx<'a> {
465
467
. flat_map ( |it| it. assoc_items ( ) )
466
468
. filter_map ( |item| {
467
469
let assoc = self . lower_assoc_item ( & item) ?;
468
- let attrs = RawAttrs :: new ( self . db , & item, & self . hygiene ) ;
470
+ let attrs = RawAttrs :: new ( self . db , & item, self . hygiene ( ) ) ;
469
471
self . add_attrs ( ModItem :: from ( assoc) . into ( ) , attrs) ;
470
472
Some ( assoc)
471
473
} )
@@ -478,7 +480,7 @@ impl<'a> Ctx<'a> {
478
480
fn lower_use ( & mut self , use_item : & ast:: Use ) -> Option < FileItemTreeId < Import > > {
479
481
let visibility = self . lower_visibility ( use_item) ;
480
482
let ast_id = self . source_ast_id_map . ast_id ( use_item) ;
481
- let ( use_tree, _) = lower_use_tree ( self . db , & self . hygiene , use_item. use_tree ( ) ?) ?;
483
+ let ( use_tree, _) = lower_use_tree ( self . db , self . hygiene ( ) , use_item. use_tree ( ) ?) ?;
482
484
483
485
let res = Import { visibility, ast_id, use_tree } ;
484
486
Some ( id ( self . data ( ) . imports . alloc ( res) ) )
@@ -500,7 +502,7 @@ impl<'a> Ctx<'a> {
500
502
}
501
503
502
504
fn lower_macro_call ( & mut self , m : & ast:: MacroCall ) -> Option < FileItemTreeId < MacroCall > > {
503
- let path = Interned :: new ( ModPath :: from_src ( self . db , m. path ( ) ?, & self . hygiene ) ?) ;
505
+ let path = Interned :: new ( ModPath :: from_src ( self . db , m. path ( ) ?, self . hygiene ( ) ) ?) ;
504
506
let ast_id = self . source_ast_id_map . ast_id ( m) ;
505
507
let expand_to = hir_expand:: ExpandTo :: from_call_site ( m) ;
506
508
let res = MacroCall { path, ast_id, expand_to } ;
@@ -535,7 +537,7 @@ impl<'a> Ctx<'a> {
535
537
// (in other words, the knowledge that they're in an extern block must not be used).
536
538
// This is because an extern block can contain macros whose ItemTree's top-level items
537
539
// should be considered to be in an extern block too.
538
- let attrs = RawAttrs :: new ( self . db , & item, & self . hygiene ) ;
540
+ let attrs = RawAttrs :: new ( self . db , & item, self . hygiene ( ) ) ;
539
541
let id: ModItem = match item {
540
542
ast:: ExternItem :: Fn ( ast) => {
541
543
let func_id = self . lower_function ( & ast) ?;
@@ -616,7 +618,9 @@ impl<'a> Ctx<'a> {
616
618
fn lower_visibility ( & mut self , item : & dyn ast:: HasVisibility ) -> RawVisibilityId {
617
619
let vis = match self . forced_visibility {
618
620
Some ( vis) => return vis,
619
- None => RawVisibility :: from_ast_with_hygiene ( self . db , item. visibility ( ) , & self . hygiene ) ,
621
+ None => {
622
+ RawVisibility :: from_ast_with_hygiene ( self . db , item. visibility ( ) , self . hygiene ( ) )
623
+ }
620
624
} ;
621
625
622
626
self . data ( ) . vis . alloc ( vis)
0 commit comments