提交 58e35d7c 编写于 作者: V Victor Berger

Addressing nits & tests explanations.

上级 f9f9f509
...@@ -184,6 +184,11 @@ pub fn set_target_and_id(&mut self, ...@@ -184,6 +184,11 @@ pub fn set_target_and_id(&mut self,
} }
} }
struct ImportResolvingError {
span: Span,
path: String,
help: String,
}
struct ImportResolver<'a, 'b:'a, 'tcx:'b> { struct ImportResolver<'a, 'b:'a, 'tcx:'b> {
resolver: &'a mut Resolver<'b, 'tcx> resolver: &'a mut Resolver<'b, 'tcx>
...@@ -218,16 +223,16 @@ fn resolve_imports(&mut self) { ...@@ -218,16 +223,16 @@ fn resolve_imports(&mut self) {
if self.resolver.unresolved_imports == prev_unresolved_imports { if self.resolver.unresolved_imports == prev_unresolved_imports {
// resolving failed // resolving failed
if errors.len() > 0 { if errors.len() > 0 {
for (span, path, help) in errors { for e in errors {
resolve_error(self.resolver, resolve_error(self.resolver,
span, e.span,
ResolutionError::UnresolvedImport(Some((&*path, &*help)))); ResolutionError::UnresolvedImport(Some((&e.path, &e.help))));
} }
} else { } else {
// report unresolved imports only if no hard error was already reported // Report unresolved imports only if no hard error was already reported
// to avoid generating multiple errors on the same import // to avoid generating multiple errors on the same import.
// imports that are still undeterminate at this point are actually blocked // Imports that are still indeterminate at this point are actually blocked
// by errored imports, so there is no point reporting them // by errored imports, so there is no point reporting them.
self.resolver.report_unresolved_imports(module_root); self.resolver.report_unresolved_imports(module_root);
} }
break; break;
...@@ -241,7 +246,7 @@ fn resolve_imports(&mut self) { ...@@ -241,7 +246,7 @@ fn resolve_imports(&mut self) {
/// Attempts to resolve imports for the given module and all of its /// Attempts to resolve imports for the given module and all of its
/// submodules. /// submodules.
fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>) fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>)
-> Vec<(Span, String, String)> { -> Vec<ImportResolvingError> {
let mut errors = Vec::new(); let mut errors = Vec::new();
debug!("(resolving imports for module subtree) resolving {}", debug!("(resolving imports for module subtree) resolving {}",
module_to_string(&*module_)); module_to_string(&*module_));
...@@ -269,7 +274,7 @@ fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>) ...@@ -269,7 +274,7 @@ fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>)
} }
/// Attempts to resolve imports for the given module only. /// Attempts to resolve imports for the given module only.
fn resolve_imports_for_module(&mut self, module: Rc<Module>) -> Vec<(Span, String, String)> { fn resolve_imports_for_module(&mut self, module: Rc<Module>) -> Vec<ImportResolvingError> {
let mut errors = Vec::new(); let mut errors = Vec::new();
if module.all_imports_resolved() { if module.all_imports_resolved() {
...@@ -292,12 +297,14 @@ fn resolve_imports_for_module(&mut self, module: Rc<Module>) -> Vec<(Span, Strin ...@@ -292,12 +297,14 @@ fn resolve_imports_for_module(&mut self, module: Rc<Module>) -> Vec<(Span, Strin
Some((span, msg)) => (span, format!(". {}", msg)), Some((span, msg)) => (span, format!(". {}", msg)),
None => (import_directive.span, String::new()) None => (import_directive.span, String::new())
}; };
errors.push((span, errors.push(ImportResolvingError {
import_path_to_string( span: span,
&import_directive.module_path, path: import_path_to_string(
import_directive.subclass &import_directive.module_path,
), import_directive.subclass
help)) ),
help: help
});
} }
ResolveResult::Indeterminate => {} ResolveResult::Indeterminate => {}
ResolveResult::Success(()) => { ResolveResult::Success(()) => {
......
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at // file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT. // http://rust-lang.org/COPYRIGHT.
// //
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unused_imports, dead_code)] // This should resolve fine. Prior to fix, the last import
// was being tried too early, and marked as unrsolved before
// the glob import had a chance to be resolved.
mod bar { mod bar {
pub use self::middle::*; pub use self::middle::*;
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// These crossed imports should resolve fine, and not block on
// each other and be reported as unresolved.
mod a { mod a {
use b::{B}; use b::{B};
pub use self::inner::A; pub use self::inner::A;
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// This should resolve fine.
// Prior to fix, the crossed imports between a and b
// would block on the glob import, itself never being resolved
// because these previous imports were not resolved.
pub mod a { pub mod a {
use b::fn_b; use b::fn_b;
use c::*; use c::*;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册