Skip to content

Commit a344f14

Browse files
committed
Refactor out BuildReducedGraphVisitor::visit_trait_item.
1 parent 9a0e88a commit a344f14

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use syntax::parse::token;
3333

3434
use syntax::ast::{Block, Crate};
3535
use syntax::ast::{ForeignItem, ForeignItemKind, Item, ItemKind};
36-
use syntax::ast::{Mutability, StmtKind, TraitItemKind};
36+
use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind};
3737
use syntax::ast::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
3838
use syntax::parse::token::keywords;
3939
use syntax::visit::{self, Visitor};
@@ -289,32 +289,14 @@ impl<'b> Resolver<'b> {
289289

290290
ItemKind::DefaultImpl(..) | ItemKind::Impl(..) => {}
291291

292-
ItemKind::Trait(.., ref items) => {
292+
ItemKind::Trait(..) => {
293293
let def_id = self.definitions.local_def_id(item.id);
294294

295295
// Add all the items within to a new module.
296296
let kind = ModuleKind::Def(Def::Trait(def_id), name);
297-
let module_parent = self.new_module(parent, kind, parent.normal_ancestor_id);
298-
self.define(parent, name, TypeNS, (module_parent, sp, vis));
299-
300-
// Add the names of all the items to the trait info.
301-
for item in items {
302-
let item_def_id = self.definitions.local_def_id(item.id);
303-
let mut is_static_method = false;
304-
let (def, ns) = match item.node {
305-
TraitItemKind::Const(..) => (Def::AssociatedConst(item_def_id), ValueNS),
306-
TraitItemKind::Method(ref sig, _) => {
307-
is_static_method = !sig.decl.has_self();
308-
(Def::Method(item_def_id), ValueNS)
309-
}
310-
TraitItemKind::Type(..) => (Def::AssociatedTy(item_def_id), TypeNS),
311-
TraitItemKind::Macro(_) => panic!("unexpanded macro in resolve!"),
312-
};
313-
314-
self.define(module_parent, item.ident.name, ns, (def, item.span, vis));
315-
316-
self.trait_item_map.insert((item.ident.name, def_id), is_static_method);
317-
}
297+
let module = self.new_module(parent, kind, parent.normal_ancestor_id);
298+
self.define(parent, name, TypeNS, (module, sp, vis));
299+
self.current_module = module;
318300
}
319301
ItemKind::Mac(_) => panic!("unexpanded macro in resolve!"),
320302
}
@@ -514,4 +496,31 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> {
514496
fn visit_block(&mut self, block: &Block) {
515497
self.resolver.build_reduced_graph_for_block(block);
516498
}
499+
500+
fn visit_trait_item(&mut self, item: &TraitItem) {
501+
let parent = self.resolver.current_module;
502+
let def_id = parent.def_id().unwrap();
503+
504+
// Add the item to the trait info.
505+
let item_def_id = self.resolver.definitions.local_def_id(item.id);
506+
let mut is_static_method = false;
507+
let (def, ns) = match item.node {
508+
TraitItemKind::Const(..) => (Def::AssociatedConst(item_def_id), ValueNS),
509+
TraitItemKind::Method(ref sig, _) => {
510+
is_static_method = !sig.decl.has_self();
511+
(Def::Method(item_def_id), ValueNS)
512+
}
513+
TraitItemKind::Type(..) => (Def::AssociatedTy(item_def_id), TypeNS),
514+
TraitItemKind::Macro(_) => panic!("unexpanded macro in resolve!"),
515+
};
516+
517+
self.resolver.trait_item_map.insert((item.ident.name, def_id), is_static_method);
518+
519+
let vis = ty::Visibility::Public;
520+
self.resolver.define(parent, item.ident.name, ns, (def, item.span, vis));
521+
522+
self.resolver.current_module = parent.parent.unwrap(); // nearest normal ancestor
523+
visit::walk_trait_item(self, item);
524+
self.resolver.current_module = parent;
525+
}
517526
}

0 commit comments

Comments
 (0)