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;
22 use Namespace::{TypeNS, ValueNS};
24 use {names_to_string, module_to_string};
25 use ParentLink::{self, ModuleParentLink, BlockParentLink};
27 use resolve_imports::Shadowable;
29 use {resolve_error, ResolutionError};
31 use self::DuplicateCheckingMode::*;
32 use self::NamespaceError::*;
34 use rustc::metadata::csearch;
35 use rustc::metadata::decoder::{DefLike, DlDef, DlField, DlImpl};
36 use rustc::middle::def::*;
37 use rustc::middle::def_id::DefId;
39 use syntax::ast::{Name, NodeId};
40 use syntax::attr::AttrMetaMethods;
41 use syntax::parse::token::special_idents;
42 use syntax::codemap::{Span, DUMMY_SP};
45 use rustc_front::hir::{Block, Crate, DeclItem};
46 use rustc_front::hir::{ForeignItem, ForeignItemFn, ForeignItemStatic};
47 use rustc_front::hir::{Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn};
48 use rustc_front::hir::{ItemForeignMod, ItemImpl, ItemMod, ItemStatic, ItemDefaultImpl};
49 use rustc_front::hir::{ItemStruct, ItemTrait, ItemTy, ItemUse};
50 use rustc_front::hir::{NamedField, PathListIdent, PathListMod, Public};
51 use rustc_front::hir::StmtDecl;
52 use rustc_front::hir::StructVariantKind;
53 use rustc_front::hir::TupleVariantKind;
54 use rustc_front::hir::UnnamedField;
55 use rustc_front::hir::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
56 use rustc_front::hir::Visibility;
57 use rustc_front::visit::{self, Visitor};
59 use std::mem::replace;
60 use std::ops::{Deref, DerefMut};
63 // Specifies how duplicates should be handled when adding a child item if
64 // another item exists with the same name in some namespace.
65 #[derive(Copy, Clone, PartialEq)]
66 enum DuplicateCheckingMode {
67 ForbidDuplicateModules,
68 ForbidDuplicateTypesAndModules,
69 ForbidDuplicateValues,
70 ForbidDuplicateTypesAndValues,
74 #[derive(Copy, Clone, PartialEq)]
82 fn namespace_error_to_string(ns: NamespaceError) -> &'static str {
85 ModuleError | TypeError => "type or module",
86 ValueError => "value",
90 struct GraphBuilder<'a, 'b:'a, 'tcx:'b> {
91 resolver: &'a mut Resolver<'b, 'tcx>
94 impl<'a, 'b:'a, 'tcx:'b> Deref for GraphBuilder<'a, 'b, 'tcx> {
95 type Target = Resolver<'b, 'tcx>;
97 fn deref(&self) -> &Resolver<'b, 'tcx> {
102 impl<'a, 'b:'a, 'tcx:'b> DerefMut for GraphBuilder<'a, 'b, 'tcx> {
103 fn deref_mut(&mut self) -> &mut Resolver<'b, 'tcx> {
108 impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
109 /// Constructs the reduced graph for the entire crate.
110 fn build_reduced_graph(self, krate: &hir::Crate) {
111 let parent = self.graph_root.get_module();
112 let mut visitor = BuildReducedGraphVisitor {
116 visit::walk_crate(&mut visitor, krate);
119 /// Adds a new child item to the module definition of the parent node and
120 /// returns its corresponding name bindings as well as the current parent.
121 /// Or, if we're inside a block, creates (or reuses) an anonymous module
122 /// corresponding to the innermost block ID and returns the name bindings
123 /// as well as the newly-created parent.
127 /// Panics if this node does not have a module definition and we are not inside
132 duplicate_checking_mode: DuplicateCheckingMode,
133 // For printing errors
135 -> Rc<NameBindings> {
136 // If this is the immediate descendant of a module, then we add the
137 // child name directly. Otherwise, we create or reuse an anonymous
138 // module and add the child to that.
140 self.check_for_conflicts_between_external_crates_and_items(&**parent,
144 // Add or reuse the child.
145 let child = parent.children.borrow().get(&name).cloned();
148 let child = Rc::new(NameBindings::new());
149 parent.children.borrow_mut().insert(name, child.clone());
153 // Enforce the duplicate checking mode:
155 // * If we're requesting duplicate module checking, check that
156 // there isn't a module in the module with the same name.
158 // * If we're requesting duplicate type checking, check that
159 // there isn't a type in the module with the same name.
161 // * If we're requesting duplicate value checking, check that
162 // there isn't a value in the module with the same name.
164 // * If we're requesting duplicate type checking and duplicate
165 // value checking, check that there isn't a duplicate type
166 // and a duplicate value with the same name.
168 // * If no duplicate checking was requested at all, do
171 let mut duplicate_type = NoError;
172 let ns = match duplicate_checking_mode {
173 ForbidDuplicateModules => {
174 if child.get_module_if_available().is_some() {
175 duplicate_type = ModuleError;
179 ForbidDuplicateTypesAndModules => {
180 if child.defined_in_namespace(TypeNS) {
181 duplicate_type = TypeError;
185 ForbidDuplicateValues => {
186 if child.defined_in_namespace(ValueNS) {
187 duplicate_type = ValueError;
191 ForbidDuplicateTypesAndValues => {
193 match child.def_for_namespace(TypeNS) {
194 Some(DefMod(_)) | None => {}
197 duplicate_type = TypeError;
200 if child.defined_in_namespace(ValueNS) {
201 duplicate_type = ValueError;
206 OverwriteDuplicates => None
208 if duplicate_type != NoError {
209 // Return an error here by looking up the namespace that
210 // had the duplicate.
211 let ns = ns.unwrap();
215 ResolutionError::DuplicateDefinition(
216 namespace_error_to_string(duplicate_type),
220 let r = child.span_for_namespace(ns);
221 if let Some(sp) = r {
222 self.session.span_note(sp,
223 &format!("first definition of {} `{}` here",
224 namespace_error_to_string(duplicate_type),
234 fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
235 // Check each statement.
236 for statement in &block.stmts {
237 match statement.node {
238 StmtDecl(ref declaration, _) => {
239 match declaration.node {
254 // If we found no items, we don't need to create
255 // an anonymous module.
260 fn get_parent_link(&mut self, parent: &Rc<Module>, name: Name) -> ParentLink {
261 ModuleParentLink(Rc::downgrade(parent), name)
264 /// Constructs the reduced graph for one item.
265 fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) -> Rc<Module> {
266 let name = item.name;
268 let is_public = item.vis == hir::Public;
269 let modifiers = if is_public {
272 DefModifiers::empty()
273 } | DefModifiers::IMPORTABLE;
276 ItemUse(ref view_path) => {
277 // Extract and intern the module part of the path. For
278 // globs and lists, the path is found directly in the AST;
279 // for simple paths we have to munge the path a little.
280 let module_path = match view_path.node {
281 ViewPathSimple(_, ref full_path) => {
283 .split_last().unwrap().1
284 .iter().map(|seg| seg.identifier.name)
288 ViewPathGlob(ref module_ident_path) |
289 ViewPathList(ref module_ident_path, _) => {
290 module_ident_path.segments
291 .iter().map(|seg| seg.identifier.name).collect()
295 // Build up the import directives.
296 let shadowable = item.attrs.iter().any(|attr| {
297 attr.name() == special_idents::prelude_import.name.as_str()
299 let shadowable = if shadowable {
305 match view_path.node {
306 ViewPathSimple(binding, ref full_path) => {
308 full_path.segments.last().unwrap().identifier.name;
309 if source_name.as_str() == "mod" || source_name.as_str() == "self" {
312 ResolutionError::SelfImportsOnlyAllowedWithin);
315 let subclass = SingleImport(binding, source_name);
316 self.build_import_directive(&**parent,
324 ViewPathList(_, ref source_items) => {
325 // Make sure there's at most one `mod` import in the list.
326 let mod_spans = source_items.iter().filter_map(|item| match item.node {
327 PathListMod { .. } => Some(item.span),
329 }).collect::<Vec<Span>>();
330 if mod_spans.len() > 1 {
334 ResolutionError::SelfImportCanOnlyAppearOnceInTheList
336 for other_span in mod_spans.iter().skip(1) {
337 self.session.span_note(*other_span,
338 "another `self` import appears here");
342 for source_item in source_items {
343 let (module_path, name, rename) = match source_item.node {
344 PathListIdent { name, rename, .. } =>
345 (module_path.clone(), name, rename.unwrap_or(name)),
346 PathListMod { rename, .. } => {
347 let name = match module_path.last() {
354 SelfImportOnlyInImportListWithNonEmptyPrefix
359 let module_path = module_path.split_last().unwrap().1;
360 let rename = rename.unwrap_or(name);
361 (module_path.to_vec(), name, rename)
364 self.build_import_directive(
367 SingleImport(rename, name),
369 source_item.node.id(),
375 self.build_import_directive(&**parent,
387 ItemExternCrate(_) => {
388 // n.b. we don't need to look at the path option here, because cstore already did
389 if let Some(crate_id) = self.session.cstore.find_extern_mod_stmt_cnum(item.id) {
390 let def_id = DefId { krate: crate_id, node: 0 };
391 self.external_exports.insert(def_id);
392 let parent_link = ModuleParentLink(Rc::downgrade(parent), name);
393 let external_module = Rc::new(Module::new(parent_link,
398 debug!("(build reduced graph for item) found extern `{}`",
399 module_to_string(&*external_module));
400 self.check_for_conflicts_between_external_crates(&**parent, name, sp);
401 parent.external_module_children.borrow_mut()
402 .insert(name, external_module.clone());
403 self.build_reduced_graph_for_external_crate(&external_module);
409 let name_bindings = self.add_child(name, parent, ForbidDuplicateModules, sp);
411 let parent_link = self.get_parent_link(parent, name);
412 let def_id = DefId { krate: 0, node: item.id };
413 name_bindings.define_module(parent_link,
420 name_bindings.get_module()
423 ItemForeignMod(..) => parent.clone(),
425 // These items live in the value namespace.
426 ItemStatic(_, m, _) => {
427 let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp);
428 let mutbl = m == hir::MutMutable;
430 name_bindings.define_value(DefStatic(DefId::local(item.id), mutbl), sp, modifiers);
434 self.add_child(name, parent, ForbidDuplicateValues, sp)
435 .define_value(DefConst(DefId::local(item.id)), sp, modifiers);
438 ItemFn(_, _, _, _, _, _) => {
439 let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp);
441 let def = DefFn(DefId::local(item.id), false);
442 name_bindings.define_value(def, sp, modifiers);
446 // These items live in the type namespace.
449 self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp);
451 name_bindings.define_type(DefTy(DefId::local(item.id), false), sp,
454 let parent_link = self.get_parent_link(parent, name);
455 name_bindings.set_module_kind(parent_link,
456 Some(DefId::local(item.id)),
464 ItemEnum(ref enum_definition, _) => {
466 self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp);
468 name_bindings.define_type(DefTy(DefId::local(item.id), true), sp, modifiers);
470 let parent_link = self.get_parent_link(parent, name);
471 name_bindings.set_module_kind(parent_link,
472 Some(DefId::local(item.id)),
478 let module = name_bindings.get_module();
480 for variant in &(*enum_definition).variants {
481 self.build_reduced_graph_for_variant(
483 DefId::local(item.id),
489 // These items live in both the type and value namespaces.
490 ItemStruct(ref struct_def, _) => {
491 // Adding to both Type and Value namespaces or just Type?
492 let (forbid, ctor_id) = match struct_def.ctor_id {
493 Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)),
494 None => (ForbidDuplicateTypesAndModules, None)
497 let name_bindings = self.add_child(name, parent, forbid, sp);
499 // Define a name in the type namespace.
500 name_bindings.define_type(DefTy(DefId::local(item.id), false), sp, modifiers);
502 // If this is a newtype or unit-like struct, define a name
503 // in the value namespace as well
504 if let Some(cid) = ctor_id {
505 name_bindings.define_value(DefStruct(DefId::local(cid)), sp, modifiers);
508 // Record the def ID and fields of this struct.
509 let named_fields = struct_def.fields.iter().filter_map(|f| {
511 NamedField(name, _) => Some(name),
512 UnnamedField(_) => None
515 self.structs.insert(DefId::local(item.id), named_fields);
520 ItemDefaultImpl(_, _) |
521 ItemImpl(..) => parent.clone(),
523 ItemTrait(_, _, _, ref items) => {
525 self.add_child(name, parent, ForbidDuplicateTypesAndModules, sp);
527 // Add all the items within to a new module.
528 let parent_link = self.get_parent_link(parent, name);
529 name_bindings.define_module(parent_link,
530 Some(DefId::local(item.id)),
535 let module_parent = name_bindings.get_module();
537 let def_id = DefId::local(item.id);
539 // Add the names of all the items to the trait info.
540 for trait_item in items {
541 let name_bindings = self.add_child(trait_item.name,
543 ForbidDuplicateTypesAndValues,
546 match trait_item.node {
547 hir::ConstTraitItem(..) => {
548 let def = DefAssociatedConst(DefId::local(trait_item.id));
549 // NB: not DefModifiers::IMPORTABLE
550 name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC);
552 hir::MethodTraitItem(..) => {
553 let def = DefMethod(DefId::local(trait_item.id));
554 // NB: not DefModifiers::IMPORTABLE
555 name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC);
557 hir::TypeTraitItem(..) => {
558 let def = DefAssociatedTy(DefId::local(item.id),
559 DefId::local(trait_item.id));
560 // NB: not DefModifiers::IMPORTABLE
561 name_bindings.define_type(def, trait_item.span, DefModifiers::PUBLIC);
565 self.trait_item_map.insert((trait_item.name, def_id),
566 DefId::local(trait_item.id));
569 name_bindings.define_type(DefTrait(def_id), sp, modifiers);
575 // Constructs the reduced graph for one variant. Variants exist in the
576 // type and value namespaces.
577 fn build_reduced_graph_for_variant(&mut self,
580 parent: &Rc<Module>) {
581 let name = variant.node.name;
582 let is_exported = match variant.node.kind {
583 TupleVariantKind(_) => false,
584 StructVariantKind(_) => {
585 // Not adding fields for variants as they are not accessed with a self receiver
586 self.structs.insert(DefId::local(variant.node.id), Vec::new());
591 let child = self.add_child(name, parent,
592 ForbidDuplicateTypesAndValues,
594 // variants are always treated as importable to allow them to be glob
596 child.define_value(DefVariant(item_id,
597 DefId::local(variant.node.id), is_exported),
598 variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
599 child.define_type(DefVariant(item_id,
600 DefId::local(variant.node.id), is_exported),
601 variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
604 /// Constructs the reduced graph for one foreign item.
605 fn build_reduced_graph_for_foreign_item(&mut self,
606 foreign_item: &ForeignItem,
607 parent: &Rc<Module>) {
608 let name = foreign_item.name;
609 let is_public = foreign_item.vis == hir::Public;
610 let modifiers = if is_public {
613 DefModifiers::empty()
614 } | DefModifiers::IMPORTABLE;
616 self.add_child(name, parent, ForbidDuplicateValues,
619 let def = match foreign_item.node {
620 ForeignItemFn(..) => {
621 DefFn(DefId::local(foreign_item.id), false)
623 ForeignItemStatic(_, m) => {
624 DefStatic(DefId::local(foreign_item.id), m)
627 name_bindings.define_value(def, foreign_item.span, modifiers);
630 fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &Rc<Module>) -> Rc<Module> {
631 if self.block_needs_anonymous_module(block) {
632 let block_id = block.id;
634 debug!("(building reduced graph for block) creating a new \
635 anonymous module for block {}",
638 let new_module = Rc::new(Module::new(
639 BlockParentLink(Rc::downgrade(parent), block_id),
644 parent.anonymous_children.borrow_mut().insert(block_id, new_module.clone());
651 fn handle_external_def(&mut self,
654 child_name_bindings: &NameBindings,
657 new_parent: &Rc<Module>) {
658 debug!("(building reduced graph for \
659 external crate) building external def {}, priv {:?}",
661 let is_public = vis == hir::Public;
662 let modifiers = if is_public {
665 DefModifiers::empty()
666 } | DefModifiers::IMPORTABLE;
667 let is_exported = is_public && match new_parent.def_id.get() {
669 Some(did) => self.external_exports.contains(&did)
672 self.external_exports.insert(def.def_id());
675 let kind = match def {
676 DefTy(_, true) => EnumModuleKind,
677 DefTy(_, false) | DefStruct(..) => TypeModuleKind,
678 _ => NormalModuleKind
682 DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
683 DefTy(def_id, _) => {
684 let type_def = child_name_bindings.type_def.borrow().clone();
686 Some(TypeNsDef { module_def: Some(module_def), .. }) => {
687 debug!("(building reduced graph for external crate) \
688 already created module");
689 module_def.def_id.set(Some(def_id));
692 debug!("(building reduced graph for \
693 external crate) building module \
694 {} {}", final_ident, is_public);
695 let parent_link = self.get_parent_link(new_parent, name);
697 child_name_bindings.define_module(parent_link,
710 DefMod(_) | DefForeignMod(_) => {}
711 DefVariant(_, variant_id, is_struct) => {
712 debug!("(building reduced graph for external crate) building \
715 // variants are always treated as importable to allow them to be
717 let modifiers = DefModifiers::PUBLIC | DefModifiers::IMPORTABLE;
719 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
720 // Not adding fields for variants as they are not accessed with a self receiver
721 self.structs.insert(variant_id, Vec::new());
723 child_name_bindings.define_value(def, DUMMY_SP, modifiers);
726 DefFn(ctor_id, true) => {
727 child_name_bindings.define_value(
728 csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id)
729 .map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, modifiers);
731 DefFn(..) | DefStatic(..) | DefConst(..) | DefAssociatedConst(..) |
733 debug!("(building reduced graph for external \
734 crate) building value (fn/static) {}", final_ident);
735 // impl methods have already been defined with the correct importability modifier
736 let mut modifiers = match *child_name_bindings.value_def.borrow() {
737 Some(ref def) => (modifiers & !DefModifiers::IMPORTABLE) |
738 (def.modifiers & DefModifiers::IMPORTABLE),
741 if new_parent.kind.get() != NormalModuleKind {
742 modifiers = modifiers & !DefModifiers::IMPORTABLE;
744 child_name_bindings.define_value(def, DUMMY_SP, modifiers);
746 DefTrait(def_id) => {
747 debug!("(building reduced graph for external \
748 crate) building type {}", final_ident);
750 // If this is a trait, add all the trait item names to the trait
753 let trait_item_def_ids =
754 csearch::get_trait_item_def_ids(&self.session.cstore, def_id);
755 for trait_item_def in &trait_item_def_ids {
756 let trait_item_name = csearch::get_trait_name(&self.session.cstore,
757 trait_item_def.def_id());
759 debug!("(building reduced graph for external crate) ... \
760 adding trait item '{}'",
763 self.trait_item_map.insert((trait_item_name, def_id),
764 trait_item_def.def_id());
767 self.external_exports.insert(trait_item_def.def_id());
771 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
773 // Define a module if necessary.
774 let parent_link = self.get_parent_link(new_parent, name);
775 child_name_bindings.set_module_kind(parent_link,
782 DefTy(..) | DefAssociatedTy(..) => {
783 debug!("(building reduced graph for external \
784 crate) building type {}", final_ident);
786 let modifiers = match new_parent.kind.get() {
787 NormalModuleKind => modifiers,
788 _ => modifiers & !DefModifiers::IMPORTABLE
791 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
793 DefStruct(def_id) => {
794 debug!("(building reduced graph for external \
795 crate) building type and value for {}",
797 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
798 let fields = csearch::get_struct_field_names(&self.session.cstore, def_id);
800 if fields.is_empty() {
801 child_name_bindings.define_value(def, DUMMY_SP, modifiers);
804 // Record the def ID and fields of this struct.
805 self.structs.insert(def_id, fields);
807 DefLocal(..) | DefPrimTy(..) | DefTyParam(..) |
808 DefUse(..) | DefUpvar(..) | DefRegion(..) |
809 DefLabel(..) | DefSelfTy(..) => {
810 panic!("didn't expect `{:?}`", def);
815 /// Builds the reduced graph for a single item in an external crate.
816 fn build_reduced_graph_for_external_crate_def(&mut self,
820 def_visibility: Visibility) {
823 // Add the new child item, if necessary.
825 DefForeignMod(def_id) => {
826 // Foreign modules have no names. Recur and populate
828 csearch::each_child_of_item(&self.session.cstore,
833 self.build_reduced_graph_for_external_crate_def(
841 let child_name_bindings =
847 self.handle_external_def(def,
849 &*child_name_bindings,
857 debug!("(building reduced graph for external crate) \
861 debug!("(building reduced graph for external crate) \
867 /// Builds the reduced graph rooted at the given external module.
868 fn populate_external_module(&mut self, module: &Rc<Module>) {
869 debug!("(populating external module) attempting to populate {}",
870 module_to_string(&**module));
872 let def_id = match module.def_id.get() {
874 debug!("(populating external module) ... no def ID!");
877 Some(def_id) => def_id,
880 csearch::each_child_of_item(&self.session.cstore,
882 |def_like, child_name, visibility| {
883 debug!("(populating external module) ... found ident: {}",
885 self.build_reduced_graph_for_external_crate_def(module,
890 module.populated.set(true)
893 /// Ensures that the reduced graph rooted at the given external module
894 /// is built, building it if it is not.
895 fn populate_module_if_necessary(&mut self, module: &Rc<Module>) {
896 if !module.populated.get() {
897 self.populate_external_module(module)
899 assert!(module.populated.get())
902 /// Builds the reduced graph rooted at the 'use' directive for an external
904 fn build_reduced_graph_for_external_crate(&mut self, root: &Rc<Module>) {
905 csearch::each_top_level_item_of_crate(&self.session.cstore,
910 |def_like, name, visibility| {
911 self.build_reduced_graph_for_external_crate_def(root, def_like, name, visibility)
915 /// Creates and adds an import directive to the given module.
916 fn build_import_directive(&mut self,
918 module_path: Vec<Name>,
919 subclass: ImportDirectiveSubclass,
923 shadowable: Shadowable) {
924 module_.imports.borrow_mut().push(ImportDirective::new(module_path,
930 self.unresolved_imports += 1;
933 module_.inc_pub_count();
936 // Bump the reference count on the name. Or, if this is a glob, set
937 // the appropriate flag.
940 SingleImport(target, _) => {
941 debug!("(building import directive) building import directive: {}::{}",
942 names_to_string(&module_.imports.borrow().last().unwrap().module_path),
945 let mut import_resolutions = module_.import_resolutions.borrow_mut();
946 match import_resolutions.get_mut(&target) {
947 Some(resolution) => {
948 debug!("(building import directive) bumping reference");
949 resolution.outstanding_references += 1;
951 // the source of this name is different now
952 resolution.type_id = id;
953 resolution.value_id = id;
954 resolution.is_public = is_public;
959 debug!("(building import directive) creating new");
960 let mut resolution = ImportResolution::new(id, is_public);
961 resolution.outstanding_references = 1;
962 import_resolutions.insert(target, resolution);
965 // Set the glob flag. This tells us that we don't know the
966 // module's exports ahead of time.
968 module_.inc_glob_count();
970 module_.inc_pub_glob_count();
977 struct BuildReducedGraphVisitor<'a, 'b:'a, 'tcx:'b> {
978 builder: GraphBuilder<'a, 'b, 'tcx>,
982 impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
983 fn visit_item(&mut self, item: &Item) {
984 let p = self.builder.build_reduced_graph_for_item(item, &self.parent);
985 let old_parent = replace(&mut self.parent, p);
986 visit::walk_item(self, item);
987 self.parent = old_parent;
990 fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
991 self.builder.build_reduced_graph_for_foreign_item(foreign_item, &self.parent);
994 fn visit_block(&mut self, block: &Block) {
995 let np = self.builder.build_reduced_graph_for_block(block, &self.parent);
996 let old_parent = replace(&mut self.parent, np);
997 visit::walk_block(self, block);
998 self.parent = old_parent;
1002 pub fn build_reduced_graph(resolver: &mut Resolver, krate: &hir::Crate) {
1005 }.build_reduced_graph(krate);
1008 pub fn populate_module_if_necessary(resolver: &mut Resolver, module: &Rc<Module>) {
1011 }.populate_module_if_necessary(module);