Refactor away field vis of ModuleS
This commit is contained in:
parent
19304837c8
commit
c46164b626
2 changed files with 27 additions and 45 deletions
|
|
@ -46,9 +46,9 @@ trait ToNameBinding<'a> {
|
|||
fn to_name_binding(self) -> NameBinding<'a>;
|
||||
}
|
||||
|
||||
impl<'a> ToNameBinding<'a> for (Module<'a>, Span) {
|
||||
impl<'a> ToNameBinding<'a> for (Module<'a>, Span, ty::Visibility) {
|
||||
fn to_name_binding(self) -> NameBinding<'a> {
|
||||
NameBinding::create_from_module(self.0, Some(self.1))
|
||||
NameBinding { kind: NameBindingKind::Module(self.0), span: Some(self.1), vis: self.2 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -247,8 +247,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
};
|
||||
let parent_link = ModuleParentLink(parent, name);
|
||||
let def = Def::Mod(def_id);
|
||||
let module = self.new_extern_crate_module(parent_link, def, vis, item.id);
|
||||
self.define(parent, name, TypeNS, (module, sp));
|
||||
let module = self.new_extern_crate_module(parent_link, def, item.id);
|
||||
self.define(parent, name, TypeNS, (module, sp, vis));
|
||||
|
||||
self.build_reduced_graph_for_external_crate(module);
|
||||
}
|
||||
|
|
@ -257,8 +257,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
ItemMod(..) => {
|
||||
let parent_link = ModuleParentLink(parent, name);
|
||||
let def = Def::Mod(self.ast_map.local_def_id(item.id));
|
||||
let module = self.new_module(parent_link, Some(def), false, vis);
|
||||
self.define(parent, name, TypeNS, (module, sp));
|
||||
let module = self.new_module(parent_link, Some(def), false);
|
||||
self.define(parent, name, TypeNS, (module, sp, vis));
|
||||
self.module_map.insert(item.id, module);
|
||||
*parent_ref = module;
|
||||
}
|
||||
|
|
@ -289,12 +289,12 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
ItemEnum(ref enum_definition, _) => {
|
||||
let parent_link = ModuleParentLink(parent, name);
|
||||
let def = Def::Enum(self.ast_map.local_def_id(item.id));
|
||||
let module = self.new_module(parent_link, Some(def), false, vis);
|
||||
self.define(parent, name, TypeNS, (module, sp));
|
||||
let module = self.new_module(parent_link, Some(def), false);
|
||||
self.define(parent, name, TypeNS, (module, sp, vis));
|
||||
|
||||
for variant in &(*enum_definition).variants {
|
||||
let item_def_id = self.ast_map.local_def_id(item.id);
|
||||
self.build_reduced_graph_for_variant(variant, item_def_id, module);
|
||||
self.build_reduced_graph_for_variant(variant, item_def_id, module, vis);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -328,8 +328,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
// Add all the items within to a new module.
|
||||
let parent_link = ModuleParentLink(parent, name);
|
||||
let def = Def::Trait(def_id);
|
||||
let module_parent = self.new_module(parent_link, Some(def), false, vis);
|
||||
self.define(parent, name, TypeNS, (module_parent, sp));
|
||||
let module_parent = self.new_module(parent_link, Some(def), false);
|
||||
self.define(parent, name, TypeNS, (module_parent, sp, vis));
|
||||
|
||||
// Add the names of all the items to the trait info.
|
||||
for item in items {
|
||||
|
|
@ -353,7 +353,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
fn build_reduced_graph_for_variant(&mut self,
|
||||
variant: &Variant,
|
||||
item_id: DefId,
|
||||
parent: Module<'b>) {
|
||||
parent: Module<'b>,
|
||||
vis: ty::Visibility) {
|
||||
let name = variant.node.name;
|
||||
if variant.node.data.is_struct() {
|
||||
// Not adding fields for variants as they are not accessed with a self receiver
|
||||
|
|
@ -364,8 +365,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
// Variants are always treated as importable to allow them to be glob used.
|
||||
// All variants are defined in both type and value namespaces as future-proofing.
|
||||
let def = Def::Variant(item_id, self.ast_map.local_def_id(variant.node.data.id()));
|
||||
self.define(parent, name, ValueNS, (def, variant.span, parent.vis));
|
||||
self.define(parent, name, TypeNS, (def, variant.span, parent.vis));
|
||||
self.define(parent, name, ValueNS, (def, variant.span, vis));
|
||||
self.define(parent, name, TypeNS, (def, variant.span, vis));
|
||||
}
|
||||
|
||||
/// Constructs the reduced graph for one foreign item.
|
||||
|
|
@ -396,7 +397,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
block_id);
|
||||
|
||||
let parent_link = BlockParentLink(parent, block_id);
|
||||
let new_module = self.new_module(parent_link, None, false, parent.vis);
|
||||
let new_module = self.new_module(parent_link, None, false);
|
||||
self.module_map.insert(block_id, new_module);
|
||||
*parent = new_module;
|
||||
}
|
||||
|
|
@ -425,8 +426,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
debug!("(building reduced graph for external crate) building module {} {:?}",
|
||||
name, vis);
|
||||
let parent_link = ModuleParentLink(parent, name);
|
||||
let module = self.new_module(parent_link, Some(def), true, vis);
|
||||
self.try_define(parent, name, TypeNS, (module, DUMMY_SP));
|
||||
let module = self.new_module(parent_link, Some(def), true);
|
||||
self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
|
||||
}
|
||||
Def::Variant(_, variant_id) => {
|
||||
debug!("(building reduced graph for external crate) building variant {}", name);
|
||||
|
|
@ -467,8 +468,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
|
|||
}
|
||||
|
||||
let parent_link = ModuleParentLink(parent, name);
|
||||
let module = self.new_module(parent_link, Some(def), true, vis);
|
||||
self.try_define(parent, name, TypeNS, (module, DUMMY_SP));
|
||||
let module = self.new_module(parent_link, Some(def), true);
|
||||
self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
|
||||
}
|
||||
Def::TyAlias(..) | Def::AssociatedTy(..) => {
|
||||
debug!("(building reduced graph for external crate) building type {}", name);
|
||||
|
|
|
|||
|
|
@ -818,7 +818,6 @@ enum ParentLink<'a> {
|
|||
pub struct ModuleS<'a> {
|
||||
parent_link: ParentLink<'a>,
|
||||
def: Option<Def>,
|
||||
vis: ty::Visibility,
|
||||
|
||||
// If the module is an extern crate, `def` is root of the external crate and `extern_crate_id`
|
||||
// is the NodeId of the local `extern crate` item (otherwise, `extern_crate_id` is None).
|
||||
|
|
@ -849,12 +848,10 @@ impl<'a> ModuleS<'a> {
|
|||
fn new(parent_link: ParentLink<'a>,
|
||||
def: Option<Def>,
|
||||
external: bool,
|
||||
vis: ty::Visibility,
|
||||
arenas: &'a ResolverArenas<'a>) -> Self {
|
||||
ModuleS {
|
||||
parent_link: parent_link,
|
||||
def: def,
|
||||
vis: vis,
|
||||
extern_crate_id: None,
|
||||
resolutions: RefCell::new(HashMap::new()),
|
||||
unresolved_imports: RefCell::new(Vec::new()),
|
||||
|
|
@ -895,7 +892,7 @@ impl<'a> ModuleS<'a> {
|
|||
|
||||
impl<'a> fmt::Debug for ModuleS<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}, {:?}", self.def, self.vis)
|
||||
write!(f, "{:?}", self.def)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -923,14 +920,6 @@ enum NameBindingKind<'a> {
|
|||
struct PrivacyError<'a>(Span, Name, &'a NameBinding<'a>);
|
||||
|
||||
impl<'a> NameBinding<'a> {
|
||||
fn create_from_module(module: Module<'a>, span: Option<Span>) -> Self {
|
||||
NameBinding {
|
||||
kind: NameBindingKind::Module(module),
|
||||
span: span,
|
||||
vis: module.vis,
|
||||
}
|
||||
}
|
||||
|
||||
fn module(&self) -> Option<Module<'a>> {
|
||||
match self.kind {
|
||||
NameBindingKind::Module(module) => Some(module),
|
||||
|
|
@ -1148,9 +1137,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
arenas: &'a ResolverArenas<'a>)
|
||||
-> Resolver<'a, 'tcx> {
|
||||
let root_def_id = ast_map.local_def_id(CRATE_NODE_ID);
|
||||
let vis = ty::Visibility::Public;
|
||||
let graph_root =
|
||||
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, vis, arenas);
|
||||
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
|
||||
let graph_root = arenas.alloc_module(graph_root);
|
||||
|
||||
Resolver {
|
||||
|
|
@ -1208,21 +1196,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn new_module(&self,
|
||||
parent_link: ParentLink<'a>,
|
||||
def: Option<Def>,
|
||||
external: bool,
|
||||
vis: ty::Visibility) -> Module<'a> {
|
||||
self.arenas.alloc_module(ModuleS::new(parent_link, def, external, vis, self.arenas))
|
||||
fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
|
||||
-> Module<'a> {
|
||||
self.arenas.alloc_module(ModuleS::new(parent_link, def, external, self.arenas))
|
||||
}
|
||||
|
||||
fn new_extern_crate_module(&self,
|
||||
parent_link: ParentLink<'a>,
|
||||
def: Def,
|
||||
vis: ty::Visibility,
|
||||
local_node_id: NodeId)
|
||||
fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def, local_node_id: NodeId)
|
||||
-> Module<'a> {
|
||||
let mut module = ModuleS::new(parent_link, Some(def), false, vis, self.arenas);
|
||||
let mut module = ModuleS::new(parent_link, Some(def), false, self.arenas);
|
||||
module.extern_crate_id = Some(local_node_id);
|
||||
self.arenas.modules.alloc(module)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue