@@ -213,14 +213,21 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
213
213
self . map . get ( & id)
214
214
}
215
215
216
- // `parent_id` is not necessarily a parent in source code tree,
217
- // it is the node from which the maximum effective visibility is inherited.
216
+ // FIXME: Share code with `fn update`.
217
+ pub fn effective_vis_or_private (
218
+ & mut self ,
219
+ id : Id ,
220
+ lazy_private_vis : impl FnOnce ( ) -> Visibility ,
221
+ ) -> & EffectiveVisibility {
222
+ self . map . entry ( id) . or_insert_with ( || EffectiveVisibility :: from_vis ( lazy_private_vis ( ) ) )
223
+ }
224
+
218
225
pub fn update < T : IntoDefIdTree > (
219
226
& mut self ,
220
227
id : Id ,
221
228
nominal_vis : Visibility ,
222
229
lazy_private_vis : impl FnOnce ( T ) -> ( Visibility , T ) ,
223
- inherited_eff_vis : Option < EffectiveVisibility > ,
230
+ inherited_effective_vis : EffectiveVisibility ,
224
231
level : Level ,
225
232
mut into_tree : T ,
226
233
) -> bool {
@@ -235,39 +242,36 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
235
242
} ;
236
243
let tree = into_tree. tree ( ) ;
237
244
238
- if let Some ( inherited_effective_vis) = inherited_eff_vis {
239
- let mut inherited_effective_vis_at_prev_level =
240
- * inherited_effective_vis. at_level ( level) ;
241
- let mut calculated_effective_vis = inherited_effective_vis_at_prev_level;
242
- for l in Level :: all_levels ( ) {
243
- if level >= l {
244
- let inherited_effective_vis_at_level = * inherited_effective_vis. at_level ( l) ;
245
- let current_effective_vis_at_level = current_effective_vis. at_level_mut ( l) ;
246
- // effective visibility for id shouldn't be recalculated if
247
- // inherited from parent_id effective visibility isn't changed at next level
248
- if !( inherited_effective_vis_at_prev_level == inherited_effective_vis_at_level
249
- && level != l)
250
- {
251
- calculated_effective_vis =
252
- if nominal_vis. is_at_least ( inherited_effective_vis_at_level, tree) {
253
- inherited_effective_vis_at_level
254
- } else {
255
- nominal_vis
256
- } ;
257
- }
258
- // effective visibility can't be decreased at next update call for the
259
- // same id
260
- if * current_effective_vis_at_level != calculated_effective_vis
261
- && calculated_effective_vis
262
- . is_at_least ( * current_effective_vis_at_level, tree)
263
- {
264
- changed = true ;
265
- * current_effective_vis_at_level = calculated_effective_vis;
266
- }
267
- inherited_effective_vis_at_prev_level = inherited_effective_vis_at_level;
245
+ let mut inherited_effective_vis_at_prev_level = * inherited_effective_vis. at_level ( level) ;
246
+ let mut calculated_effective_vis = inherited_effective_vis_at_prev_level;
247
+ for l in Level :: all_levels ( ) {
248
+ if level >= l {
249
+ let inherited_effective_vis_at_level = * inherited_effective_vis. at_level ( l) ;
250
+ let current_effective_vis_at_level = current_effective_vis. at_level_mut ( l) ;
251
+ // effective visibility for id shouldn't be recalculated if
252
+ // inherited from parent_id effective visibility isn't changed at next level
253
+ if !( inherited_effective_vis_at_prev_level == inherited_effective_vis_at_level
254
+ && level != l)
255
+ {
256
+ calculated_effective_vis =
257
+ if nominal_vis. is_at_least ( inherited_effective_vis_at_level, tree) {
258
+ inherited_effective_vis_at_level
259
+ } else {
260
+ nominal_vis
261
+ } ;
262
+ }
263
+ // effective visibility can't be decreased at next update call for the
264
+ // same id
265
+ if * current_effective_vis_at_level != calculated_effective_vis
266
+ && calculated_effective_vis. is_at_least ( * current_effective_vis_at_level, tree)
267
+ {
268
+ changed = true ;
269
+ * current_effective_vis_at_level = calculated_effective_vis;
268
270
}
271
+ inherited_effective_vis_at_prev_level = inherited_effective_vis_at_level;
269
272
}
270
273
}
274
+
271
275
self . map . insert ( id, current_effective_vis) ;
272
276
changed
273
277
}
0 commit comments