@@ -14,7 +14,7 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
1414use rustc_index:: vec:: { Idx , IndexVec } ;
1515use rustc_session:: utils:: NtToTokenstream ;
1616use rustc_session:: Session ;
17- use rustc_span:: source_map:: { respan , DesugaringKind } ;
17+ use rustc_span:: source_map:: DesugaringKind ;
1818use rustc_span:: symbol:: { kw, sym, Ident } ;
1919use rustc_span:: Span ;
2020use rustc_target:: spec:: abi;
@@ -230,15 +230,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
230230
231231 fn lower_item ( & mut self , i : & Item ) -> & ' hir hir:: Item < ' hir > {
232232 let mut ident = i. ident ;
233- let mut vis = self . lower_visibility ( & i. vis ) ;
233+ let vis_span = self . lower_span ( i. vis . span ) ;
234234 let hir_id = self . lower_node_id ( i. id ) ;
235235 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 ) ;
237237 let item = hir:: Item {
238238 def_id : hir_id. expect_owner ( ) ,
239239 ident : self . lower_ident ( ident) ,
240240 kind,
241- vis ,
241+ vis_span ,
242242 span : self . lower_span ( i. span ) ,
243243 } ;
244244 self . arena . alloc ( item)
@@ -251,7 +251,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
251251 hir_id : hir:: HirId ,
252252 ident : & mut Ident ,
253253 attrs : Option < & ' hir [ Attribute ] > ,
254- vis : & mut hir :: Visibility < ' hir > ,
254+ vis_span : Span ,
255255 i : & ItemKind ,
256256 ) -> hir:: ItemKind < ' hir > {
257257 match * i {
@@ -260,7 +260,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
260260 // Start with an empty prefix.
261261 let prefix = Path { segments : vec ! [ ] , span : use_tree. span , tokens : None } ;
262262
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)
264264 }
265265 ItemKind :: Static ( ref t, m, ref e) => {
266266 let ( ty, body_id) = self . lower_const_item ( t, span, e. as_deref ( ) ) ;
@@ -527,12 +527,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
527527 tree : & UseTree ,
528528 prefix : & Path ,
529529 id : NodeId ,
530- vis : & mut hir :: Visibility < ' hir > ,
530+ vis_span : Span ,
531531 ident : & mut Ident ,
532532 attrs : Option < & ' hir [ Attribute ] > ,
533533 ) -> hir:: ItemKind < ' hir > {
534534 debug ! ( "lower_use_tree(tree={:?})" , tree) ;
535- debug ! ( "lower_use_tree: vis = {:?}" , vis) ;
536535
537536 let path = & tree. prefix ;
538537 let segments = prefix. segments . iter ( ) . chain ( path. segments . iter ( ) ) . cloned ( ) . collect ( ) ;
@@ -586,7 +585,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
586585 let res = this. lower_res ( res) ;
587586 let path = this. lower_path_extra ( res, & path, ParamMode :: Explicit ) ;
588587 let kind = hir:: ItemKind :: Use ( path, hir:: UseKind :: Single ) ;
589- let vis = this. rebuild_vis ( & vis) ;
590588 if let Some ( attrs) = attrs {
591589 this. attrs . insert ( hir:: ItemLocalId :: new ( 0 ) , attrs) ;
592590 }
@@ -595,7 +593,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
595593 def_id : new_id,
596594 ident : this. lower_ident ( ident) ,
597595 kind,
598- vis ,
596+ vis_span ,
599597 span : this. lower_span ( span) ,
600598 } ;
601599 hir:: OwnerNode :: Item ( this. arena . alloc ( item) )
@@ -657,11 +655,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
657655 // own its own names, we have to adjust the owner before
658656 // lowering the rest of the import.
659657 self . with_hir_id_owner ( id, |this| {
660- let mut vis = this. rebuild_vis ( & vis) ;
661658 let mut ident = * ident;
662659
663660 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) ;
665662 if let Some ( attrs) = attrs {
666663 this. attrs . insert ( hir:: ItemLocalId :: new ( 0 ) , attrs) ;
667664 }
@@ -670,37 +667,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
670667 def_id : new_hir_id,
671668 ident : this. lower_ident ( ident) ,
672669 kind,
673- vis ,
670+ vis_span ,
674671 span : this. lower_span ( use_tree. span ) ,
675672 } ;
676673 hir:: OwnerNode :: Item ( this. arena . alloc ( item) )
677674 } ) ;
678675 }
679676
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-
704677 let res = self . expect_full_res_from_use ( id) . next ( ) . unwrap_or ( Res :: Err ) ;
705678 let res = self . lower_res ( res) ;
706679 let path = self . lower_path_extra ( res, & prefix, ParamMode :: Explicit ) ;
@@ -709,37 +682,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
709682 }
710683 }
711684
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-
743685 fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> & ' hir hir:: ForeignItem < ' hir > {
744686 let hir_id = self . lower_node_id ( i. id ) ;
745687 let def_id = hir_id. expect_owner ( ) ;
@@ -773,7 +715,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
773715 ForeignItemKind :: TyAlias ( ..) => hir:: ForeignItemKind :: Type ,
774716 ForeignItemKind :: MacCall ( _) => panic ! ( "macro shouldn't exist here" ) ,
775717 } ,
776- vis : self . lower_visibility ( & i. vis ) ,
718+ vis_span : self . lower_span ( i. vis . span ) ,
777719 span : self . lower_span ( i. span ) ,
778720 } ;
779721 self . arena . alloc ( item)
@@ -851,7 +793,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
851793 // FIXME(jseyfried): positional field hygiene.
852794 None => Ident :: new ( sym:: integer ( index) , self . lower_span ( f. span ) ) ,
853795 } ,
854- vis : self . lower_visibility ( & f. vis ) ,
796+ vis_span : self . lower_span ( f. vis . span ) ,
855797 ty,
856798 }
857799 }
@@ -1016,8 +958,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
1016958 def_id : hir_id. expect_owner ( ) ,
1017959 ident : self . lower_ident ( i. ident ) ,
1018960 generics,
1019- vis : self . lower_visibility ( & i. vis ) ,
1020961 kind,
962+ vis_span : self . lower_span ( i. vis . span ) ,
1021963 span : self . lower_span ( i. span ) ,
1022964 } ;
1023965 self . arena . alloc ( item)
@@ -1044,28 +986,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1044986 }
1045987 }
1046988
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-
1069989 fn lower_defaultness (
1070990 & self ,
1071991 d : Defaultness ,
0 commit comments