Skip to content

Commit 58e35d7

Browse files
committed
Addressing nits & tests explanations.
1 parent f9f9f50 commit 58e35d7

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ impl ImportResolution {
184184
}
185185
}
186186

187+
struct ImportResolvingError {
188+
span: Span,
189+
path: String,
190+
help: String,
191+
}
187192

188193
struct ImportResolver<'a, 'b:'a, 'tcx:'b> {
189194
resolver: &'a mut Resolver<'b, 'tcx>
@@ -218,16 +223,16 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
218223
if self.resolver.unresolved_imports == prev_unresolved_imports {
219224
// resolving failed
220225
if errors.len() > 0 {
221-
for (span, path, help) in errors {
226+
for e in errors {
222227
resolve_error(self.resolver,
223-
span,
224-
ResolutionError::UnresolvedImport(Some((&*path, &*help))));
228+
e.span,
229+
ResolutionError::UnresolvedImport(Some((&e.path, &e.help))));
225230
}
226231
} else {
227-
// report unresolved imports only if no hard error was already reported
228-
// to avoid generating multiple errors on the same import
229-
// imports that are still undeterminate at this point are actually blocked
230-
// by errored imports, so there is no point reporting them
232+
// Report unresolved imports only if no hard error was already reported
233+
// to avoid generating multiple errors on the same import.
234+
// Imports that are still indeterminate at this point are actually blocked
235+
// by errored imports, so there is no point reporting them.
231236
self.resolver.report_unresolved_imports(module_root);
232237
}
233238
break;
@@ -241,7 +246,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
241246
/// Attempts to resolve imports for the given module and all of its
242247
/// submodules.
243248
fn resolve_imports_for_module_subtree(&mut self, module_: Rc<Module>)
244-
-> Vec<(Span, String, String)> {
249+
-> Vec<ImportResolvingError> {
245250
let mut errors = Vec::new();
246251
debug!("(resolving imports for module subtree) resolving {}",
247252
module_to_string(&*module_));
@@ -269,7 +274,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
269274
}
270275

271276
/// Attempts to resolve imports for the given module only.
272-
fn resolve_imports_for_module(&mut self, module: Rc<Module>) -> Vec<(Span, String, String)> {
277+
fn resolve_imports_for_module(&mut self, module: Rc<Module>) -> Vec<ImportResolvingError> {
273278
let mut errors = Vec::new();
274279

275280
if module.all_imports_resolved() {
@@ -292,12 +297,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
292297
Some((span, msg)) => (span, format!(". {}", msg)),
293298
None => (import_directive.span, String::new())
294299
};
295-
errors.push((span,
296-
import_path_to_string(
297-
&import_directive.module_path,
298-
import_directive.subclass
299-
),
300-
help))
300+
errors.push(ImportResolvingError {
301+
span: span,
302+
path: import_path_to_string(
303+
&import_directive.module_path,
304+
import_directive.subclass
305+
),
306+
help: help
307+
});
301308
}
302309
ResolveResult::Indeterminate => {}
303310
ResolveResult::Success(()) => {

src/test/run-pass/import-glob-1.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![allow(unused_imports, dead_code)]
11+
// This should resolve fine. Prior to fix, the last import
12+
// was being tried too early, and marked as unrsolved before
13+
// the glob import had a chance to be resolved.
1214

1315
mod bar {
1416
pub use self::middle::*;

src/test/run-pass/issue-18083.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// These crossed imports should resolve fine, and not block on
12+
// each other and be reported as unresolved.
13+
1114
mod a {
1215
use b::{B};
1316
pub use self::inner::A;

src/test/run-pass/issue-4865-1.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// This should resolve fine.
12+
// Prior to fix, the crossed imports between a and b
13+
// would block on the glob import, itself never being resolved
14+
// because these previous imports were not resolved.
15+
1116
pub mod a {
1217
use b::fn_b;
1318
use c::*;

0 commit comments

Comments
 (0)