mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
effvis: Stop considering crate root its own parent
It helped to reuse `update_def` for the crate root, but it created confusion and caused some mistakes when I implemented #109500
This commit is contained in:
parent
ede21e8932
commit
b3bfeaf765
@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||
use std::hash::Hash;
|
||||
|
||||
/// Represents the levels of effective visibility an item can have.
|
||||
@ -107,6 +107,10 @@ impl EffectiveVisibilities {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update_root(&mut self) {
|
||||
self.map.insert(CRATE_DEF_ID, EffectiveVisibility::from_vis(Visibility::Public));
|
||||
}
|
||||
|
||||
// FIXME: Share code with `fn update`.
|
||||
pub fn update_eff_vis(
|
||||
&mut self,
|
||||
|
@ -61,7 +61,7 @@ impl Resolver<'_, '_> {
|
||||
// For mod items `nearest_normal_mod` returns its argument, but we actually need its parent.
|
||||
let normal_mod_id = self.nearest_normal_mod(def_id);
|
||||
if normal_mod_id == def_id {
|
||||
self.tcx.opt_local_parent(def_id).map_or(Visibility::Public, Visibility::Restricted)
|
||||
Visibility::Restricted(self.tcx.local_parent(def_id))
|
||||
} else {
|
||||
Visibility::Restricted(normal_mod_id)
|
||||
}
|
||||
@ -80,12 +80,11 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
||||
r,
|
||||
def_effective_visibilities: Default::default(),
|
||||
import_effective_visibilities: Default::default(),
|
||||
current_private_vis: Visibility::Public,
|
||||
current_private_vis: Visibility::Restricted(CRATE_DEF_ID),
|
||||
changed: false,
|
||||
};
|
||||
|
||||
visitor.update(CRATE_DEF_ID, CRATE_DEF_ID);
|
||||
visitor.current_private_vis = Visibility::Restricted(CRATE_DEF_ID);
|
||||
visitor.def_effective_visibilities.update_root();
|
||||
visitor.set_bindings_effective_visibilities(CRATE_DEF_ID);
|
||||
|
||||
while visitor.changed {
|
||||
@ -202,7 +201,7 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
|
||||
);
|
||||
}
|
||||
|
||||
fn update(&mut self, def_id: LocalDefId, parent_id: LocalDefId) {
|
||||
fn update_field(&mut self, def_id: LocalDefId, parent_id: LocalDefId) {
|
||||
self.update_def(def_id, self.r.visibilities[&def_id], ParentId::Def(parent_id));
|
||||
}
|
||||
}
|
||||
@ -234,14 +233,14 @@ impl<'r, 'ast, 'tcx> Visitor<'ast> for EffectiveVisibilitiesVisitor<'ast, 'r, 't
|
||||
for variant in variants {
|
||||
let variant_def_id = self.r.local_def_id(variant.id);
|
||||
for field in variant.data.fields() {
|
||||
self.update(self.r.local_def_id(field.id), variant_def_id);
|
||||
self.update_field(self.r.local_def_id(field.id), variant_def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ast::ItemKind::Struct(ref def, _) | ast::ItemKind::Union(ref def, _) => {
|
||||
for field in def.fields() {
|
||||
self.update(self.r.local_def_id(field.id), def_id);
|
||||
self.update_field(self.r.local_def_id(field.id), def_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user