提交 0bed9aea 编写于 作者: J Jeffrey Seyfried

Make populate_module_if_necessary a method of resolver

上级 77f0f4a6
......@@ -532,16 +532,6 @@ fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>, xcd
}
}
/// Ensures that the reduced graph rooted at the given external module
/// is built, building it if it is not.
fn populate_module_if_necessary(&mut self, module: Module<'b>) {
if module.populated.get() { return }
for child in self.session.cstore.item_children(module.def_id().unwrap()) {
self.build_reduced_graph_for_external_crate_def(module, child);
}
module.populated.set(true)
}
/// Builds the reduced graph rooted at the 'use' directive for an external
/// crate.
fn build_reduced_graph_for_external_crate(&mut self, root: Module<'b>) {
......@@ -585,6 +575,19 @@ fn build_import_directive(&mut self,
}
}
impl<'a, 'tcx> Resolver<'a, 'tcx> {
/// Ensures that the reduced graph rooted at the given external module
/// is built, building it if it is not.
pub fn populate_module_if_necessary(&mut self, module: Module<'a>) {
if module.populated.get() { return }
let mut builder = GraphBuilder { resolver: self };
for child in self.session.cstore.item_children(module.def_id().unwrap()) {
builder.build_reduced_graph_for_external_crate_def(module, child);
}
module.populated.set(true)
}
}
struct BuildReducedGraphVisitor<'a, 'b: 'a, 'tcx: 'b> {
builder: GraphBuilder<'a, 'b, 'tcx>,
parent: Module<'b>,
......@@ -617,8 +620,3 @@ fn visit_block(&mut self, block: &Block) {
pub fn build_reduced_graph(resolver: &mut Resolver, krate: &hir::Crate) {
GraphBuilder { resolver: resolver }.build_reduced_graph(krate);
}
pub fn populate_module_if_necessary<'a, 'tcx>(resolver: &mut Resolver<'a, 'tcx>,
module: Module<'a>) {
GraphBuilder { resolver: resolver }.populate_module_if_necessary(module);
}
......@@ -1542,7 +1542,7 @@ fn resolve_name_in_module(&mut self,
-> ResolveResult<&'a NameBinding<'a>> {
debug!("(resolving name in module) resolving `{}` in `{}`", name, module_to_string(module));
build_reduced_graph::populate_module_if_necessary(self, module);
self.populate_module_if_necessary(module);
match use_lexical_scope {
true => module.resolve_name_in_lexical_scope(name, namespace)
.map(Success).unwrap_or(Failed(None)),
......@@ -3363,7 +3363,7 @@ fn lookup_candidates<FilterFn>(&mut self,
while let Some((in_module,
path_segments,
in_module_is_extern)) = worklist.pop() {
build_reduced_graph::populate_module_if_necessary(self, &in_module);
self.populate_module_if_necessary(in_module);
in_module.for_each_child(|name, ns, name_binding| {
......
......@@ -21,8 +21,6 @@
use {names_to_string, module_to_string};
use {resolve_error, ResolutionError};
use build_reduced_graph;
use rustc::lint;
use rustc::middle::def::*;
......@@ -610,7 +608,7 @@ fn resolve_glob_import(&mut self,
let msg = "Cannot glob-import a module into itself.".into();
return Failed(Some((directive.span, msg)));
}
build_reduced_graph::populate_module_if_necessary(self.resolver, target_module);
self.resolver.populate_module_if_necessary(target_module);
if directive.is_prelude {
*module_.prelude.borrow_mut() = Some(target_module);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册