@@ -6,8 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
6
6
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
7
7
use rustc_macros:: HashStable ;
8
8
use 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 ;
11
10
12
11
/// Represents the levels of effective visibility an item can have.
13
12
///
@@ -75,33 +74,33 @@ impl EffectiveVisibility {
75
74
}
76
75
77
76
/// 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 > ,
81
80
}
82
81
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 {
85
84
self . effective_vis ( id)
86
85
. map_or ( false , |effective_vis| effective_vis. is_public_at_level ( level) )
87
86
}
88
87
89
88
/// See `Level::Reachable`.
90
- pub fn is_reachable ( & self , id : Id ) -> bool {
89
+ pub fn is_reachable ( & self , id : LocalDefId ) -> bool {
91
90
self . is_public_at_level ( id, Level :: Reachable )
92
91
}
93
92
94
93
/// See `Level::Reexported`.
95
- pub fn is_exported ( & self , id : Id ) -> bool {
94
+ pub fn is_exported ( & self , id : LocalDefId ) -> bool {
96
95
self . is_public_at_level ( id, Level :: Reexported )
97
96
}
98
97
99
98
/// See `Level::Direct`.
100
- pub fn is_directly_public ( & self , id : Id ) -> bool {
99
+ pub fn is_directly_public ( & self , id : LocalDefId ) -> bool {
101
100
self . is_public_at_level ( id, Level :: Direct )
102
101
}
103
102
104
- pub fn public_at_level ( & self , id : Id ) -> Option < Level > {
103
+ pub fn public_at_level ( & self , id : LocalDefId ) -> Option < Level > {
105
104
self . effective_vis ( id) . and_then ( |effective_vis| {
106
105
for level in Level :: all_levels ( ) {
107
106
if effective_vis. is_public_at_level ( level) {
@@ -112,24 +111,17 @@ impl<Id: Hash + Eq + Copy> EffectiveVisibilities<Id> {
112
111
} )
113
112
}
114
113
115
- pub fn effective_vis ( & self , id : Id ) -> Option < & EffectiveVisibility > {
114
+ pub fn effective_vis ( & self , id : LocalDefId ) -> Option < & EffectiveVisibility > {
116
115
self . map . get ( & id)
117
116
}
118
117
119
- pub fn iter ( & self ) -> impl Iterator < Item = ( & Id , & EffectiveVisibility ) > {
118
+ pub fn iter ( & self ) -> impl Iterator < Item = ( & LocalDefId , & EffectiveVisibility ) > {
120
119
self . map . iter ( )
121
120
}
122
121
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
-
130
122
pub fn set_public_at_level (
131
123
& mut self ,
132
- id : Id ,
124
+ id : LocalDefId ,
133
125
default_vis : impl FnOnce ( ) -> Visibility ,
134
126
level : Level ,
135
127
) {
@@ -144,23 +136,21 @@ impl<Id: Hash + Eq + Copy> EffectiveVisibilities<Id> {
144
136
}
145
137
self . map . insert ( id, effective_vis) ;
146
138
}
147
- }
148
139
149
- impl < Id : Hash + Eq + Copy + Into < DefId > > EffectiveVisibilities < Id > {
150
140
// `parent_id` is not necessarily a parent in source code tree,
151
141
// it is the node from which the maximum effective visibility is inherited.
152
142
pub fn update (
153
143
& mut self ,
154
- id : Id ,
144
+ id : LocalDefId ,
155
145
nominal_vis : Visibility ,
156
146
default_vis : impl FnOnce ( ) -> Visibility ,
157
- parent_id : Id ,
147
+ parent_id : LocalDefId ,
158
148
level : Level ,
159
149
tree : impl DefIdTree ,
160
150
) -> bool {
161
151
let mut changed = false ;
162
152
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 ( ) {
164
154
EffectiveVisibility :: from_vis ( Visibility :: Public )
165
155
} else {
166
156
EffectiveVisibility :: from_vis ( default_vis ( ) )
@@ -204,12 +194,6 @@ impl<Id: Hash + Eq + Copy + Into<DefId>> EffectiveVisibilities<Id> {
204
194
}
205
195
}
206
196
207
- impl < Id > Default for EffectiveVisibilities < Id > {
208
- fn default ( ) -> Self {
209
- EffectiveVisibilities { map : Default :: default ( ) }
210
- }
211
- }
212
-
213
197
impl < ' a > HashStable < StableHashingContext < ' a > > for EffectiveVisibilities {
214
198
fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
215
199
let EffectiveVisibilities { ref map } = * self ;
0 commit comments