@@ -55,6 +55,38 @@ impl<'r, 'a> EffectiveVisibilitiesVisitor<'r, 'a> {
5555 visit:: walk_crate ( & mut visitor, krate) ;
5656 }
5757
58+ // Update visibilities for import def ids. These are not used during the
59+ // `EffectiveVisibilitiesVisitor` pass, because we have more detailed binding-based
60+ // information, but are used by later passes. Effective visibility of an import def id
61+ // is the maximum value among visibilities of bindings corresponding to that def id.
62+ for ( binding, eff_vis) in visitor. import_effective_visibilities . iter ( ) {
63+ let NameBindingKind :: Import { import, .. } = binding. kind else { unreachable ! ( ) } ;
64+ if let Some ( node_id) = import. id ( ) {
65+ let mut update = |node_id| {
66+ r. effective_visibilities . update_eff_vis (
67+ r. local_def_id ( node_id) ,
68+ eff_vis,
69+ ResolverTree ( & r. definitions , & r. crate_loader ) ,
70+ )
71+ } ;
72+ update ( node_id) ;
73+ if let ImportKind :: Single { additional_ids : ( id1, id2) , .. } = import. kind {
74+ // In theory all the single import IDs have individual visibilities and
75+ // effective visibilities, but in practice these IDs go straigth to HIR
76+ // where all their few uses assume that their (effective) visibility
77+ // applies to the whole syntactic `use` item. So they all get the same
78+ // value which is the maximum of all bindings. Maybe HIR for imports
79+ // shouldn't use three IDs at all.
80+ if id1 != ast:: DUMMY_NODE_ID {
81+ update ( id1) ;
82+ }
83+ if id2 != ast:: DUMMY_NODE_ID {
84+ update ( id2) ;
85+ }
86+ }
87+ }
88+ }
89+
5890 info ! ( "resolve::effective_visibilities: {:#?}" , r. effective_visibilities) ;
5991 }
6092
@@ -75,41 +107,10 @@ impl<'r, 'a> EffectiveVisibilitiesVisitor<'r, 'a> {
75107 // sets the rest of the `use` chain to `Level::Reexported` until
76108 // we hit the actual exported item.
77109 let mut parent_id = ParentId :: Def ( module_id) ;
78- while let NameBindingKind :: Import { binding : nested_binding, import, .. } =
79- binding. kind
80- {
110+ while let NameBindingKind :: Import { binding : nested_binding, .. } = binding. kind {
81111 let binding_id = ImportId :: new_unchecked ( binding) ;
82112 self . update_import ( binding_id, parent_id) ;
83113
84- // Update visibilities for import ids. These are not used during this pass,
85- // because we have more detailed binding-based information, but are used by
86- // later passes. Effective visibility of an import def id is the maximum value
87- // among visibilities of bindings corresponding to that def id.
88- if let Some ( node_id) = import. id ( ) {
89- let mut update = |node_id| {
90- self . update_def (
91- self . r . local_def_id ( node_id) ,
92- binding. vis . expect_local ( ) ,
93- parent_id,
94- )
95- } ;
96- update ( node_id) ;
97- if let ImportKind :: Single { additional_ids : ( id1, id2) , .. } = import. kind {
98- // In theory all the single import IDs have individual visibilities and
99- // effective visibilities, but in practice these IDs go straigth to HIR
100- // where all their few uses assume that their (effective) visibility
101- // applies to the whole syntactic `use` item. So they all get the same
102- // value which is the maximum of all bindings. Maybe HIR for imports
103- // shouldn't use three IDs at all.
104- if id1 != ast:: DUMMY_NODE_ID {
105- update ( id1) ;
106- }
107- if id2 != ast:: DUMMY_NODE_ID {
108- update ( id2) ;
109- }
110- }
111- }
112-
113114 parent_id = ParentId :: Import ( binding_id) ;
114115 binding = nested_binding;
115116 }
0 commit comments