Addressing nits & tests explanations.

This commit is contained in:
Victor Berger 2015-08-04 08:14:32 +02:00
parent f9f9f509a0
commit 58e35d7c2a
4 changed files with 34 additions and 17 deletions

View File

@ -184,6 +184,11 @@ impl ImportResolution {
}
}
struct ImportResolvingError {
span: Span,
path: String,
help: String,
}
struct ImportResolver<'a, 'b:'a, 'tcx:'b> {
resolver: &'a mut Resolver<'b, 'tcx>
@ -218,16 +223,16 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
if self.resolver.unresolved_imports == prev_unresolved_imports {
// resolving failed
if errors.len() > 0 {
for (span, path, help) in errors {
for e in errors {
resolve_error(self.resolver,
span,
ResolutionError::UnresolvedImport(Some((&*path, &*help))));
e.span,
ResolutionError::UnresolvedImport(Some((&e.path, &e.help))));
}
} else {
// report unresolved imports only if no hard error was already reported
// to avoid generating multiple errors on the same import
// imports that are still undeterminate at this point are actually blocked
// by errored imports, so there is no point reporting them
// Report unresolved imports only if no hard error was already reported
// to avoid generating multiple errors on the same import.
// Imports that are still indeterminate at this point are actually blocked
// by errored imports, so there is no point reporting them.
self.resolver.report_unresolved_imports(module_root);
}
break;
@ -241,7 +246,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
/// Attempts to resolve imports for the given module and all of its
/// submodules.
fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>)
-> Vec<(Span, String, String)> {
-> Vec<ImportResolvingError> {
let mut errors = Vec::new();
debug!("(resolving imports for module subtree) resolving {}",
module_to_string(&*module_));
@ -269,7 +274,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
}
/// 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();
if module.all_imports_resolved() {
@ -292,12 +297,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
Some((span, msg)) => (span, format!(". {}", msg)),
None => (import_directive.span, String::new())
};
errors.push((span,
import_path_to_string(
&import_directive.module_path,
import_directive.subclass
),
help))
errors.push(ImportResolvingError {
span: span,
path: import_path_to_string(
&import_directive.module_path,
import_directive.subclass
),
help: help
});
}
ResolveResult::Indeterminate => {}
ResolveResult::Success(()) => {

View File

@ -1,4 +1,4 @@
// 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
// http://rust-lang.org/COPYRIGHT.
//
@ -8,7 +8,9 @@
// option. This file may not be copied, modified, or distributed
// 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 {
pub use self::middle::*;

View File

@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// These crossed imports should resolve fine, and not block on
// each other and be reported as unresolved.
mod a {
use b::{B};
pub use self::inner::A;

View File

@ -8,6 +8,11 @@
// option. This file may not be copied, modified, or distributed
// 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 {
use b::fn_b;
use c::*;