Rename Module field anonymous_children to module_children, expand it to include both named an anonymous modules, and fix #31644
This commit is contained in:
parent
4af85643b1
commit
81d5d02c37
4 changed files with 20 additions and 69 deletions
|
@ -306,6 +306,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
|||
let def = Def::Mod(self.ast_map.local_def_id(item.id));
|
||||
let module = self.new_module(parent_link, Some(def), false, is_public);
|
||||
self.define(parent, name, TypeNS, (module, sp));
|
||||
parent.module_children.borrow_mut().insert(item.id, module);
|
||||
module
|
||||
}
|
||||
|
||||
|
@ -474,7 +475,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
|||
|
||||
let parent_link = BlockParentLink(parent, block_id);
|
||||
let new_module = self.new_module(parent_link, None, false, false);
|
||||
parent.anonymous_children.borrow_mut().insert(block_id, new_module);
|
||||
parent.module_children.borrow_mut().insert(block_id, new_module);
|
||||
new_module
|
||||
} else {
|
||||
parent
|
||||
|
|
|
@ -801,9 +801,9 @@ pub struct ModuleS<'a> {
|
|||
resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>,
|
||||
imports: RefCell<Vec<ImportDirective>>,
|
||||
|
||||
// The anonymous children of this node. Anonymous children are pseudo-
|
||||
// modules that are implicitly created around items contained within
|
||||
// blocks.
|
||||
// The module children of this node, including normal modules and anonymous modules.
|
||||
// Anonymous children are pseudo-modules that are implicitly created around items
|
||||
// contained within blocks.
|
||||
//
|
||||
// For example, if we have this:
|
||||
//
|
||||
|
@ -815,7 +815,7 @@ pub struct ModuleS<'a> {
|
|||
//
|
||||
// There will be an anonymous module created around `g` with the ID of the
|
||||
// entry block for `f`.
|
||||
anonymous_children: RefCell<NodeMap<Module<'a>>>,
|
||||
module_children: RefCell<NodeMap<Module<'a>>>,
|
||||
|
||||
shadowed_traits: RefCell<Vec<&'a NameBinding<'a>>>,
|
||||
|
||||
|
@ -848,7 +848,7 @@ impl<'a> ModuleS<'a> {
|
|||
is_extern_crate: false,
|
||||
resolutions: RefCell::new(HashMap::new()),
|
||||
imports: RefCell::new(Vec::new()),
|
||||
anonymous_children: RefCell::new(NodeMap()),
|
||||
module_children: RefCell::new(NodeMap()),
|
||||
shadowed_traits: RefCell::new(Vec::new()),
|
||||
glob_count: Cell::new(0),
|
||||
pub_count: Cell::new(0),
|
||||
|
@ -906,14 +906,6 @@ impl<'a> ModuleS<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn for_each_local_child<F: FnMut(Name, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
|
||||
self.for_each_child(|name, ns, name_binding| {
|
||||
if !name_binding.is_import() && !name_binding.is_extern_crate() {
|
||||
f(name, ns, name_binding)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn def_id(&self) -> Option<DefId> {
|
||||
self.def.as_ref().map(Def::def_id)
|
||||
}
|
||||
|
@ -1640,20 +1632,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// Descend into children and anonymous children.
|
||||
build_reduced_graph::populate_module_if_necessary(self, module_);
|
||||
|
||||
module_.for_each_local_child(|_, _, child_node| {
|
||||
match child_node.module() {
|
||||
None => {
|
||||
// Continue.
|
||||
}
|
||||
Some(child_module) => {
|
||||
self.report_unresolved_imports(child_module);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (_, module_) in module_.anonymous_children.borrow().iter() {
|
||||
for (_, module_) in module_.module_children.borrow().iter() {
|
||||
self.report_unresolved_imports(module_);
|
||||
}
|
||||
}
|
||||
|
@ -1676,32 +1655,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// generate a fake "implementation scope" containing all the
|
||||
// implementations thus found, for compatibility with old resolve pass.
|
||||
|
||||
fn with_scope<F>(&mut self, name: Option<Name>, f: F)
|
||||
fn with_scope<F>(&mut self, id: NodeId, f: F)
|
||||
where F: FnOnce(&mut Resolver)
|
||||
{
|
||||
let orig_module = self.current_module;
|
||||
|
||||
// Move down in the graph.
|
||||
match name {
|
||||
None => {
|
||||
// Nothing to do.
|
||||
}
|
||||
Some(name) => {
|
||||
build_reduced_graph::populate_module_if_necessary(self, &orig_module);
|
||||
|
||||
if let Success(name_binding) = orig_module.resolve_name(name, TypeNS, false) {
|
||||
match name_binding.module() {
|
||||
None => {
|
||||
debug!("!!! (with scope) didn't find module for `{}` in `{}`",
|
||||
name,
|
||||
module_to_string(orig_module));
|
||||
}
|
||||
Some(module) => {
|
||||
self.current_module = module;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(module) = orig_module.module_children.borrow().get(&id) {
|
||||
self.current_module = module;
|
||||
}
|
||||
|
||||
f(self);
|
||||
|
@ -1825,7 +1786,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
|
||||
ItemMod(_) | ItemForeignMod(_) => {
|
||||
self.with_scope(Some(name), |this| {
|
||||
self.with_scope(item.id, |this| {
|
||||
intravisit::walk_item(this, item);
|
||||
});
|
||||
}
|
||||
|
@ -2261,7 +2222,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// Move down in the graph, if there's an anonymous module rooted here.
|
||||
let orig_module = self.current_module;
|
||||
let anonymous_module =
|
||||
orig_module.anonymous_children.borrow().get(&block.id).map(|module| *module);
|
||||
orig_module.module_children.borrow().get(&block.id).map(|module| *module);
|
||||
|
||||
if let Some(anonymous_module) = anonymous_module {
|
||||
debug!("(resolving block) found anonymous module, moving down");
|
||||
|
|
|
@ -243,19 +243,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
errors.extend(self.resolve_imports_for_module(module_));
|
||||
self.resolver.current_module = orig_module;
|
||||
|
||||
build_reduced_graph::populate_module_if_necessary(self.resolver, module_);
|
||||
module_.for_each_local_child(|_, _, child_node| {
|
||||
match child_node.module() {
|
||||
None => {
|
||||
// Nothing to do.
|
||||
}
|
||||
Some(child_module) => {
|
||||
errors.extend(self.resolve_imports_for_module_subtree(child_module));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (_, child_module) in module_.anonymous_children.borrow().iter() {
|
||||
for (_, child_module) in module_.module_children.borrow().iter() {
|
||||
errors.extend(self.resolve_imports_for_module_subtree(child_module));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
mod Foo {
|
||||
pub static X: isize = 42;
|
||||
}
|
||||
|
||||
enum Foo { //~ ERROR duplicate definition of type or module `Foo`
|
||||
enum Foo {
|
||||
X
|
||||
}
|
||||
|
||||
mod Foo { //~ ERROR duplicate definition of type or module `Foo`
|
||||
pub static X: isize = 42;
|
||||
fn f() { f() } // Check that this does not result in a resolution error
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue