1
1
//! AST -> `ItemTree` lowering code.
2
2
3
- use std:: { collections:: hash_map:: Entry , mem , sync:: Arc } ;
3
+ use std:: { collections:: hash_map:: Entry , sync:: Arc } ;
4
4
5
5
use hir_expand:: { ast_id_map:: AstIdMap , hygiene:: Hygiene , HirFileId } ;
6
6
use syntax:: ast:: { self , HasModuleItem } ;
@@ -21,7 +21,6 @@ pub(super) struct Ctx<'a> {
21
21
tree : ItemTree ,
22
22
source_ast_id_map : Arc < AstIdMap > ,
23
23
body_ctx : crate :: body:: LowerCtx < ' a > ,
24
- forced_visibility : Option < RawVisibilityId > ,
25
24
}
26
25
27
26
impl < ' a > Ctx < ' a > {
@@ -31,7 +30,6 @@ impl<'a> Ctx<'a> {
31
30
tree : ItemTree :: default ( ) ,
32
31
source_ast_id_map : db. ast_id_map ( file) ,
33
32
body_ctx : crate :: body:: LowerCtx :: new ( db, file) ,
34
- forced_visibility : None ,
35
33
}
36
34
}
37
35
@@ -225,11 +223,10 @@ impl<'a> Ctx<'a> {
225
223
let visibility = self . lower_visibility ( enum_) ;
226
224
let name = enum_. name ( ) ?. as_name ( ) ;
227
225
let generic_params = self . lower_generic_params ( GenericsOwner :: Enum , enum_) ;
228
- let variants =
229
- self . with_inherited_visibility ( visibility, |this| match & enum_. variant_list ( ) {
230
- Some ( variant_list) => this. lower_variants ( variant_list) ,
231
- None => IdxRange :: new ( this. next_variant_idx ( ) ..this. next_variant_idx ( ) ) ,
232
- } ) ;
226
+ let variants = match & enum_. variant_list ( ) {
227
+ Some ( variant_list) => self . lower_variants ( variant_list) ,
228
+ None => IdxRange :: new ( self . next_variant_idx ( ) ..self . next_variant_idx ( ) ) ,
229
+ } ;
233
230
let ast_id = self . source_ast_id_map . ast_id ( enum_) ;
234
231
let res = Enum { name, visibility, generic_params, variants, ast_id } ;
235
232
Some ( id ( self . data ( ) . enums . alloc ( res) ) )
@@ -440,18 +437,15 @@ impl<'a> Ctx<'a> {
440
437
let is_auto = trait_def. auto_token ( ) . is_some ( ) ;
441
438
let is_unsafe = trait_def. unsafe_token ( ) . is_some ( ) ;
442
439
let items = trait_def. assoc_item_list ( ) . map ( |list| {
443
- let db = self . db ;
444
- self . with_inherited_visibility ( visibility, |this| {
445
- list. assoc_items ( )
446
- . filter_map ( |item| {
447
- let attrs = RawAttrs :: new ( db, & item, this. hygiene ( ) ) ;
448
- this. lower_assoc_item ( & item) . map ( |item| {
449
- this. add_attrs ( ModItem :: from ( item) . into ( ) , attrs) ;
450
- item
451
- } )
440
+ list. assoc_items ( )
441
+ . filter_map ( |item| {
442
+ let attrs = RawAttrs :: new ( self . db , & item, self . hygiene ( ) ) ;
443
+ self . lower_assoc_item ( & item) . map ( |item| {
444
+ self . add_attrs ( ModItem :: from ( item) . into ( ) , attrs) ;
445
+ item
452
446
} )
453
- . collect ( )
454
- } )
447
+ } )
448
+ . collect ( )
455
449
} ) ;
456
450
let ast_id = self . source_ast_id_map . ast_id ( trait_def) ;
457
451
let res = Trait {
@@ -622,13 +616,7 @@ impl<'a> Ctx<'a> {
622
616
}
623
617
624
618
fn lower_visibility ( & mut self , item : & dyn ast:: HasVisibility ) -> RawVisibilityId {
625
- let vis = match self . forced_visibility {
626
- Some ( vis) => return vis,
627
- None => {
628
- RawVisibility :: from_ast_with_hygiene ( self . db , item. visibility ( ) , self . hygiene ( ) )
629
- }
630
- } ;
631
-
619
+ let vis = RawVisibility :: from_ast_with_hygiene ( self . db , item. visibility ( ) , self . hygiene ( ) ) ;
632
620
self . data ( ) . vis . alloc ( vis)
633
621
}
634
622
@@ -649,18 +637,6 @@ impl<'a> Ctx<'a> {
649
637
}
650
638
}
651
639
652
- /// Forces the visibility `vis` to be used for all items lowered during execution of `f`.
653
- fn with_inherited_visibility < R > (
654
- & mut self ,
655
- vis : RawVisibilityId ,
656
- f : impl FnOnce ( & mut Self ) -> R ,
657
- ) -> R {
658
- let old = mem:: replace ( & mut self . forced_visibility , Some ( vis) ) ;
659
- let res = f ( self ) ;
660
- self . forced_visibility = old;
661
- res
662
- }
663
-
664
640
fn next_field_idx ( & self ) -> Idx < Field > {
665
641
Idx :: from_raw ( RawIdx :: from (
666
642
self . tree . data . as_ref ( ) . map_or ( 0 , |data| data. fields . len ( ) as u32 ) ,
0 commit comments