1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Reduced graph building
13 //! Here we build the "reduced graph": the graph of the module tree without
14 //! any imports resolved.
17 use resolve_imports::ImportDirective;
18 use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
19 use resolve_imports::{ImportResolution, ImportResolutionPerNamespace};
21 use Namespace::{TypeNS, ValueNS};
23 use {names_to_string, module_to_string};
24 use ParentLink::{ModuleParentLink, BlockParentLink};
26 use resolve_imports::Shadowable;
27 use {resolve_error, resolve_struct_error, ResolutionError};
29 use self::DuplicateCheckingMode::*;
31 use rustc::middle::cstore::{CrateStore, ChildItem, DlDef, DlField, DlImpl};
32 use rustc::middle::def::*;
33 use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};
34 use rustc::middle::ty::VariantKind;
36 use syntax::ast::{Name, NodeId};
37 use syntax::attr::AttrMetaMethods;
38 use syntax::parse::token::special_idents;
39 use syntax::codemap::{Span, DUMMY_SP};
42 use rustc_front::hir::{Block, DeclItem};
43 use rustc_front::hir::{ForeignItem, ForeignItemFn, ForeignItemStatic};
44 use rustc_front::hir::{Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn};
45 use rustc_front::hir::{ItemForeignMod, ItemImpl, ItemMod, ItemStatic, ItemDefaultImpl};
46 use rustc_front::hir::{ItemStruct, ItemTrait, ItemTy, ItemUse};
47 use rustc_front::hir::{NamedField, PathListIdent, PathListMod};
48 use rustc_front::hir::StmtDecl;
49 use rustc_front::hir::UnnamedField;
50 use rustc_front::hir::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
51 use rustc_front::hir::Visibility;
52 use rustc_front::intravisit::{self, Visitor};
54 use std::mem::replace;
55 use std::ops::{Deref, DerefMut};
57 // Specifies how duplicates should be handled when adding a child item if
58 // another item exists with the same name in some namespace.
59 #[derive(Copy, Clone, PartialEq)]
60 enum DuplicateCheckingMode {
62 ForbidDuplicateValues,
63 ForbidDuplicateTypesAndValues,
67 struct GraphBuilder<'a, 'b: 'a, 'tcx: 'b> {
68 resolver: &'a mut Resolver<'b, 'tcx>,
71 impl<'a, 'b:'a, 'tcx:'b> Deref for GraphBuilder<'a, 'b, 'tcx> {
72 type Target = Resolver<'b, 'tcx>;
74 fn deref(&self) -> &Resolver<'b, 'tcx> {
79 impl<'a, 'b:'a, 'tcx:'b> DerefMut for GraphBuilder<'a, 'b, 'tcx> {
80 fn deref_mut(&mut self) -> &mut Resolver<'b, 'tcx> {
85 impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
86 /// Constructs the reduced graph for the entire crate.
87 fn build_reduced_graph(self, krate: &hir::Crate) {
88 let mut visitor = BuildReducedGraphVisitor {
89 parent: self.graph_root,
92 intravisit::walk_crate(&mut visitor, krate);
95 /// Adds a new child item to the module definition of the parent node,
96 /// or if there is already a child, does duplicate checking on the child.
97 /// Returns the child's corresponding name bindings.
101 duplicate_checking_mode: DuplicateCheckingMode,
102 // For printing errors
104 -> NameBindings<'b> {
105 self.check_for_conflicts_between_external_crates_and_items(parent, name, sp);
107 // Add or reuse the child.
108 let child = parent.children.borrow().get(&name).cloned();
111 let child = NameBindings::new();
112 parent.children.borrow_mut().insert(name, child.clone());
116 // Enforce the duplicate checking mode:
118 // * If we're requesting duplicate type checking, check that
119 // the name isn't defined in the type namespace.
121 // * If we're requesting duplicate value checking, check that
122 // the name isn't defined in the value namespace.
124 // * If we're requesting duplicate type and value checking,
125 // check that the name isn't defined in either namespace.
127 // * If no duplicate checking was requested at all, do
130 let ns = match duplicate_checking_mode {
131 ForbidDuplicateTypes if child.type_ns.defined() => TypeNS,
132 ForbidDuplicateValues if child.value_ns.defined() => ValueNS,
133 ForbidDuplicateTypesAndValues if child.type_ns.defined() => TypeNS,
134 ForbidDuplicateTypesAndValues if child.value_ns.defined() => ValueNS,
138 // Record an error here by looking up the namespace that had the duplicate
139 let ns_str = match ns { TypeNS => "type or module", ValueNS => "value" };
140 let mut err = resolve_struct_error(self,
142 ResolutionError::DuplicateDefinition(ns_str,
145 if let Some(sp) = child[ns].span() {
146 let note = format!("first definition of {} `{}` here", ns_str, name);
147 err.span_note(sp, ¬e);
155 fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
156 // Check each statement.
157 for statement in &block.stmts {
158 match statement.node {
159 StmtDecl(ref declaration, _) => {
160 match declaration.node {
175 // If we found no items, we don't need to create
176 // an anonymous module.
181 /// Constructs the reduced graph for one item.
182 fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> Module<'b> {
183 let name = item.name;
185 let is_public = item.vis == hir::Public;
186 let modifiers = if is_public {
189 DefModifiers::empty()
190 } | DefModifiers::IMPORTABLE;
193 ItemUse(ref view_path) => {
194 // Extract and intern the module part of the path. For
195 // globs and lists, the path is found directly in the AST;
196 // for simple paths we have to munge the path a little.
197 let module_path = match view_path.node {
198 ViewPathSimple(_, ref full_path) => {
204 .map(|seg| seg.identifier.name)
208 ViewPathGlob(ref module_ident_path) |
209 ViewPathList(ref module_ident_path, _) => {
210 module_ident_path.segments
212 .map(|seg| seg.identifier.name)
217 // Build up the import directives.
218 let shadowable = item.attrs.iter().any(|attr| {
219 attr.name() == special_idents::prelude_import.name.as_str()
221 let shadowable = if shadowable {
227 match view_path.node {
228 ViewPathSimple(binding, ref full_path) => {
229 let source_name = full_path.segments.last().unwrap().identifier.name;
230 if source_name.as_str() == "mod" || source_name.as_str() == "self" {
233 ResolutionError::SelfImportsOnlyAllowedWithin);
236 let subclass = SingleImport(binding, source_name);
237 self.build_import_directive(parent,
245 ViewPathList(_, ref source_items) => {
246 // Make sure there's at most one `mod` import in the list.
247 let mod_spans = source_items.iter()
250 PathListMod { .. } => Some(item.span),
254 .collect::<Vec<Span>>();
255 if mod_spans.len() > 1 {
256 let mut e = resolve_struct_error(self,
258 ResolutionError::SelfImportCanOnlyAppearOnceInTheList);
259 for other_span in mod_spans.iter().skip(1) {
260 e.span_note(*other_span, "another `self` import appears here");
265 for source_item in source_items {
266 let (module_path, name, rename) = match source_item.node {
267 PathListIdent { name, rename, .. } =>
268 (module_path.clone(), name, rename.unwrap_or(name)),
269 PathListMod { rename, .. } => {
270 let name = match module_path.last() {
277 SelfImportOnlyInImportListWithNonEmptyPrefix
282 let module_path = module_path.split_last().unwrap().1;
283 let rename = rename.unwrap_or(name);
284 (module_path.to_vec(), name, rename)
287 self.build_import_directive(parent,
289 SingleImport(rename, name),
291 source_item.node.id(),
297 self.build_import_directive(parent,
309 ItemExternCrate(_) => {
310 // n.b. we don't need to look at the path option here, because cstore already
312 if let Some(crate_id) = self.session.cstore.extern_mod_stmt_cnum(item.id) {
315 index: CRATE_DEF_INDEX,
317 self.external_exports.insert(def_id);
318 let parent_link = ModuleParentLink(parent, name);
319 let def = Def::Mod(def_id);
320 let external_module = self.new_module(parent_link, Some(def), false, true);
322 debug!("(build reduced graph for item) found extern `{}`",
323 module_to_string(&*external_module));
324 self.check_for_conflicts_for_external_crate(parent, name, sp);
325 parent.external_module_children
327 .insert(name, external_module);
328 self.build_reduced_graph_for_external_crate(&external_module);
334 let name_bindings = self.add_child(name, parent, ForbidDuplicateTypes, sp);
336 let parent_link = ModuleParentLink(parent, name);
337 let def = Def::Mod(self.ast_map.local_def_id(item.id));
338 let module = self.new_module(parent_link, Some(def), false, is_public);
339 name_bindings.define_module(module.clone(), sp);
343 ItemForeignMod(..) => parent,
345 // These items live in the value namespace.
346 ItemStatic(_, m, _) => {
347 let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp);
348 let mutbl = m == hir::MutMutable;
350 name_bindings.define_value(Def::Static(self.ast_map.local_def_id(item.id), mutbl),
356 self.add_child(name, parent, ForbidDuplicateValues, sp)
357 .define_value(Def::Const(self.ast_map.local_def_id(item.id)), sp, modifiers);
360 ItemFn(_, _, _, _, _, _) => {
361 let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp);
363 let def = Def::Fn(self.ast_map.local_def_id(item.id));
364 name_bindings.define_value(def, sp, modifiers);
368 // These items live in the type namespace.
370 let name_bindings = self.add_child(name,
372 ForbidDuplicateTypes,
375 let parent_link = ModuleParentLink(parent, name);
376 let def = Def::TyAlias(self.ast_map.local_def_id(item.id));
377 let module = self.new_module(parent_link, Some(def), false, is_public);
378 name_bindings.define_module(module, sp);
382 ItemEnum(ref enum_definition, _) => {
383 let name_bindings = self.add_child(name,
385 ForbidDuplicateTypes,
388 let parent_link = ModuleParentLink(parent, name);
389 let def = Def::Enum(self.ast_map.local_def_id(item.id));
390 let module = self.new_module(parent_link, Some(def), false, is_public);
391 name_bindings.define_module(module.clone(), sp);
393 let variant_modifiers = if is_public {
394 DefModifiers::empty()
396 DefModifiers::PRIVATE_VARIANT
398 for variant in &(*enum_definition).variants {
399 let item_def_id = self.ast_map.local_def_id(item.id);
400 self.build_reduced_graph_for_variant(variant, item_def_id,
401 &module, variant_modifiers);
406 // These items live in both the type and value namespaces.
407 ItemStruct(ref struct_def, _) => {
408 // Adding to both Type and Value namespaces or just Type?
409 let (forbid, ctor_id) = if struct_def.is_struct() {
410 (ForbidDuplicateTypes, None)
412 (ForbidDuplicateTypesAndValues, Some(struct_def.id()))
415 let name_bindings = self.add_child(name, parent, forbid, sp);
417 // Define a name in the type namespace.
418 name_bindings.define_type(Def::Struct(self.ast_map.local_def_id(item.id)),
422 // If this is a newtype or unit-like struct, define a name
423 // in the value namespace as well
424 if let Some(cid) = ctor_id {
425 name_bindings.define_value(Def::Struct(self.ast_map.local_def_id(cid)),
430 // Record the def ID and fields of this struct.
431 let named_fields = struct_def.fields()
435 NamedField(name, _) => Some(name),
436 UnnamedField(_) => None,
440 let item_def_id = self.ast_map.local_def_id(item.id);
441 self.structs.insert(item_def_id, named_fields);
446 ItemDefaultImpl(_, _) |
447 ItemImpl(..) => parent,
449 ItemTrait(_, _, _, ref items) => {
450 let name_bindings = self.add_child(name,
452 ForbidDuplicateTypes,
455 let def_id = self.ast_map.local_def_id(item.id);
457 // Add all the items within to a new module.
458 let parent_link = ModuleParentLink(parent, name);
459 let def = Def::Trait(def_id);
460 let module_parent = self.new_module(parent_link, Some(def), false, is_public);
461 name_bindings.define_module(module_parent.clone(), sp);
463 // Add the names of all the items to the trait info.
464 for trait_item in items {
465 let name_bindings = self.add_child(trait_item.name,
467 ForbidDuplicateTypesAndValues,
470 match trait_item.node {
471 hir::ConstTraitItem(..) => {
472 let def = Def::AssociatedConst(self.ast_map.
473 local_def_id(trait_item.id));
474 // NB: not DefModifiers::IMPORTABLE
475 name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC);
477 hir::MethodTraitItem(..) => {
478 let def = Def::Method(self.ast_map.local_def_id(trait_item.id));
479 // NB: not DefModifiers::IMPORTABLE
480 name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC);
482 hir::TypeTraitItem(..) => {
483 let def = Def::AssociatedTy(self.ast_map.local_def_id(item.id),
484 self.ast_map.local_def_id(trait_item.id));
485 // NB: not DefModifiers::IMPORTABLE
486 name_bindings.define_type(def, trait_item.span, DefModifiers::PUBLIC);
490 let trait_item_def_id = self.ast_map.local_def_id(trait_item.id);
491 self.trait_item_map.insert((trait_item.name, def_id), trait_item_def_id);
499 // Constructs the reduced graph for one variant. Variants exist in the
500 // type and value namespaces.
501 fn build_reduced_graph_for_variant(&mut self,
505 variant_modifiers: DefModifiers) {
506 let name = variant.node.name;
507 if variant.node.data.is_struct() {
508 // Not adding fields for variants as they are not accessed with a self receiver
509 let variant_def_id = self.ast_map.local_def_id(variant.node.data.id());
510 self.structs.insert(variant_def_id, Vec::new());
513 let child = self.add_child(name, parent, ForbidDuplicateTypesAndValues, variant.span);
514 // variants are always treated as importable to allow them to be glob
516 child.define_value(Def::Variant(item_id, self.ast_map.local_def_id(variant.node.data.id())),
518 DefModifiers::PUBLIC | DefModifiers::IMPORTABLE | variant_modifiers);
519 child.define_type(Def::Variant(item_id, self.ast_map.local_def_id(variant.node.data.id())),
521 DefModifiers::PUBLIC | DefModifiers::IMPORTABLE | variant_modifiers);
524 /// Constructs the reduced graph for one foreign item.
525 fn build_reduced_graph_for_foreign_item(&mut self,
526 foreign_item: &ForeignItem,
527 parent: Module<'b>) {
528 let name = foreign_item.name;
529 let is_public = foreign_item.vis == hir::Public;
530 let modifiers = if is_public {
533 DefModifiers::empty()
534 } | DefModifiers::IMPORTABLE;
535 let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, foreign_item.span);
537 let def = match foreign_item.node {
538 ForeignItemFn(..) => {
539 Def::Fn(self.ast_map.local_def_id(foreign_item.id))
541 ForeignItemStatic(_, m) => {
542 Def::Static(self.ast_map.local_def_id(foreign_item.id), m)
545 name_bindings.define_value(def, foreign_item.span, modifiers);
548 fn build_reduced_graph_for_block(&mut self, block: &Block, parent: Module<'b>) -> Module<'b> {
549 if self.block_needs_anonymous_module(block) {
550 let block_id = block.id;
552 debug!("(building reduced graph for block) creating a new anonymous module for block \
556 let parent_link = BlockParentLink(parent, block_id);
557 let new_module = self.new_module(parent_link, None, false, false);
558 parent.anonymous_children.borrow_mut().insert(block_id, new_module);
565 fn handle_external_def(&mut self,
568 child_name_bindings: &NameBindings<'b>,
571 new_parent: Module<'b>) {
572 debug!("(building reduced graph for external crate) building external def {}, priv {:?}",
575 let is_public = vis == hir::Public;
576 let modifiers = if is_public {
579 DefModifiers::empty()
580 } | DefModifiers::IMPORTABLE;
581 let is_exported = is_public &&
582 match new_parent.def_id() {
584 Some(did) => self.external_exports.contains(&did),
587 self.external_exports.insert(def.def_id());
589 let is_struct_ctor = if let Def::Struct(def_id) = def {
590 self.session.cstore.tuple_struct_definition_if_ctor(def_id).is_some()
600 Def::TyAlias(..) if !is_struct_ctor => {
601 if let Some(module_def) = child_name_bindings.type_ns.module() {
602 debug!("(building reduced graph for external crate) already created module");
603 module_def.def.set(Some(def));
605 debug!("(building reduced graph for external crate) building module {} {}",
608 let parent_link = ModuleParentLink(new_parent, name);
609 let module = self.new_module(parent_link, Some(def), true, is_public);
610 child_name_bindings.define_module(module, DUMMY_SP);
617 Def::Mod(_) | Def::ForeignMod(_) => {}
618 Def::Variant(_, variant_id) => {
619 debug!("(building reduced graph for external crate) building variant {}",
621 // variants are always treated as importable to allow them to be
623 let modifiers = DefModifiers::PUBLIC | DefModifiers::IMPORTABLE;
624 if self.session.cstore.variant_kind(variant_id) == Some(VariantKind::Struct) {
625 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
626 // Not adding fields for variants as they are not accessed with a self receiver
627 self.structs.insert(variant_id, Vec::new());
629 child_name_bindings.define_value(def, DUMMY_SP, modifiers);
635 Def::AssociatedConst(..) |
637 debug!("(building reduced graph for external crate) building value (fn/static) {}",
639 // impl methods have already been defined with the correct importability
641 let mut modifiers = match *child_name_bindings.value_ns.borrow() {
642 Some(ref def) => (modifiers & !DefModifiers::IMPORTABLE) |
643 (def.modifiers & DefModifiers::IMPORTABLE),
646 if !new_parent.is_normal() {
647 modifiers = modifiers & !DefModifiers::IMPORTABLE;
649 child_name_bindings.define_value(def, DUMMY_SP, modifiers);
651 Def::Trait(def_id) => {
652 debug!("(building reduced graph for external crate) building type {}",
655 // If this is a trait, add all the trait item names to the trait
658 let trait_item_def_ids = self.session.cstore.trait_item_def_ids(def_id);
659 for trait_item_def in &trait_item_def_ids {
660 let trait_item_name =
661 self.session.cstore.item_name(trait_item_def.def_id());
663 debug!("(building reduced graph for external crate) ... adding trait item \
667 self.trait_item_map.insert((trait_item_name, def_id), trait_item_def.def_id());
670 self.external_exports.insert(trait_item_def.def_id());
674 // Define a module if necessary.
675 let parent_link = ModuleParentLink(new_parent, name);
676 let module = self.new_module(parent_link, Some(def), true, is_public);
677 child_name_bindings.define_module(module, DUMMY_SP);
679 Def::Enum(..) | Def::TyAlias(..) | Def::AssociatedTy(..) => {
680 debug!("(building reduced graph for external crate) building type {}",
683 let modifiers = match new_parent.is_normal() {
685 _ => modifiers & !DefModifiers::IMPORTABLE,
688 if let Def::Enum(..) = def {
689 child_name_bindings.type_ns.set_modifiers(modifiers);
690 } else if let Def::TyAlias(..) = def {
691 child_name_bindings.type_ns.set_modifiers(modifiers);
693 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
696 Def::Struct(..) if is_struct_ctor => {
699 Def::Struct(def_id) => {
700 debug!("(building reduced graph for external crate) building type and value for \
704 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
705 if let Some(ctor_def_id) = self.session.cstore.struct_ctor_def_id(def_id) {
706 child_name_bindings.define_value(Def::Struct(ctor_def_id), DUMMY_SP, modifiers);
709 // Record the def ID and fields of this struct.
710 let fields = self.session.cstore.struct_field_names(def_id);
711 self.structs.insert(def_id, fields);
720 panic!("didn't expect `{:?}`", def);
725 /// Builds the reduced graph for a single item in an external crate.
726 fn build_reduced_graph_for_external_crate_def(&mut self,
731 // Add the new child item, if necessary.
733 Def::ForeignMod(def_id) => {
734 // Foreign modules have no names. Recur and populate
736 for child in self.session.cstore.item_children(def_id) {
737 self.build_reduced_graph_for_external_crate_def(root, child)
741 let child_name_bindings = self.add_child(xcdef.name,
746 self.handle_external_def(def,
748 &child_name_bindings,
749 &xcdef.name.as_str(),
756 debug!("(building reduced graph for external crate) ignoring impl");
759 debug!("(building reduced graph for external crate) ignoring field");
764 /// Builds the reduced graph rooted at the given external module.
765 fn populate_external_module(&mut self, module: Module<'b>) {
766 debug!("(populating external module) attempting to populate {}",
767 module_to_string(module));
769 let def_id = match module.def_id() {
771 debug!("(populating external module) ... no def ID!");
774 Some(def_id) => def_id,
777 for child in self.session.cstore.item_children(def_id) {
778 debug!("(populating external module) ... found ident: {}",
780 self.build_reduced_graph_for_external_crate_def(module, child);
782 module.populated.set(true)
785 /// Ensures that the reduced graph rooted at the given external module
786 /// is built, building it if it is not.
787 fn populate_module_if_necessary(&mut self, module: Module<'b>) {
788 if !module.populated.get() {
789 self.populate_external_module(module)
791 assert!(module.populated.get())
794 /// Builds the reduced graph rooted at the 'use' directive for an external
796 fn build_reduced_graph_for_external_crate(&mut self, root: Module<'b>) {
797 let root_cnum = root.def_id().unwrap().krate;
798 for child in self.session.cstore.crate_top_level_items(root_cnum) {
799 self.build_reduced_graph_for_external_crate_def(root, child);
803 /// Creates and adds an import directive to the given module.
804 fn build_import_directive(&mut self,
806 module_path: Vec<Name>,
807 subclass: ImportDirectiveSubclass,
811 shadowable: Shadowable) {
814 .push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
815 self.unresolved_imports += 1;
818 module_.inc_pub_count();
821 // Bump the reference count on the name. Or, if this is a glob, set
822 // the appropriate flag.
825 SingleImport(target, _) => {
826 debug!("(building import directive) building import directive: {}::{}",
827 names_to_string(&module_.imports.borrow().last().unwrap().module_path),
830 let mut import_resolutions = module_.import_resolutions.borrow_mut();
831 match import_resolutions.get_mut(&target) {
832 Some(resolution_per_ns) => {
833 debug!("(building import directive) bumping reference");
834 resolution_per_ns.outstanding_references += 1;
836 // the source of this name is different now
838 ImportResolution { id: id, is_public: is_public, target: None };
839 resolution_per_ns[TypeNS] = resolution.clone();
840 resolution_per_ns[ValueNS] = resolution;
845 debug!("(building import directive) creating new");
846 let mut import_resolution_per_ns = ImportResolutionPerNamespace::new(id, is_public);
847 import_resolution_per_ns.outstanding_references = 1;
848 import_resolutions.insert(target, import_resolution_per_ns);
851 // Set the glob flag. This tells us that we don't know the
852 // module's exports ahead of time.
854 module_.inc_glob_count();
856 module_.inc_pub_glob_count();
863 struct BuildReducedGraphVisitor<'a, 'b: 'a, 'tcx: 'b> {
864 builder: GraphBuilder<'a, 'b, 'tcx>,
868 impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
869 fn visit_nested_item(&mut self, item: hir::ItemId) {
870 self.visit_item(self.builder.resolver.ast_map.expect_item(item.id))
873 fn visit_item(&mut self, item: &Item) {
874 let p = self.builder.build_reduced_graph_for_item(item, &self.parent);
875 let old_parent = replace(&mut self.parent, p);
876 intravisit::walk_item(self, item);
877 self.parent = old_parent;
880 fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
881 self.builder.build_reduced_graph_for_foreign_item(foreign_item, &self.parent);
884 fn visit_block(&mut self, block: &Block) {
885 let np = self.builder.build_reduced_graph_for_block(block, &self.parent);
886 let old_parent = replace(&mut self.parent, np);
887 intravisit::walk_block(self, block);
888 self.parent = old_parent;
892 pub fn build_reduced_graph(resolver: &mut Resolver, krate: &hir::Crate) {
893 GraphBuilder { resolver: resolver }.build_reduced_graph(krate);
896 pub fn populate_module_if_necessary<'a, 'tcx>(resolver: &mut Resolver<'a, 'tcx>,
897 module: Module<'a>) {
898 GraphBuilder { resolver: resolver }.populate_module_if_necessary(module);