Skip to content

Commit cc079c3

Browse files
committed
Refactor away ImportResolvingError.
1 parent 6cd43f6 commit cc079c3

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,6 @@ impl<'a> Resolver<'a> {
342342
}
343343
}
344344

345-
struct ImportResolvingError<'a> {
346-
import_directive: &'a ImportDirective<'a>,
347-
span: Span,
348-
help: String,
349-
}
350-
351345
struct ImportResolver<'a, 'b: 'a> {
352346
resolver: &'a mut Resolver<'b>,
353347
}
@@ -416,34 +410,33 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
416410
self.finalize_resolutions_in(module);
417411
}
418412

419-
let mut errors = Vec::new();
413+
let mut errors = false;
420414
for i in 0 .. self.determined_imports.len() {
421415
let import = self.determined_imports[i];
422416
if let Failed(err) = self.finalize_import(import) {
417+
errors = true;
423418
let (span, help) = match err {
424419
Some((span, msg)) => (span, format!(". {}", msg)),
425420
None => (import.span, String::new()),
426421
};
427-
errors.push(ImportResolvingError {
428-
import_directive: import,
429-
span: span,
430-
help: help,
431-
});
422+
423+
// If the error is a single failed import then create a "fake" import
424+
// resolution for it so that later resolve stages won't complain.
425+
self.import_dummy_binding(import);
426+
let path = import_path_to_string(&import.module_path, &import.subclass);
427+
let error = ResolutionError::UnresolvedImport(Some((&path, &help)));
428+
resolve_error(self.resolver, span, error);
432429
}
433430
}
434431

435432
// Report unresolved imports only if no hard error was already reported
436433
// to avoid generating multiple errors on the same import.
437-
if errors.len() == 0 {
434+
if !errors {
438435
if let Some(import) = self.indeterminate_imports.iter().next() {
439436
let error = ResolutionError::UnresolvedImport(None);
440437
resolve_error(self.resolver, import.span, error);
441438
}
442439
}
443-
444-
for e in errors {
445-
self.import_resolving_error(e)
446-
}
447440
}
448441

449442
// Define a "dummy" resolution containing a Def::Err as a placeholder for a
@@ -462,19 +455,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
462455
}
463456
}
464457

465-
/// Resolves an `ImportResolvingError` into the correct enum discriminant
466-
/// and passes that on to `resolve_error`.
467-
fn import_resolving_error(&mut self, e: ImportResolvingError<'b>) {
468-
// If the error is a single failed import then create a "fake" import
469-
// resolution for it so that later resolve stages won't complain.
470-
self.import_dummy_binding(e.import_directive);
471-
let path = import_path_to_string(&e.import_directive.module_path,
472-
&e.import_directive.subclass);
473-
resolve_error(self.resolver,
474-
e.span,
475-
ResolutionError::UnresolvedImport(Some((&path, &e.help))));
476-
}
477-
478458
/// Attempts to resolve the given import. The return value indicates
479459
/// failure if we're certain the name does not exist, indeterminate if we
480460
/// don't know whether the name exists at the moment due to other

0 commit comments

Comments
 (0)