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 }
}
}
};
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);
}
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;
}
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);
}
}
// 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 {
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
// 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.
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;
}
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);
}
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);
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).
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()),
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)
}
}
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),
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 {
}
}
- 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)
}