@@ -14,7 +14,7 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
14
14
use rustc_index:: vec:: { Idx , IndexVec } ;
15
15
use rustc_session:: utils:: NtToTokenstream ;
16
16
use rustc_session:: Session ;
17
- use rustc_span:: source_map:: { respan , DesugaringKind } ;
17
+ use rustc_span:: source_map:: DesugaringKind ;
18
18
use rustc_span:: symbol:: { kw, sym, Ident } ;
19
19
use rustc_span:: Span ;
20
20
use rustc_target:: spec:: abi;
@@ -230,15 +230,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
230
230
231
231
fn lower_item ( & mut self , i : & Item ) -> & ' hir hir:: Item < ' hir > {
232
232
let mut ident = i. ident ;
233
- let mut vis = self . lower_visibility ( & i. vis ) ;
233
+ let vis_span = self . lower_span ( i. vis . span ) ;
234
234
let hir_id = self . lower_node_id ( i. id ) ;
235
235
let attrs = self . lower_attrs ( hir_id, & i. attrs ) ;
236
- let kind = self . lower_item_kind ( i. span , i. id , hir_id, & mut ident, attrs, & mut vis , & i. kind ) ;
236
+ let kind = self . lower_item_kind ( i. span , i. id , hir_id, & mut ident, attrs, vis_span , & i. kind ) ;
237
237
let item = hir:: Item {
238
238
def_id : hir_id. expect_owner ( ) ,
239
239
ident : self . lower_ident ( ident) ,
240
240
kind,
241
- vis ,
241
+ vis_span ,
242
242
span : self . lower_span ( i. span ) ,
243
243
} ;
244
244
self . arena . alloc ( item)
@@ -251,7 +251,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
251
251
hir_id : hir:: HirId ,
252
252
ident : & mut Ident ,
253
253
attrs : Option < & ' hir [ Attribute ] > ,
254
- vis : & mut hir :: Visibility < ' hir > ,
254
+ vis_span : Span ,
255
255
i : & ItemKind ,
256
256
) -> hir:: ItemKind < ' hir > {
257
257
match * i {
@@ -260,7 +260,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
260
260
// Start with an empty prefix.
261
261
let prefix = Path { segments : vec ! [ ] , span : use_tree. span , tokens : None } ;
262
262
263
- self . lower_use_tree ( use_tree, & prefix, id, vis , ident, attrs)
263
+ self . lower_use_tree ( use_tree, & prefix, id, vis_span , ident, attrs)
264
264
}
265
265
ItemKind :: Static ( ref t, m, ref e) => {
266
266
let ( ty, body_id) = self . lower_const_item ( t, span, e. as_deref ( ) ) ;
@@ -527,12 +527,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
527
527
tree : & UseTree ,
528
528
prefix : & Path ,
529
529
id : NodeId ,
530
- vis : & mut hir :: Visibility < ' hir > ,
530
+ vis_span : Span ,
531
531
ident : & mut Ident ,
532
532
attrs : Option < & ' hir [ Attribute ] > ,
533
533
) -> hir:: ItemKind < ' hir > {
534
534
debug ! ( "lower_use_tree(tree={:?})" , tree) ;
535
- debug ! ( "lower_use_tree: vis = {:?}" , vis) ;
536
535
537
536
let path = & tree. prefix ;
538
537
let segments = prefix. segments . iter ( ) . chain ( path. segments . iter ( ) ) . cloned ( ) . collect ( ) ;
@@ -586,7 +585,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
586
585
let res = this. lower_res ( res) ;
587
586
let path = this. lower_path_extra ( res, & path, ParamMode :: Explicit ) ;
588
587
let kind = hir:: ItemKind :: Use ( path, hir:: UseKind :: Single ) ;
589
- let vis = this. rebuild_vis ( & vis) ;
590
588
if let Some ( attrs) = attrs {
591
589
this. attrs . insert ( hir:: ItemLocalId :: new ( 0 ) , attrs) ;
592
590
}
@@ -595,7 +593,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
595
593
def_id : new_id,
596
594
ident : this. lower_ident ( ident) ,
597
595
kind,
598
- vis ,
596
+ vis_span ,
599
597
span : this. lower_span ( span) ,
600
598
} ;
601
599
hir:: OwnerNode :: Item ( this. arena . alloc ( item) )
@@ -657,11 +655,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
657
655
// own its own names, we have to adjust the owner before
658
656
// lowering the rest of the import.
659
657
self . with_hir_id_owner ( id, |this| {
660
- let mut vis = this. rebuild_vis ( & vis) ;
661
658
let mut ident = * ident;
662
659
663
660
let kind =
664
- this. lower_use_tree ( use_tree, & prefix, id, & mut vis , & mut ident, attrs) ;
661
+ this. lower_use_tree ( use_tree, & prefix, id, vis_span , & mut ident, attrs) ;
665
662
if let Some ( attrs) = attrs {
666
663
this. attrs . insert ( hir:: ItemLocalId :: new ( 0 ) , attrs) ;
667
664
}
@@ -670,37 +667,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
670
667
def_id : new_hir_id,
671
668
ident : this. lower_ident ( ident) ,
672
669
kind,
673
- vis ,
670
+ vis_span ,
674
671
span : this. lower_span ( use_tree. span ) ,
675
672
} ;
676
673
hir:: OwnerNode :: Item ( this. arena . alloc ( item) )
677
674
} ) ;
678
675
}
679
676
680
- // Subtle and a bit hacky: we lower the privacy level
681
- // of the list stem to "private" most of the time, but
682
- // not for "restricted" paths. The key thing is that
683
- // we don't want it to stay as `pub` (with no caveats)
684
- // because that affects rustdoc and also the lints
685
- // about `pub` items. But we can't *always* make it
686
- // private -- particularly not for restricted paths --
687
- // because it contains node-ids that would then be
688
- // unused, failing the check that HirIds are "densely
689
- // assigned".
690
- match vis. node {
691
- hir:: VisibilityKind :: Public
692
- | hir:: VisibilityKind :: Crate ( _)
693
- | hir:: VisibilityKind :: Inherited => {
694
- * vis = respan (
695
- self . lower_span ( prefix. span . shrink_to_lo ( ) ) ,
696
- hir:: VisibilityKind :: Inherited ,
697
- ) ;
698
- }
699
- hir:: VisibilityKind :: Restricted { .. } => {
700
- // Do nothing here, as described in the comment on the match.
701
- }
702
- }
703
-
704
677
let res = self . expect_full_res_from_use ( id) . next ( ) . unwrap_or ( Res :: Err ) ;
705
678
let res = self . lower_res ( res) ;
706
679
let path = self . lower_path_extra ( res, & prefix, ParamMode :: Explicit ) ;
@@ -709,37 +682,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
709
682
}
710
683
}
711
684
712
- /// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated
713
- /// many times in the HIR tree; for each occurrence, we need to assign distinct
714
- /// `NodeId`s. (See, e.g., #56128.)
715
- fn rebuild_use_path ( & mut self , path : & hir:: Path < ' hir > ) -> & ' hir hir:: Path < ' hir > {
716
- debug ! ( "rebuild_use_path(path = {:?})" , path) ;
717
- let segments =
718
- self . arena . alloc_from_iter ( path. segments . iter ( ) . map ( |seg| hir:: PathSegment {
719
- ident : seg. ident ,
720
- hir_id : seg. hir_id . map ( |_| self . next_id ( ) ) ,
721
- res : seg. res ,
722
- args : None ,
723
- infer_args : seg. infer_args ,
724
- } ) ) ;
725
- self . arena . alloc ( hir:: Path { span : path. span , res : path. res , segments } )
726
- }
727
-
728
- fn rebuild_vis ( & mut self , vis : & hir:: Visibility < ' hir > ) -> hir:: Visibility < ' hir > {
729
- let vis_kind = match vis. node {
730
- hir:: VisibilityKind :: Public => hir:: VisibilityKind :: Public ,
731
- hir:: VisibilityKind :: Crate ( sugar) => hir:: VisibilityKind :: Crate ( sugar) ,
732
- hir:: VisibilityKind :: Inherited => hir:: VisibilityKind :: Inherited ,
733
- hir:: VisibilityKind :: Restricted { ref path, hir_id : _ } => {
734
- hir:: VisibilityKind :: Restricted {
735
- path : self . rebuild_use_path ( path) ,
736
- hir_id : self . next_id ( ) ,
737
- }
738
- }
739
- } ;
740
- respan ( self . lower_span ( vis. span ) , vis_kind)
741
- }
742
-
743
685
fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> & ' hir hir:: ForeignItem < ' hir > {
744
686
let hir_id = self . lower_node_id ( i. id ) ;
745
687
let def_id = hir_id. expect_owner ( ) ;
@@ -773,7 +715,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
773
715
ForeignItemKind :: TyAlias ( ..) => hir:: ForeignItemKind :: Type ,
774
716
ForeignItemKind :: MacCall ( _) => panic ! ( "macro shouldn't exist here" ) ,
775
717
} ,
776
- vis : self . lower_visibility ( & i. vis ) ,
718
+ vis_span : self . lower_span ( i. vis . span ) ,
777
719
span : self . lower_span ( i. span ) ,
778
720
} ;
779
721
self . arena . alloc ( item)
@@ -851,7 +793,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
851
793
// FIXME(jseyfried): positional field hygiene.
852
794
None => Ident :: new ( sym:: integer ( index) , self . lower_span ( f. span ) ) ,
853
795
} ,
854
- vis : self . lower_visibility ( & f. vis ) ,
796
+ vis_span : self . lower_span ( f. vis . span ) ,
855
797
ty,
856
798
}
857
799
}
@@ -1016,8 +958,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1016
958
def_id : hir_id. expect_owner ( ) ,
1017
959
ident : self . lower_ident ( i. ident ) ,
1018
960
generics,
1019
- vis : self . lower_visibility ( & i. vis ) ,
1020
961
kind,
962
+ vis_span : self . lower_span ( i. vis . span ) ,
1021
963
span : self . lower_span ( i. span ) ,
1022
964
} ;
1023
965
self . arena . alloc ( item)
@@ -1044,28 +986,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1044
986
}
1045
987
}
1046
988
1047
- /// If an `explicit_owner` is given, this method allocates the `HirId` in
1048
- /// the address space of that item instead of the item currently being
1049
- /// lowered. This can happen during `lower_impl_item_ref()` where we need to
1050
- /// lower a `Visibility` value although we haven't lowered the owning
1051
- /// `ImplItem` in question yet.
1052
- fn lower_visibility ( & mut self , v : & Visibility ) -> hir:: Visibility < ' hir > {
1053
- let node = match v. kind {
1054
- VisibilityKind :: Public => hir:: VisibilityKind :: Public ,
1055
- VisibilityKind :: Crate ( sugar) => hir:: VisibilityKind :: Crate ( sugar) ,
1056
- VisibilityKind :: Restricted { ref path, id } => {
1057
- debug ! ( "lower_visibility: restricted path id = {:?}" , id) ;
1058
- let lowered_id = self . lower_node_id ( id) ;
1059
- hir:: VisibilityKind :: Restricted {
1060
- path : self . lower_path ( id, path, ParamMode :: Explicit ) ,
1061
- hir_id : lowered_id,
1062
- }
1063
- }
1064
- VisibilityKind :: Inherited => hir:: VisibilityKind :: Inherited ,
1065
- } ;
1066
- respan ( self . lower_span ( v. span ) , node)
1067
- }
1068
-
1069
989
fn lower_defaultness (
1070
990
& self ,
1071
991
d : Defaultness ,
0 commit comments