提交 d107d225 编写于 作者: J Jeffrey Seyfried

Refactor `module.add_import_directive()` -> `resolver.add_import_directive()`.

上级 aef6971c
......@@ -130,7 +130,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
let subclass = ImportDirectiveSubclass::single(binding.name, source_name);
let span = view_path.span;
parent.add_import_directive(module_path, subclass, span, item.id, vis);
self.add_import_directive(module_path, subclass, span, item.id, vis);
self.unresolved_imports += 1;
}
ViewPathList(_, ref source_items) => {
......@@ -176,14 +176,14 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
};
let subclass = ImportDirectiveSubclass::single(rename, name);
let (span, id) = (source_item.span, source_item.node.id());
parent.add_import_directive(module_path, subclass, span, id, vis);
self.add_import_directive(module_path, subclass, span, id, vis);
self.unresolved_imports += 1;
}
}
ViewPathGlob(_) => {
let subclass = GlobImport { is_prelude: is_prelude };
let span = view_path.span;
parent.add_import_directive(module_path, subclass, span, item.id, vis);
self.add_import_directive(module_path, subclass, span, item.id, vis);
self.unresolved_imports += 1;
}
}
......
......@@ -212,8 +212,11 @@ pub fn resolve_name(&self, name: Name, ns: Namespace, allow_private_imports: boo
Failed(None)
}
}
pub fn add_import_directive(&self,
impl<'a> Resolver<'a> {
// Add an import directive to the current module.
pub fn add_import_directive(&mut self,
module_path: Vec<Name>,
subclass: ImportDirectiveSubclass,
span: Span,
......@@ -228,23 +231,21 @@ pub fn add_import_directive(&self,
vis: vis,
});
self.unresolved_imports.borrow_mut().push(directive);
self.current_module.unresolved_imports.borrow_mut().push(directive);
match directive.subclass {
SingleImport { target, .. } => {
for &ns in &[ValueNS, TypeNS] {
self.resolution(target, ns).borrow_mut().single_imports
.add_directive(directive);
let mut resolution = self.current_module.resolution(target, ns).borrow_mut();
resolution.single_imports.add_directive(directive);
}
}
// We don't add prelude imports to the globs since they only affect lexical scopes,
// which are not relevant to import resolution.
GlobImport { is_prelude: true } => {}
GlobImport { .. } => self.globs.borrow_mut().push(directive),
GlobImport { .. } => self.current_module.globs.borrow_mut().push(directive),
}
}
}
impl<'a> Resolver<'a> {
// Given a binding and an import directive that resolves to it,
// return the corresponding binding defined by the import directive.
fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册