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::*;
15 use Namespace::{self, TypeNS, ValueNS};
16 use {NameBinding, NameBindingKind};
20 use UseLexicalScopeFlag;
21 use {names_to_string, module_to_string};
22 use {resolve_error, ResolutionError};
24 use build_reduced_graph;
27 use rustc::middle::def::*;
28 use rustc::middle::def_id::DefId;
29 use rustc::middle::privacy::*;
31 use syntax::ast::{NodeId, Name};
32 use syntax::attr::AttrMetaMethods;
33 use syntax::codemap::Span;
34 use syntax::util::lev_distance::find_best_match_for_name;
36 use std::mem::replace;
38 /// Contains data for specific types of import directives.
39 #[derive(Copy, Clone,Debug)]
40 pub enum ImportDirectiveSubclass {
41 SingleImport(Name /* target */, Name /* source */),
45 /// Whether an import can be shadowed by another import.
46 #[derive(Debug,PartialEq,Clone,Copy)]
52 /// One import directive.
53 #[derive(Debug,Clone)]
54 pub struct ImportDirective {
55 pub module_path: Vec<Name>,
56 pub subclass: ImportDirectiveSubclass,
59 pub is_public: bool, // see note in ImportResolutionPerNamespace about how to use this
60 pub shadowable: Shadowable,
63 impl ImportDirective {
64 pub fn new(module_path: Vec<Name>,
65 subclass: ImportDirectiveSubclass,
69 shadowable: Shadowable)
72 module_path: module_path,
77 shadowable: shadowable,
81 // Given the binding to which this directive resolves in a particular namespace,
82 // this returns the binding for the name this directive defines in that namespace.
83 fn import<'a>(&self, binding: &'a NameBinding<'a>) -> NameBinding<'a> {
84 let mut modifiers = match self.is_public {
85 true => DefModifiers::PUBLIC | DefModifiers::IMPORTABLE,
86 false => DefModifiers::empty(),
88 if let GlobImport = self.subclass {
89 modifiers = modifiers | DefModifiers::GLOB_IMPORTED;
91 if self.shadowable == Shadowable::Always {
92 modifiers = modifiers | DefModifiers::PRELUDE;
96 kind: NameBindingKind::Import { binding: binding, id: self.id },
97 span: Some(self.span),
104 /// An ImportResolution records what we know about an imported name in a given namespace.
105 /// More specifically, it records the number of unresolved `use` directives that import the name,
106 /// the `use` directive importing the name in the namespace, and the `NameBinding` to which the
107 /// name in the namespace resolves (if applicable).
108 /// Different `use` directives may import the same name in different namespaces.
109 pub struct ImportResolution<'a> {
110 // When outstanding_references reaches zero, outside modules can count on the targets being
111 // correct. Before then, all bets are off; future `use` directives could override the name.
112 // Since shadowing is forbidden, the only way outstanding_references > 1 in a legal program
113 // is if the name is imported by exactly two `use` directives, one of which resolves to a
114 // value and the other of which resolves to a type.
115 pub outstanding_references: usize,
117 /// Whether this resolution came from a `use` or a `pub use`.
120 /// Resolution of the name in the namespace
121 pub binding: Option<&'a NameBinding<'a>>,
123 /// The source node of the `use` directive
127 impl<'a> ImportResolution<'a> {
128 pub fn new(id: NodeId, is_public: bool) -> Self {
130 outstanding_references: 0,
133 is_public: is_public,
137 pub fn shadowable(&self) -> Shadowable {
139 Some(binding) if binding.defined_with(DefModifiers::PRELUDE) =>
141 Some(_) => Shadowable::Never,
142 None => Shadowable::Always,
147 struct ImportResolvingError<'a> {
148 /// Module where the error happened
149 source_module: Module<'a>,
150 import_directive: ImportDirective,
155 struct ImportResolver<'a, 'b: 'a, 'tcx: 'b> {
156 resolver: &'a mut Resolver<'b, 'tcx>,
159 impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
162 // This is a fixed-point algorithm. We resolve imports until our efforts
163 // are stymied by an unresolved import; then we bail out of the current
164 // module and continue. We terminate successfully once no more imports
165 // remain or unsuccessfully when no forward progress in resolving imports
168 /// Resolves all imports for the crate. This method performs the fixed-
170 fn resolve_imports(&mut self) {
172 let mut prev_unresolved_imports = 0;
174 debug!("(resolving imports) iteration {}, {} imports left",
176 self.resolver.unresolved_imports);
178 let module_root = self.resolver.graph_root;
179 let errors = self.resolve_imports_for_module_subtree(module_root);
181 if self.resolver.unresolved_imports == 0 {
182 debug!("(resolving imports) success");
186 if self.resolver.unresolved_imports == prev_unresolved_imports {
188 if errors.len() > 0 {
190 self.import_resolving_error(e)
193 // Report unresolved imports only if no hard error was already reported
194 // to avoid generating multiple errors on the same import.
195 // Imports that are still indeterminate at this point are actually blocked
196 // by errored imports, so there is no point reporting them.
197 self.resolver.report_unresolved_imports(module_root);
203 prev_unresolved_imports = self.resolver.unresolved_imports;
207 /// Resolves an `ImportResolvingError` into the correct enum discriminant
208 /// and passes that on to `resolve_error`.
209 fn import_resolving_error(&self, e: ImportResolvingError<'b>) {
210 // If it's a single failed import then create a "fake" import
211 // resolution for it so that later resolve stages won't complain.
212 if let SingleImport(target, _) = e.import_directive.subclass {
213 let mut import_resolutions = e.source_module.import_resolutions.borrow_mut();
215 let resolution = import_resolutions.entry((target, ValueNS)).or_insert_with(|| {
216 debug!("(resolving import error) adding import resolution for `{}`",
219 ImportResolution::new(e.import_directive.id,
220 e.import_directive.is_public)
223 if resolution.binding.is_none() {
224 debug!("(resolving import error) adding fake target to import resolution of `{}`",
227 let dummy_binding = self.resolver.new_name_binding(NameBinding {
228 modifiers: DefModifiers::IMPORTABLE,
229 kind: NameBindingKind::Def(Def::Err),
233 resolution.binding = Some(dummy_binding);
237 let path = import_path_to_string(&e.import_directive.module_path,
238 e.import_directive.subclass);
240 resolve_error(self.resolver,
242 ResolutionError::UnresolvedImport(Some((&path, &e.help))));
245 /// Attempts to resolve imports for the given module and all of its
247 fn resolve_imports_for_module_subtree(&mut self,
249 -> Vec<ImportResolvingError<'b>> {
250 let mut errors = Vec::new();
251 debug!("(resolving imports for module subtree) resolving {}",
252 module_to_string(&*module_));
253 let orig_module = replace(&mut self.resolver.current_module, module_);
254 errors.extend(self.resolve_imports_for_module(module_));
255 self.resolver.current_module = orig_module;
257 build_reduced_graph::populate_module_if_necessary(self.resolver, module_);
258 module_.for_each_local_child(|_, _, child_node| {
259 match child_node.module() {
263 Some(child_module) => {
264 errors.extend(self.resolve_imports_for_module_subtree(child_module));
269 for (_, child_module) in module_.anonymous_children.borrow().iter() {
270 errors.extend(self.resolve_imports_for_module_subtree(child_module));
276 /// Attempts to resolve imports for the given module only.
277 fn resolve_imports_for_module(&mut self, module: Module<'b>) -> Vec<ImportResolvingError<'b>> {
278 let mut errors = Vec::new();
280 if module.all_imports_resolved() {
281 debug!("(resolving imports for module) all imports resolved for {}",
282 module_to_string(&*module));
286 let mut imports = module.imports.borrow_mut();
287 let import_count = imports.len();
288 let mut indeterminate_imports = Vec::new();
289 while module.resolved_import_count.get() + indeterminate_imports.len() < import_count {
290 let import_index = module.resolved_import_count.get();
291 match self.resolve_import_for_module(module, &imports[import_index]) {
292 ResolveResult::Failed(err) => {
293 let import_directive = &imports[import_index];
294 let (span, help) = match err {
295 Some((span, msg)) => (span, format!(". {}", msg)),
296 None => (import_directive.span, String::new()),
298 errors.push(ImportResolvingError {
299 source_module: module,
300 import_directive: import_directive.clone(),
305 ResolveResult::Indeterminate => {}
306 ResolveResult::Success(()) => {
308 module.resolved_import_count
309 .set(module.resolved_import_count.get() + 1);
313 // This resolution was not successful, keep it for later
314 indeterminate_imports.push(imports.swap_remove(import_index));
318 imports.extend(indeterminate_imports);
323 /// Attempts to resolve the given import. The return value indicates
324 /// failure if we're certain the name does not exist, indeterminate if we
325 /// don't know whether the name exists at the moment due to other
326 /// currently-unresolved imports, or success if we know the name exists.
327 /// If successful, the resolved bindings are written into the module.
328 fn resolve_import_for_module(&mut self,
330 import_directive: &ImportDirective)
331 -> ResolveResult<()> {
332 debug!("(resolving import for module) resolving import `{}::...` in `{}`",
333 names_to_string(&import_directive.module_path),
334 module_to_string(&*module_));
337 .resolve_module_path(module_,
338 &import_directive.module_path,
339 UseLexicalScopeFlag::DontUseLexicalScope,
340 import_directive.span)
341 .and_then(|(containing_module, lp)| {
342 // We found the module that the target is contained
343 // within. Attempt to resolve the import within it.
344 if let SingleImport(target, source) = import_directive.subclass {
345 self.resolve_single_import(module_,
352 self.resolve_glob_import(module_, containing_module, import_directive, lp)
356 // Decrement the count of unresolved imports.
357 assert!(self.resolver.unresolved_imports >= 1);
358 self.resolver.unresolved_imports -= 1;
360 if let GlobImport = import_directive.subclass {
361 module_.dec_glob_count();
362 if import_directive.is_public {
363 module_.dec_pub_glob_count();
366 if import_directive.is_public {
367 module_.dec_pub_count();
373 /// Resolves the name in the namespace of the module because it is being imported by
374 /// importing_module. Returns the name bindings defining the name.
375 fn resolve_name_in_module(&mut self,
376 module: Module<'b>, // Module containing the name
379 importing_module: Module<'b>) // Module importing the name
380 -> ResolveResult<&'b NameBinding<'b>> {
381 build_reduced_graph::populate_module_if_necessary(self.resolver, module);
382 if let Some(name_binding) = module.get_child(name, ns) {
383 if name_binding.is_extern_crate() {
384 // track the extern crate as used.
385 if let Some(DefId { krate, .. }) = name_binding.module().unwrap().def_id() {
386 self.resolver.used_crates.insert(krate);
389 return Success(name_binding);
392 // If there is an unresolved glob at this point in the containing module, bail out.
393 // We don't know enough to be able to resolve the name.
394 if module.pub_glob_count.get() > 0 {
395 return Indeterminate;
398 match module.import_resolutions.borrow().get(&(name, ns)) {
399 // The containing module definitely doesn't have an exported import with the
400 // name in question. We can therefore accurately report that names are unbound.
401 None => Failed(None),
403 // The name is an import which has been fully resolved, so we just follow it.
404 Some(resolution) if resolution.outstanding_references == 0 => {
405 // Import resolutions must be declared with "pub" in order to be exported.
406 if !resolution.is_public {
410 if let Some(binding) = resolution.binding {
411 self.resolver.record_import_use(name, ns, &resolution);
418 // If module is the same module whose import we are resolving and
419 // it has an unresolved import with the same name as `name`, then the user
420 // is actually trying to import an item that is declared in the same scope
423 // use self::submodule;
424 // pub mod submodule;
426 // In this case we continue as if we resolved the import and let
427 // check_for_conflicts_between_imports_and_items handle the conflict
428 Some(_) => match (importing_module.def_id(), module.def_id()) {
429 (Some(id1), Some(id2)) if id1 == id2 => Failed(None),
435 fn resolve_single_import(&mut self,
437 target_module: Module<'b>,
440 directive: &ImportDirective,
442 -> ResolveResult<()> {
443 debug!("(resolving single import) resolving `{}` = `{}::{}` from `{}` id {}, last \
446 module_to_string(&*target_module),
448 module_to_string(module_),
457 .span_bug(directive.span, "not expecting Import here, must be LastMod")
461 // We need to resolve both namespaces for this to succeed.
463 self.resolve_name_in_module(target_module, source, ValueNS, module_);
465 self.resolve_name_in_module(target_module, source, TypeNS, module_);
467 match (&value_result, &type_result) {
468 (&Success(name_binding), _) if !name_binding.is_import() &&
469 directive.is_public &&
470 !name_binding.is_public() => {
471 let msg = format!("`{}` is private, and cannot be reexported", source);
472 let note_msg = format!("Consider marking `{}` as `pub` in the imported module",
474 struct_span_err!(self.resolver.session, directive.span, E0364, "{}", &msg)
475 .span_note(directive.span, ¬e_msg)
479 (_, &Success(name_binding)) if !name_binding.is_import() && directive.is_public => {
480 if !name_binding.is_public() {
481 let msg = format!("`{}` is private, and cannot be reexported", source);
483 format!("Consider declaring type or module `{}` with `pub`", source);
484 struct_span_err!(self.resolver.session, directive.span, E0365, "{}", &msg)
485 .span_note(directive.span, ¬e_msg)
487 } else if name_binding.defined_with(DefModifiers::PRIVATE_VARIANT) {
488 let msg = format!("variant `{}` is private, and cannot be reexported \
489 (error E0364), consider declaring its enum as `pub`",
491 self.resolver.session.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
501 let mut lev_suggestion = "".to_owned();
502 match (&value_result, &type_result) {
503 (&Indeterminate, _) | (_, &Indeterminate) => return Indeterminate,
504 (&Failed(_), &Failed(_)) => {
505 let children = target_module.children.borrow();
506 let names = children.keys().map(|&(ref name, _)| name);
507 if let Some(name) = find_best_match_for_name(names, &source.as_str(), None) {
508 lev_suggestion = format!(". Did you mean to use `{}`?", name);
510 let resolutions = target_module.import_resolutions.borrow();
511 let names = resolutions.keys().map(|&(ref name, _)| name);
512 if let Some(name) = find_best_match_for_name(names,
516 format!(". Did you mean to use the re-exported import `{}`?", name);
523 // We've successfully resolved the import. Write the results in.
524 let mut import_resolutions = module_.import_resolutions.borrow_mut();
527 let mut check_and_write_import = |namespace, result| {
528 let result: &ResolveResult<&NameBinding> = result;
530 let import_resolution = import_resolutions.get_mut(&(target, namespace)).unwrap();
531 let namespace_name = match namespace {
537 Success(name_binding) => {
538 debug!("(resolving single import) found {:?} target: {:?}",
541 self.check_for_conflicting_import(&import_resolution,
546 self.check_that_import_is_importable(&name_binding,
550 import_resolution.binding =
551 Some(self.resolver.new_name_binding(directive.import(name_binding)));
552 import_resolution.id = directive.id;
553 import_resolution.is_public = directive.is_public;
555 self.add_export(module_, target, &import_resolution);
561 panic!("{:?} result should be known at this point", namespace_name);
565 self.check_for_conflicts_between_imports_and_items(module_,
568 (target, namespace));
570 check_and_write_import(ValueNS, &value_result);
571 check_and_write_import(TypeNS, &type_result);
574 if let (&Failed(_), &Failed(_)) = (&value_result, &type_result) {
575 let msg = format!("There is no `{}` in `{}`{}",
577 module_to_string(target_module), lev_suggestion);
578 return Failed(Some((directive.span, msg)));
581 let value_def_and_priv = {
582 let import_resolution_value = import_resolutions.get_mut(&(target, ValueNS)).unwrap();
583 assert!(import_resolution_value.outstanding_references >= 1);
584 import_resolution_value.outstanding_references -= 1;
586 // Record what this import resolves to for later uses in documentation,
587 // this may resolve to either a value or a type, but for documentation
588 // purposes it's good enough to just favor one over the other.
589 import_resolution_value.binding.as_ref().map(|binding| {
590 let def = binding.def().unwrap();
591 let last_private = if binding.is_public() { lp } else { DependsOn(def.def_id()) };
596 let type_def_and_priv = {
597 let import_resolution_type = import_resolutions.get_mut(&(target, TypeNS)).unwrap();
598 assert!(import_resolution_type.outstanding_references >= 1);
599 import_resolution_type.outstanding_references -= 1;
601 import_resolution_type.binding.as_ref().map(|binding| {
602 let def = binding.def().unwrap();
603 let last_private = if binding.is_public() { lp } else { DependsOn(def.def_id()) };
608 let import_lp = LastImport {
609 value_priv: value_def_and_priv.map(|(_, p)| p),
611 type_priv: type_def_and_priv.map(|(_, p)| p),
615 if let Some((def, _)) = value_def_and_priv {
616 self.resolver.def_map.borrow_mut().insert(directive.id,
619 last_private: import_lp,
623 if let Some((def, _)) = type_def_and_priv {
624 self.resolver.def_map.borrow_mut().insert(directive.id,
627 last_private: import_lp,
632 debug!("(resolving single import) successfully resolved import");
636 // Resolves a glob import. Note that this function cannot fail; it either
637 // succeeds or bails out (as importing * from an empty module or a module
638 // that exports nothing is valid). target_module is the module we are
639 // actually importing, i.e., `foo` in `use foo::*`.
640 fn resolve_glob_import(&mut self,
642 target_module: Module<'b>,
643 import_directive: &ImportDirective,
645 -> ResolveResult<()> {
646 let id = import_directive.id;
647 let is_public = import_directive.is_public;
649 // This function works in a highly imperative manner; it eagerly adds
650 // everything it can to the list of import resolutions of the module
652 debug!("(resolving glob import) resolving glob import {}", id);
654 // We must bail out if the node has unresolved imports of any kind
655 // (including globs).
656 if (*target_module).pub_count.get() > 0 {
657 debug!("(resolving glob import) target module has unresolved pub imports; bailing out");
658 return ResolveResult::Indeterminate;
661 // Add all resolved imports from the containing module.
662 let import_resolutions = target_module.import_resolutions.borrow();
664 if module_.import_resolutions.borrow_state() != ::std::cell::BorrowState::Unused {
665 // In this case, target_module == module_
666 // This means we are trying to glob import a module into itself,
668 debug!("(resolving glob imports) target module is current module; giving up");
669 return ResolveResult::Failed(Some((import_directive.span,
670 "Cannot glob-import a module into itself.".into())));
673 for (&(name, ns), target_import_resolution) in import_resolutions.iter() {
674 debug!("(resolving glob import) writing module resolution {} into `{}`",
676 module_to_string(module_));
678 // Here we merge two import resolutions.
679 let mut import_resolutions = module_.import_resolutions.borrow_mut();
680 let mut dest_import_resolution =
681 import_resolutions.entry((name, ns))
682 .or_insert_with(|| ImportResolution::new(id, is_public));
684 match target_import_resolution.binding {
685 Some(binding) if target_import_resolution.is_public => {
686 self.check_for_conflicting_import(&dest_import_resolution,
687 import_directive.span,
690 dest_import_resolution.id = id;
691 dest_import_resolution.is_public = is_public;
692 dest_import_resolution.binding =
693 Some(self.resolver.new_name_binding(import_directive.import(binding)));
694 self.add_export(module_, name, &dest_import_resolution);
700 // Add all children from the containing module.
701 build_reduced_graph::populate_module_if_necessary(self.resolver, target_module);
703 target_module.for_each_local_child(|name, ns, name_binding| {
704 self.merge_import_resolution(module_,
711 // Record the destination of this import
712 if let Some(did) = target_module.def_id() {
713 self.resolver.def_map.borrow_mut().insert(id,
715 base_def: Def::Mod(did),
721 debug!("(resolving glob import) successfully resolved import");
722 return ResolveResult::Success(());
725 fn merge_import_resolution(&mut self,
727 containing_module: Module<'b>,
728 import_directive: &ImportDirective,
729 (name, ns): (Name, Namespace),
730 name_binding: &'b NameBinding<'b>) {
731 let id = import_directive.id;
732 let is_public = import_directive.is_public;
734 let mut import_resolutions = module_.import_resolutions.borrow_mut();
735 let dest_import_resolution = import_resolutions.entry((name, ns)).or_insert_with(|| {
736 ImportResolution::new(id, is_public)
739 debug!("(resolving glob import) writing resolution `{}` in `{}` to `{}`",
741 module_to_string(&*containing_module),
742 module_to_string(module_));
744 // Merge the child item into the import resolution.
745 let modifier = DefModifiers::IMPORTABLE | DefModifiers::PUBLIC;
747 if ns == TypeNS && is_public && name_binding.defined_with(DefModifiers::PRIVATE_VARIANT) {
748 let msg = format!("variant `{}` is private, and cannot be reexported (error \
749 E0364), consider declaring its enum as `pub`", name);
750 self.resolver.session.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
752 import_directive.span,
756 if name_binding.defined_with(modifier) {
757 let namespace_name = match ns {
761 debug!("(resolving glob import) ... for {} target", namespace_name);
762 if dest_import_resolution.shadowable() == Shadowable::Never {
763 let msg = format!("a {} named `{}` has already been imported in this module",
766 span_err!(self.resolver.session, import_directive.span, E0251, "{}", msg);
768 dest_import_resolution.binding =
769 Some(self.resolver.new_name_binding(import_directive.import(name_binding)));
770 dest_import_resolution.id = id;
771 dest_import_resolution.is_public = is_public;
772 self.add_export(module_, name, &dest_import_resolution);
776 self.check_for_conflicts_between_imports_and_items(module_,
777 dest_import_resolution,
778 import_directive.span,
782 fn add_export(&mut self, module: Module<'b>, name: Name, resolution: &ImportResolution<'b>) {
783 if !resolution.is_public { return }
784 let node_id = match module.def_id() {
785 Some(def_id) => self.resolver.ast_map.as_local_node_id(def_id).unwrap(),
788 let export = match resolution.binding.as_ref().unwrap().def() {
789 Some(def) => Export { name: name, def_id: def.def_id() },
792 self.resolver.export_map.entry(node_id).or_insert(Vec::new()).push(export);
795 /// Checks that imported names and items don't have the same name.
796 fn check_for_conflicting_import(&mut self,
797 import_resolution: &ImportResolution,
800 namespace: Namespace) {
801 let binding = &import_resolution.binding;
802 debug!("check_for_conflicting_import: {}; target exists: {}",
807 Some(binding) if !binding.defined_with(DefModifiers::PRELUDE) => {
808 let ns_word = match namespace {
810 match binding.module() {
811 Some(ref module) if module.is_normal() => "module",
812 Some(ref module) if module.is_trait() => "trait",
818 let use_id = import_resolution.id;
819 let item = self.resolver.ast_map.expect_item(use_id);
820 let mut err = struct_span_err!(self.resolver.session,
823 "a {} named `{}` has already been imported \
829 "previous import of `{}` here",
837 /// Checks that an import is actually importable
838 fn check_that_import_is_importable(&mut self,
839 name_binding: &NameBinding,
842 if !name_binding.defined_with(DefModifiers::IMPORTABLE) {
843 let msg = format!("`{}` is not directly importable", name);
844 span_err!(self.resolver.session, import_span, E0253, "{}", &msg[..]);
848 /// Checks that imported names and items don't have the same name.
849 fn check_for_conflicts_between_imports_and_items(&mut self,
851 import: &ImportResolution<'b>,
853 (name, ns): (Name, Namespace)) {
854 // Check for item conflicts.
855 let name_binding = match module.get_child(name, ns) {
857 // There can't be any conflicts.
860 Some(name_binding) => name_binding,
864 match import.binding {
865 Some(binding) if !binding.defined_with(DefModifiers::PRELUDE) => {
866 let mut err = struct_span_err!(self.resolver.session,
869 "import `{}` conflicts with \
870 value in this module",
872 if let Some(span) = name_binding.span {
873 err.span_note(span, "conflicting value here");
880 match import.binding {
881 Some(binding) if !binding.defined_with(DefModifiers::PRELUDE) => {
882 if name_binding.is_extern_crate() {
883 let msg = format!("import `{0}` conflicts with imported crate \
884 in this module (maybe you meant `use {0}::*`?)",
886 span_err!(self.resolver.session, import_span, E0254, "{}", &msg[..]);
890 let (what, note) = match name_binding.module() {
891 Some(ref module) if module.is_normal() =>
892 ("existing submodule", "note conflicting module here"),
893 Some(ref module) if module.is_trait() =>
894 ("trait in this module", "note conflicting trait here"),
895 _ => ("type in this module", "note conflicting type here"),
897 let mut err = struct_span_err!(self.resolver.session,
900 "import `{}` conflicts with {}",
903 if let Some(span) = name_binding.span {
904 err.span_note(span, note);
914 fn import_path_to_string(names: &[Name], subclass: ImportDirectiveSubclass) -> String {
915 if names.is_empty() {
916 import_directive_subclass_to_string(subclass)
919 names_to_string(names),
920 import_directive_subclass_to_string(subclass)))
925 fn import_directive_subclass_to_string(subclass: ImportDirectiveSubclass) -> String {
927 SingleImport(_, source) => source.to_string(),
928 GlobImport => "*".to_string(),
932 pub fn resolve_imports(resolver: &mut Resolver) {
933 let mut import_resolver = ImportResolver { resolver: resolver };
934 import_resolver.resolve_imports();