提交 77f0f4a6 编写于 作者: J Jeffrey Seyfried

Avoid repeating parent

上级 ff014a3a
......@@ -43,7 +43,6 @@
use rustc_front::hir::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
use rustc_front::intravisit::{self, Visitor};
use std::mem::replace;
use std::ops::{Deref, DerefMut};
struct GraphBuilder<'a, 'b: 'a, 'tcx: 'b> {
......@@ -122,7 +121,8 @@ fn is_item(statement: &hir::Stmt) -> bool {
}
/// Constructs the reduced graph for one item.
fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> Module<'b> {
fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<'b>) {
let parent = *parent_ref;
let name = item.name;
let sp = item.span;
let is_public = item.vis == hir::Public;
......@@ -242,7 +242,6 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
is_prelude);
}
}
parent
}
ItemExternCrate(_) => {
......@@ -260,7 +259,6 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
self.build_reduced_graph_for_external_crate(module);
}
parent
}
ItemMod(..) => {
......@@ -269,34 +267,30 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
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
*parent_ref = module;
}
ItemForeignMod(..) => parent,
ItemForeignMod(..) => {}
// These items live in the value namespace.
ItemStatic(_, m, _) => {
let mutbl = m == hir::MutMutable;
let def = Def::Static(self.ast_map.local_def_id(item.id), mutbl);
self.define(parent, name, ValueNS, (def, sp, modifiers));
parent
}
ItemConst(_, _) => {
let def = Def::Const(self.ast_map.local_def_id(item.id));
self.define(parent, name, ValueNS, (def, sp, modifiers));
parent
}
ItemFn(_, _, _, _, _, _) => {
let def = Def::Fn(self.ast_map.local_def_id(item.id));
self.define(parent, name, ValueNS, (def, sp, modifiers));
parent
}
// These items live in the type namespace.
ItemTy(..) => {
let def = Def::TyAlias(self.ast_map.local_def_id(item.id));
self.define(parent, name, TypeNS, (def, sp, modifiers));
parent
}
ItemEnum(ref enum_definition, _) => {
......@@ -315,7 +309,6 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
self.build_reduced_graph_for_variant(variant, item_def_id,
module, variant_modifiers);
}
parent
}
// These items live in both the type and value namespaces.
......@@ -338,12 +331,9 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
.collect();
let item_def_id = self.ast_map.local_def_id(item.id);
self.structs.insert(item_def_id, field_names);
parent
}
ItemDefaultImpl(_, _) |
ItemImpl(..) => parent,
ItemDefaultImpl(_, _) | ItemImpl(..) => {}
ItemTrait(_, _, _, ref items) => {
let def_id = self.ast_map.local_def_id(item.id);
......@@ -368,8 +358,6 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
self.trait_item_map.insert((item.name, def_id), item_def_id);
}
parent
}
}
}
......@@ -420,7 +408,7 @@ fn build_reduced_graph_for_foreign_item(&mut self,
self.define(parent, name, ValueNS, (def, foreign_item.span, modifiers));
}
fn build_reduced_graph_for_block(&mut self, block: &Block, parent: Module<'b>) -> Module<'b> {
fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &mut Module<'b>) {
if self.block_needs_anonymous_module(block) {
let block_id = block.id;
......@@ -431,9 +419,7 @@ fn build_reduced_graph_for_block(&mut self, block: &Block, parent: Module<'b>) -
let parent_link = BlockParentLink(parent, block_id);
let new_module = self.new_module(parent_link, None, false, false);
parent.module_children.borrow_mut().insert(block_id, new_module);
new_module
} else {
parent
*parent = new_module;
}
}
......@@ -610,8 +596,8 @@ fn visit_nested_item(&mut self, item: hir::ItemId) {
}
fn visit_item(&mut self, item: &Item) {
let p = self.builder.build_reduced_graph_for_item(item, &self.parent);
let old_parent = replace(&mut self.parent, p);
let old_parent = self.parent;
self.builder.build_reduced_graph_for_item(item, &mut self.parent);
intravisit::walk_item(self, item);
self.parent = old_parent;
}
......@@ -621,8 +607,8 @@ fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
}
fn visit_block(&mut self, block: &Block) {
let np = self.builder.build_reduced_graph_for_block(block, &self.parent);
let old_parent = replace(&mut self.parent, np);
let old_parent = self.parent;
self.builder.build_reduced_graph_for_block(block, &mut self.parent);
intravisit::walk_block(self, block);
self.parent = old_parent;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册