@@ -6,8 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
66use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
77use rustc_macros:: HashStable ;
88use rustc_query_system:: ich:: StableHashingContext ;
9- use rustc_span:: def_id:: { DefId , LocalDefId } ;
10- use std:: hash:: Hash ;
9+ use rustc_span:: def_id:: LocalDefId ;
1110
1211/// Represents the levels of effective visibility an item can have.
1312///
@@ -75,33 +74,33 @@ impl EffectiveVisibility {
7574}
7675
7776/// Holds a map of effective visibilities for reachable HIR nodes.
78- #[ derive( Debug , Clone ) ]
79- pub struct EffectiveVisibilities < Id = LocalDefId > {
80- map : FxHashMap < Id , EffectiveVisibility > ,
77+ #[ derive( Default , Clone , Debug ) ]
78+ pub struct EffectiveVisibilities {
79+ map : FxHashMap < LocalDefId , EffectiveVisibility > ,
8180}
8281
83- impl < Id : Hash + Eq + Copy > EffectiveVisibilities < Id > {
84- pub fn is_public_at_level ( & self , id : Id , level : Level ) -> bool {
82+ impl EffectiveVisibilities {
83+ pub fn is_public_at_level ( & self , id : LocalDefId , level : Level ) -> bool {
8584 self . effective_vis ( id)
8685 . map_or ( false , |effective_vis| effective_vis. is_public_at_level ( level) )
8786 }
8887
8988 /// See `Level::Reachable`.
90- pub fn is_reachable ( & self , id : Id ) -> bool {
89+ pub fn is_reachable ( & self , id : LocalDefId ) -> bool {
9190 self . is_public_at_level ( id, Level :: Reachable )
9291 }
9392
9493 /// See `Level::Reexported`.
95- pub fn is_exported ( & self , id : Id ) -> bool {
94+ pub fn is_exported ( & self , id : LocalDefId ) -> bool {
9695 self . is_public_at_level ( id, Level :: Reexported )
9796 }
9897
9998 /// See `Level::Direct`.
100- pub fn is_directly_public ( & self , id : Id ) -> bool {
99+ pub fn is_directly_public ( & self , id : LocalDefId ) -> bool {
101100 self . is_public_at_level ( id, Level :: Direct )
102101 }
103102
104- pub fn public_at_level ( & self , id : Id ) -> Option < Level > {
103+ pub fn public_at_level ( & self , id : LocalDefId ) -> Option < Level > {
105104 self . effective_vis ( id) . and_then ( |effective_vis| {
106105 for level in Level :: all_levels ( ) {
107106 if effective_vis. is_public_at_level ( level) {
@@ -112,24 +111,17 @@ impl<Id: Hash + Eq + Copy> EffectiveVisibilities<Id> {
112111 } )
113112 }
114113
115- pub fn effective_vis ( & self , id : Id ) -> Option < & EffectiveVisibility > {
114+ pub fn effective_vis ( & self , id : LocalDefId ) -> Option < & EffectiveVisibility > {
116115 self . map . get ( & id)
117116 }
118117
119- pub fn iter ( & self ) -> impl Iterator < Item = ( & Id , & EffectiveVisibility ) > {
118+ pub fn iter ( & self ) -> impl Iterator < Item = ( & LocalDefId , & EffectiveVisibility ) > {
120119 self . map . iter ( )
121120 }
122121
123- pub fn map_id < OutId : Hash + Eq + Copy > (
124- & self ,
125- f : impl Fn ( Id ) -> OutId ,
126- ) -> EffectiveVisibilities < OutId > {
127- EffectiveVisibilities { map : self . map . iter ( ) . map ( |( k, v) | ( f ( * k) , * v) ) . collect ( ) }
128- }
129-
130122 pub fn set_public_at_level (
131123 & mut self ,
132- id : Id ,
124+ id : LocalDefId ,
133125 default_vis : impl FnOnce ( ) -> Visibility ,
134126 level : Level ,
135127 ) {
@@ -144,23 +136,21 @@ impl<Id: Hash + Eq + Copy> EffectiveVisibilities<Id> {
144136 }
145137 self . map . insert ( id, effective_vis) ;
146138 }
147- }
148139
149- impl < Id : Hash + Eq + Copy + Into < DefId > > EffectiveVisibilities < Id > {
150140 // `parent_id` is not necessarily a parent in source code tree,
151141 // it is the node from which the maximum effective visibility is inherited.
152142 pub fn update (
153143 & mut self ,
154- id : Id ,
144+ id : LocalDefId ,
155145 nominal_vis : Visibility ,
156146 default_vis : impl FnOnce ( ) -> Visibility ,
157- parent_id : Id ,
147+ parent_id : LocalDefId ,
158148 level : Level ,
159149 tree : impl DefIdTree ,
160150 ) -> bool {
161151 let mut changed = false ;
162152 let mut current_effective_vis = self . effective_vis ( id) . copied ( ) . unwrap_or_else ( || {
163- if id. into ( ) . is_crate_root ( ) {
153+ if id. is_top_level_module ( ) {
164154 EffectiveVisibility :: from_vis ( Visibility :: Public )
165155 } else {
166156 EffectiveVisibility :: from_vis ( default_vis ( ) )
@@ -204,12 +194,6 @@ impl<Id: Hash + Eq + Copy + Into<DefId>> EffectiveVisibilities<Id> {
204194 }
205195}
206196
207- impl < Id > Default for EffectiveVisibilities < Id > {
208- fn default ( ) -> Self {
209- EffectiveVisibilities { map : Default :: default ( ) }
210- }
211- }
212-
213197impl < ' a > HashStable < StableHashingContext < ' a > > for EffectiveVisibilities {
214198 fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
215199 let EffectiveVisibilities { ref map } = * self ;
0 commit comments