1 // Copyright 2015 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 use self::ImportDirectiveSubclass::*;
16 use Namespace::{self, TypeNS, ValueNS};
18 use NamespaceResult::{BoundResult, UnboundResult, UnknownResult};
23 use UseLexicalScopeFlag;
24 use {names_to_string, module_to_string};
26 use build_reduced_graph;
28 use rustc::middle::def::*;
29 use rustc::middle::privacy::*;
31 use syntax::ast::{DefId, NodeId, Name};
32 use syntax::attr::AttrMetaMethods;
33 use syntax::parse::token;
34 use syntax::codemap::Span;
36 use std::mem::replace;
40 /// Contains data for specific types of import directives.
41 #[derive(Copy, Clone,Debug)]
42 pub enum ImportDirectiveSubclass {
43 SingleImport(Name /* target */, Name /* source */),
47 /// Whether an import can be shadowed by another import.
48 #[derive(Debug,PartialEq,Clone,Copy)]
54 /// One import directive.
56 pub struct ImportDirective {
57 pub module_path: Vec<Name>,
58 pub subclass: ImportDirectiveSubclass,
61 pub is_public: bool, // see note in ImportResolution about how to use this
62 pub shadowable: Shadowable,
65 impl ImportDirective {
66 pub fn new(module_path: Vec<Name> ,
67 subclass: ImportDirectiveSubclass,
71 shadowable: Shadowable)
74 module_path: module_path,
79 shadowable: shadowable,
84 /// The item that an import resolves to.
85 #[derive(Clone,Debug)]
87 pub target_module: Rc<Module>,
88 pub bindings: Rc<NameBindings>,
89 pub shadowable: Shadowable,
93 pub fn new(target_module: Rc<Module>,
94 bindings: Rc<NameBindings>,
95 shadowable: Shadowable)
98 target_module: target_module,
100 shadowable: shadowable,
105 /// An ImportResolution represents a particular `use` directive.
107 pub struct ImportResolution {
108 /// Whether this resolution came from a `use` or a `pub use`. Note that this
109 /// should *not* be used whenever resolution is being performed. Privacy
110 /// testing occurs during a later phase of compilation.
113 // The number of outstanding references to this name. When this reaches
114 // zero, outside modules can count on the targets being correct. Before
115 // then, all bets are off; future imports could override this name.
116 // Note that this is usually either 0 or 1 - shadowing is forbidden the only
117 // way outstanding_references is > 1 in a legal program is if the name is
118 // used in both namespaces.
119 pub outstanding_references: usize,
121 /// The value that this `use` directive names, if there is one.
122 pub value_target: Option<Target>,
123 /// The source node of the `use` directive leading to the value target
125 pub value_id: NodeId,
127 /// The type that this `use` directive names, if there is one.
128 pub type_target: Option<Target>,
129 /// The source node of the `use` directive leading to the type target
134 impl ImportResolution {
135 pub fn new(id: NodeId, is_public: bool) -> ImportResolution {
139 outstanding_references: 0,
142 is_public: is_public,
146 pub fn target_for_namespace(&self, namespace: Namespace)
149 TypeNS => self.type_target.clone(),
150 ValueNS => self.value_target.clone(),
154 pub fn id(&self, namespace: Namespace) -> NodeId {
156 TypeNS => self.type_id,
157 ValueNS => self.value_id,
161 pub fn shadowable(&self, namespace: Namespace) -> Shadowable {
162 let target = self.target_for_namespace(namespace);
163 if target.is_none() {
164 return Shadowable::Always;
167 target.unwrap().shadowable
170 pub fn set_target_and_id(&mut self,
171 namespace: Namespace,
172 target: Option<Target>,
176 self.type_target = target;
180 self.value_target = target;
188 struct ImportResolver<'a, 'b:'a, 'tcx:'b> {
189 resolver: &'a mut Resolver<'b, 'tcx>
192 impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
195 // This is a fixed-point algorithm. We resolve imports until our efforts
196 // are stymied by an unresolved import; then we bail out of the current
197 // module and continue. We terminate successfully once no more imports
198 // remain or unsuccessfully when no forward progress in resolving imports
201 /// Resolves all imports for the crate. This method performs the fixed-
203 fn resolve_imports(&mut self) {
205 let mut prev_unresolved_imports = 0;
207 debug!("(resolving imports) iteration {}, {} imports left",
208 i, self.resolver.unresolved_imports);
210 let module_root = self.resolver.graph_root.get_module();
211 self.resolve_imports_for_module_subtree(module_root.clone());
213 if self.resolver.unresolved_imports == 0 {
214 debug!("(resolving imports) success");
218 if self.resolver.unresolved_imports == prev_unresolved_imports {
219 self.resolver.report_unresolved_imports(module_root);
224 prev_unresolved_imports = self.resolver.unresolved_imports;
228 /// Attempts to resolve imports for the given module and all of its
230 fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>) {
231 debug!("(resolving imports for module subtree) resolving {}",
232 module_to_string(&*module_));
233 let orig_module = replace(&mut self.resolver.current_module, module_.clone());
234 self.resolve_imports_for_module(module_.clone());
235 self.resolver.current_module = orig_module;
237 build_reduced_graph::populate_module_if_necessary(self.resolver, &module_);
238 for (_, child_node) in module_.children.borrow().iter() {
239 match child_node.get_module_if_available() {
243 Some(child_module) => {
244 self.resolve_imports_for_module_subtree(child_module);
249 for (_, child_module) in module_.anonymous_children.borrow().iter() {
250 self.resolve_imports_for_module_subtree(child_module.clone());
254 /// Attempts to resolve imports for the given module only.
255 fn resolve_imports_for_module(&mut self, module: Rc<Module>) {
256 if module.all_imports_resolved() {
257 debug!("(resolving imports for module) all imports resolved for \
259 module_to_string(&*module));
263 let imports = module.imports.borrow();
264 let import_count = imports.len();
265 while module.resolved_import_count.get() < import_count {
266 let import_index = module.resolved_import_count.get();
267 let import_directive = &(*imports)[import_index];
268 match self.resolve_import_for_module(module.clone(),
270 ResolveResult::Failed(err) => {
271 let (span, help) = match err {
272 Some((span, msg)) => (span, format!(". {}", msg)),
273 None => (import_directive.span, String::new())
275 resolve_err!(self.resolver, span, E0432,
276 "unresolved import `{}`{}",
277 import_path_to_string(
278 &import_directive.module_path,
279 import_directive.subclass),
282 ResolveResult::Indeterminate => break, // Bail out. We'll come around next time.
283 ResolveResult::Success(()) => () // Good. Continue.
286 module.resolved_import_count
287 .set(module.resolved_import_count.get() + 1);
291 /// Attempts to resolve the given import. The return value indicates
292 /// failure if we're certain the name does not exist, indeterminate if we
293 /// don't know whether the name exists at the moment due to other
294 /// currently-unresolved imports, or success if we know the name exists.
295 /// If successful, the resolved bindings are written into the module.
296 fn resolve_import_for_module(&mut self,
298 import_directive: &ImportDirective)
299 -> ResolveResult<()> {
300 let mut resolution_result = ResolveResult::Failed(None);
301 let module_path = &import_directive.module_path;
303 debug!("(resolving import for module) resolving import `{}::...` in `{}`",
304 names_to_string(&module_path[..]),
305 module_to_string(&*module_));
307 // First, resolve the module path for the directive, if necessary.
308 let container = if module_path.is_empty() {
309 // Use the crate root.
310 Some((self.resolver.graph_root.get_module(), LastMod(AllPublic)))
312 match self.resolver.resolve_module_path(module_.clone(),
314 UseLexicalScopeFlag::DontUseLexicalScope,
315 import_directive.span,
316 NameSearchType::ImportSearch) {
317 ResolveResult::Failed(err) => {
318 resolution_result = ResolveResult::Failed(err);
321 ResolveResult::Indeterminate => {
322 resolution_result = ResolveResult::Indeterminate;
325 ResolveResult::Success(container) => Some(container),
331 Some((containing_module, lp)) => {
332 // We found the module that the target is contained
333 // within. Attempt to resolve the import within it.
335 match import_directive.subclass {
336 SingleImport(target, source) => {
338 self.resolve_single_import(&module_,
347 self.resolve_glob_import(&module_,
356 // Decrement the count of unresolved imports.
357 match resolution_result {
358 ResolveResult::Success(()) => {
359 assert!(self.resolver.unresolved_imports >= 1);
360 self.resolver.unresolved_imports -= 1;
363 // Nothing to do here; just return the error.
367 // Decrement the count of unresolved globs if necessary. But only if
368 // the resolution result is indeterminate -- otherwise we'll stop
369 // processing imports here. (See the loop in
370 // resolve_imports_for_module).
372 if !resolution_result.indeterminate() {
373 match import_directive.subclass {
375 assert!(module_.glob_count.get() >= 1);
376 module_.glob_count.set(module_.glob_count.get() - 1);
378 SingleImport(..) => {
384 return resolution_result;
387 fn resolve_single_import(&mut self,
389 target_module: Rc<Module>,
392 directive: &ImportDirective,
394 -> ResolveResult<()> {
395 debug!("(resolving single import) resolving `{}` = `{}::{}` from \
396 `{}` id {}, last private {:?}",
398 module_to_string(&*target_module),
400 module_to_string(module_),
407 self.resolver.session
408 .span_bug(directive.span,
409 "not expecting Import here, must be LastMod")
413 // We need to resolve both namespaces for this to succeed.
416 let mut value_result = UnknownResult;
417 let mut type_result = UnknownResult;
419 // Search for direct children of the containing module.
420 build_reduced_graph::populate_module_if_necessary(self.resolver, &target_module);
422 match target_module.children.borrow().get(&source) {
426 Some(ref child_name_bindings) => {
427 // pub_err makes sure we don't give the same error twice.
428 let mut pub_err = false;
429 if child_name_bindings.defined_in_namespace(ValueNS) {
430 debug!("(resolving single import) found value binding");
431 value_result = BoundResult(target_module.clone(),
432 (*child_name_bindings).clone());
433 if directive.is_public && !child_name_bindings.is_public(ValueNS) {
434 let msg = format!("`{}` is private", source);
435 span_err!(self.resolver.session, directive.span, E0364, "{}", &msg);
439 if child_name_bindings.defined_in_namespace(TypeNS) {
440 debug!("(resolving single import) found type binding");
441 type_result = BoundResult(target_module.clone(),
442 (*child_name_bindings).clone());
443 if !pub_err && directive.is_public && !child_name_bindings.is_public(TypeNS) {
444 let msg = format!("`{}` is private", source);
445 span_err!(self.resolver.session, directive.span, E0365, "{}", &msg);
451 // Unless we managed to find a result in both namespaces (unlikely),
452 // search imports as well.
453 let mut value_used_reexport = false;
454 let mut type_used_reexport = false;
455 match (value_result.clone(), type_result.clone()) {
456 (BoundResult(..), BoundResult(..)) => {} // Continue.
458 // If there is an unresolved glob at this point in the
459 // containing module, bail out. We don't know enough to be
460 // able to resolve this import.
462 if target_module.glob_count.get() > 0 {
463 debug!("(resolving single import) unresolved glob; \
465 return ResolveResult::Indeterminate;
468 // Now search the exported imports within the containing module.
469 match target_module.import_resolutions.borrow().get(&source) {
471 debug!("(resolving single import) no import");
472 // The containing module definitely doesn't have an
473 // exported import with the name in question. We can
474 // therefore accurately report that the names are
477 if value_result.is_unknown() {
478 value_result = UnboundResult;
480 if type_result.is_unknown() {
481 type_result = UnboundResult;
484 Some(import_resolution)
485 if import_resolution.outstanding_references == 0 => {
487 fn get_binding(this: &mut Resolver,
488 import_resolution: &ImportResolution,
489 namespace: Namespace,
493 // Import resolutions must be declared with "pub"
494 // in order to be exported.
495 if !import_resolution.is_public {
496 return UnboundResult;
499 match import_resolution.target_for_namespace(namespace) {
501 return UnboundResult;
508 debug!("(resolving single import) found \
509 import in ns {:?}", namespace);
510 let id = import_resolution.id(namespace);
511 // track used imports and extern crates as well
512 this.used_imports.insert((id, namespace));
513 this.record_import_use(id, *source);
514 match target_module.def_id.get() {
515 Some(DefId{krate: kid, ..}) => {
516 this.used_crates.insert(kid);
520 return BoundResult(target_module, bindings);
525 // The name is an import which has been fully
526 // resolved. We can, therefore, just follow it.
527 if value_result.is_unknown() {
528 value_result = get_binding(self.resolver,
532 value_used_reexport = import_resolution.is_public;
534 if type_result.is_unknown() {
535 type_result = get_binding(self.resolver,
539 type_used_reexport = import_resolution.is_public;
544 // If target_module is the same module whose import we are resolving
545 // and there it has an unresolved import with the same name as `source`,
546 // then the user is actually trying to import an item that is declared
550 // use self::submodule;
551 // pub mod submodule;
553 // In this case we continue as if we resolved the import and let the
554 // check_for_conflicts_between_imports_and_items call below handle
556 match (module_.def_id.get(), target_module.def_id.get()) {
557 (Some(id1), Some(id2)) if id1 == id2 => {
558 if value_result.is_unknown() {
559 value_result = UnboundResult;
561 if type_result.is_unknown() {
562 type_result = UnboundResult;
566 // The import is unresolved. Bail out.
567 debug!("(resolving single import) unresolved import; \
569 return ResolveResult::Indeterminate;
577 let mut value_used_public = false;
578 let mut type_used_public = false;
580 // If we didn't find a result in the type namespace, search the
583 BoundResult(..) => {}
585 match target_module.external_module_children.borrow_mut().get(&source).cloned() {
586 None => {} // Continue.
588 debug!("(resolving single import) found external module");
589 // track the module as used.
590 match module.def_id.get() {
591 Some(DefId{krate: kid, ..}) => {
592 self.resolver.used_crates.insert(kid);
597 Rc::new(Resolver::create_name_bindings_from_module(module));
598 type_result = BoundResult(target_module.clone(), name_bindings);
599 type_used_public = true;
605 // We've successfully resolved the import. Write the results in.
606 let mut import_resolutions = module_.import_resolutions.borrow_mut();
607 let import_resolution = import_resolutions.get_mut(&target).unwrap();
610 let mut check_and_write_import = |namespace, result: &_, used_public: &mut bool| {
611 let namespace_name = match namespace {
617 BoundResult(ref target_module, ref name_bindings) => {
618 debug!("(resolving single import) found {:?} target: {:?}",
620 name_bindings.def_for_namespace(namespace));
621 self.check_for_conflicting_import(
627 self.check_that_import_is_importable(
633 let target = Some(Target::new(target_module.clone(),
634 name_bindings.clone(),
635 directive.shadowable));
636 import_resolution.set_target_and_id(namespace, target, directive.id);
637 import_resolution.is_public = directive.is_public;
638 *used_public = name_bindings.defined_in_public_namespace(namespace);
640 UnboundResult => { /* Continue. */ }
642 panic!("{:?} result should be known at this point", namespace_name);
646 check_and_write_import(ValueNS, &value_result, &mut value_used_public);
647 check_and_write_import(TypeNS, &type_result, &mut type_used_public);
650 self.check_for_conflicts_between_imports_and_items(
656 if value_result.is_unbound() && type_result.is_unbound() {
657 let msg = format!("There is no `{}` in `{}`",
659 module_to_string(&target_module));
660 return ResolveResult::Failed(Some((directive.span, msg)));
662 let value_used_public = value_used_reexport || value_used_public;
663 let type_used_public = type_used_reexport || type_used_public;
665 assert!(import_resolution.outstanding_references >= 1);
666 import_resolution.outstanding_references -= 1;
668 // Record what this import resolves to for later uses in documentation,
669 // this may resolve to either a value or a type, but for documentation
670 // purposes it's good enough to just favor one over the other.
671 let value_def_and_priv = import_resolution.value_target.as_ref().map(|target| {
672 let def = target.bindings.def_for_namespace(ValueNS).unwrap();
673 (def, if value_used_public { lp } else { DependsOn(def.def_id()) })
675 let type_def_and_priv = import_resolution.type_target.as_ref().map(|target| {
676 let def = target.bindings.def_for_namespace(TypeNS).unwrap();
677 (def, if type_used_public { lp } else { DependsOn(def.def_id()) })
680 let import_lp = LastImport {
681 value_priv: value_def_and_priv.map(|(_, p)| p),
683 type_priv: type_def_and_priv.map(|(_, p)| p),
687 if let Some((def, _)) = value_def_and_priv {
688 self.resolver.def_map.borrow_mut().insert(directive.id, PathResolution {
690 last_private: import_lp,
694 if let Some((def, _)) = type_def_and_priv {
695 self.resolver.def_map.borrow_mut().insert(directive.id, PathResolution {
697 last_private: import_lp,
702 debug!("(resolving single import) successfully resolved import");
703 return ResolveResult::Success(());
706 // Resolves a glob import. Note that this function cannot fail; it either
707 // succeeds or bails out (as importing * from an empty module or a module
708 // that exports nothing is valid). target_module is the module we are
709 // actually importing, i.e., `foo` in `use foo::*`.
710 fn resolve_glob_import(&mut self,
712 target_module: Rc<Module>,
713 import_directive: &ImportDirective,
715 -> ResolveResult<()> {
716 let id = import_directive.id;
717 let is_public = import_directive.is_public;
719 // This function works in a highly imperative manner; it eagerly adds
720 // everything it can to the list of import resolutions of the module
722 debug!("(resolving glob import) resolving glob import {}", id);
724 // We must bail out if the node has unresolved imports of any kind
725 // (including globs).
726 if !(*target_module).all_imports_resolved() {
727 debug!("(resolving glob import) target module has unresolved \
728 imports; bailing out");
729 return ResolveResult::Indeterminate;
732 assert_eq!(target_module.glob_count.get(), 0);
734 // Add all resolved imports from the containing module.
735 let import_resolutions = target_module.import_resolutions.borrow();
736 for (ident, target_import_resolution) in import_resolutions.iter() {
737 debug!("(resolving glob import) writing module resolution \
740 module_to_string(module_));
742 if !target_import_resolution.is_public {
743 debug!("(resolving glob import) nevermind, just kidding");
747 // Here we merge two import resolutions.
748 let mut import_resolutions = module_.import_resolutions.borrow_mut();
749 match import_resolutions.get_mut(ident) {
750 Some(dest_import_resolution) => {
751 // Merge the two import resolutions at a finer-grained
754 match target_import_resolution.value_target {
758 Some(ref value_target) => {
759 self.check_for_conflicting_import(&dest_import_resolution,
760 import_directive.span,
763 dest_import_resolution.value_target = Some(value_target.clone());
766 match target_import_resolution.type_target {
770 Some(ref type_target) => {
771 self.check_for_conflicting_import(&dest_import_resolution,
772 import_directive.span,
775 dest_import_resolution.type_target = Some(type_target.clone());
778 dest_import_resolution.is_public = is_public;
784 // Simple: just copy the old import resolution.
785 let mut new_import_resolution = ImportResolution::new(id, is_public);
786 new_import_resolution.value_target =
787 target_import_resolution.value_target.clone();
788 new_import_resolution.type_target =
789 target_import_resolution.type_target.clone();
791 import_resolutions.insert(*ident, new_import_resolution);
794 // Add all children from the containing module.
795 build_reduced_graph::populate_module_if_necessary(self.resolver, &target_module);
797 for (&name, name_bindings) in target_module.children.borrow().iter() {
798 self.merge_import_resolution(module_,
799 target_module.clone(),
802 name_bindings.clone());
806 // Add external module children from the containing module.
807 for (&name, module) in target_module.external_module_children.borrow().iter() {
809 Rc::new(Resolver::create_name_bindings_from_module(module.clone()));
810 self.merge_import_resolution(module_,
811 target_module.clone(),
817 // Record the destination of this import
818 if let Some(did) = target_module.def_id.get() {
819 self.resolver.def_map.borrow_mut().insert(id, PathResolution {
820 base_def: DefMod(did),
826 debug!("(resolving glob import) successfully resolved import");
827 return ResolveResult::Success(());
830 fn merge_import_resolution(&mut self,
832 containing_module: Rc<Module>,
833 import_directive: &ImportDirective,
835 name_bindings: Rc<NameBindings>) {
836 let id = import_directive.id;
837 let is_public = import_directive.is_public;
839 let mut import_resolutions = module_.import_resolutions.borrow_mut();
840 let dest_import_resolution = import_resolutions.entry(name)
841 .or_insert_with(|| ImportResolution::new(id, is_public));
843 debug!("(resolving glob import) writing resolution `{}` in `{}` \
846 module_to_string(&*containing_module),
847 module_to_string(module_));
849 // Merge the child item into the import resolution.
851 let mut merge_child_item = |namespace| {
852 let modifier = DefModifiers::IMPORTABLE | DefModifiers::PUBLIC;
854 if name_bindings.defined_in_namespace_with(namespace, modifier) {
855 let namespace_name = match namespace {
859 debug!("(resolving glob import) ... for {} target", namespace_name);
860 if dest_import_resolution.shadowable(namespace) == Shadowable::Never {
861 let msg = format!("a {} named `{}` has already been imported \
865 span_err!(self.resolver.session, import_directive.span, E0251, "{}", msg);
867 let target = Target::new(containing_module.clone(),
868 name_bindings.clone(),
869 import_directive.shadowable);
870 dest_import_resolution.set_target_and_id(namespace,
876 merge_child_item(ValueNS);
877 merge_child_item(TypeNS);
880 dest_import_resolution.is_public = is_public;
882 self.check_for_conflicts_between_imports_and_items(
884 dest_import_resolution,
885 import_directive.span,
889 /// Checks that imported names and items don't have the same name.
890 fn check_for_conflicting_import(&mut self,
891 import_resolution: &ImportResolution,
894 namespace: Namespace) {
895 let target = import_resolution.target_for_namespace(namespace);
896 debug!("check_for_conflicting_import: {}; target exists: {}",
901 Some(ref target) if target.shadowable != Shadowable::Always => {
902 let ns_word = match namespace {
904 if let Some(ref ty_def) = *target.bindings.type_def.borrow() {
905 match ty_def.module_def {
907 if module.kind.get() == ModuleKind::NormalModuleKind =>
910 if module.kind.get() == ModuleKind::TraitModuleKind =>
918 span_err!(self.resolver.session, import_span, E0252,
919 "a {} named `{}` has already been imported \
920 in this module", ns_word,
922 let use_id = import_resolution.id(namespace);
923 let item = self.resolver.ast_map.expect_item(use_id);
924 // item is syntax::ast::Item;
925 span_note!(self.resolver.session, item.span,
926 "previous import of `{}` here",
933 /// Checks that an import is actually importable
934 fn check_that_import_is_importable(&mut self,
935 name_bindings: &NameBindings,
938 namespace: Namespace) {
939 if !name_bindings.defined_in_namespace_with(namespace, DefModifiers::IMPORTABLE) {
940 let msg = format!("`{}` is not directly importable",
942 span_err!(self.resolver.session, import_span, E0253, "{}", &msg[..]);
946 /// Checks that imported names and items don't have the same name.
947 fn check_for_conflicts_between_imports_and_items(&mut self,
953 // First, check for conflicts between imports and `extern crate`s.
954 if module.external_module_children
956 .contains_key(&name) {
957 match import_resolution.type_target {
958 Some(ref target) if target.shadowable != Shadowable::Always => {
959 let msg = format!("import `{0}` conflicts with imported \
960 crate in this module \
961 (maybe you meant `use {0}::*`?)",
963 span_err!(self.resolver.session, import_span, E0254, "{}", &msg[..]);
969 // Check for item conflicts.
970 let children = module.children.borrow();
971 let name_bindings = match children.get(&name) {
973 // There can't be any conflicts.
976 Some(ref name_bindings) => (*name_bindings).clone(),
979 match import_resolution.value_target {
980 Some(ref target) if target.shadowable != Shadowable::Always => {
981 if let Some(ref value) = *name_bindings.value_def.borrow() {
982 span_err!(self.resolver.session, import_span, E0255,
983 "import `{}` conflicts with value in this module",
985 if let Some(span) = value.value_span {
986 self.resolver.session.span_note(span, "conflicting value here");
993 match import_resolution.type_target {
994 Some(ref target) if target.shadowable != Shadowable::Always => {
995 if let Some(ref ty) = *name_bindings.type_def.borrow() {
996 let (what, note) = match ty.module_def {
998 if module.kind.get() == ModuleKind::NormalModuleKind =>
999 ("existing submodule", "note conflicting module here"),
1001 if module.kind.get() == ModuleKind::TraitModuleKind =>
1002 ("trait in this module", "note conflicting trait here"),
1003 _ => ("type in this module", "note conflicting type here"),
1005 span_err!(self.resolver.session, import_span, E0256,
1006 "import `{}` conflicts with {}",
1008 if let Some(span) = ty.type_span {
1009 self.resolver.session.span_note(span, note);
1013 Some(_) | None => {}
1018 fn import_path_to_string(names: &[Name],
1019 subclass: ImportDirectiveSubclass)
1021 if names.is_empty() {
1022 import_directive_subclass_to_string(subclass)
1025 names_to_string(names),
1026 import_directive_subclass_to_string(subclass))).to_string()
1030 fn import_directive_subclass_to_string(subclass: ImportDirectiveSubclass) -> String {
1032 SingleImport(_, source) => {
1033 token::get_name(source).to_string()
1035 GlobImport => "*".to_string()
1039 pub fn resolve_imports(resolver: &mut Resolver) {
1040 let mut import_resolver = ImportResolver {
1043 import_resolver.resolve_imports();