use DefModifiers;
use resolve_imports::ImportDirective;
use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
-use resolve_imports::ImportResolution;
use Module;
use Namespace::{self, TypeNS, ValueNS};
-use {NameBinding, DefOrModule};
+use {NameBinding, NameBindingKind};
use {names_to_string, module_to_string};
use ParentLink::{ModuleParentLink, BlockParentLink};
use Resolver;
impl<'a> ToNameBinding<'a> for (Def, Span, DefModifiers) {
fn to_name_binding(self) -> NameBinding<'a> {
- let def = DefOrModule::Def(self.0);
- NameBinding { modifiers: self.2, def_or_module: def, span: Some(self.1) }
+ let kind = NameBindingKind::Def(self.0);
+ NameBinding { modifiers: self.2, kind: kind, span: Some(self.1) }
}
}
fn try_define<T>(&self, parent: Module<'b>, name: Name, ns: Namespace, def: T)
where T: ToNameBinding<'b>
{
- parent.try_define_child(name, ns, def.to_name_binding());
+ parent.try_define_child(name, ns, self.new_name_binding(def.to_name_binding()));
}
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
/// otherwise, reports an error.
fn define<T: ToNameBinding<'b>>(&self, parent: Module<'b>, name: Name, ns: Namespace, def: T) {
- let binding = def.to_name_binding();
- let old_binding = match parent.try_define_child(name, ns, binding.clone()) {
+ let binding = self.new_name_binding(def.to_name_binding());
+ let old_binding = match parent.try_define_child(name, ns, binding) {
Some(old_binding) => old_binding,
None => return,
};
}
fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
- // Check each statement.
- for statement in &block.stmts {
- match statement.node {
- StmtDecl(ref declaration, _) => {
- match declaration.node {
- DeclItem(_) => {
- return true;
- }
- _ => {
- // Keep searching.
- }
- }
- }
- _ => {
- // Keep searching.
+ fn is_item(statement: &hir::Stmt) -> bool {
+ if let StmtDecl(ref declaration, _) = statement.node {
+ if let DeclItem(_) = declaration.node {
+ return true;
}
}
+ false
}
- // If we found no items, we don't need to create
- // an anonymous module.
-
- return false;
+ // If any statements are items, we need to create an anonymous module
+ block.stmts.iter().any(is_item)
}
/// Constructs the reduced graph for one item.
let external_module = self.new_extern_crate_module(parent_link, def);
self.define(parent, name, TypeNS, (external_module, sp));
- self.build_reduced_graph_for_external_crate(&external_module);
+ self.build_reduced_graph_for_external_crate(external_module);
}
parent
}
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, variant_modifiers);
+ module, variant_modifiers);
}
parent
}
};
let modifiers = DefModifiers::PUBLIC; // NB: not DefModifiers::IMPORTABLE
- self.define(&module_parent, item.name, ns, (def, item.span, modifiers));
+ self.define(module_parent, item.name, ns, (def, item.span, modifiers));
self.trait_item_map.insert((item.name, def_id), item_def_id);
}
debug!("(building import directive) building import directive: {}::{}",
names_to_string(&module_.imports.borrow().last().unwrap().module_path),
target);
-
- let mut import_resolutions = module_.import_resolutions.borrow_mut();
- for &ns in [TypeNS, ValueNS].iter() {
- let mut resolution = import_resolutions.entry((target, ns)).or_insert(
- ImportResolution::new(id, is_public)
- );
-
- resolution.outstanding_references += 1;
- // the source of this name is different now
- resolution.id = id;
- resolution.is_public = is_public;
- }
+ module_.increment_outstanding_references_for(target, ValueNS);
+ module_.increment_outstanding_references_for(target, TypeNS);
}
GlobImport => {
// Set the glob flag. This tells us that we don't know the