diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-08-18 03:39:48 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-08-18 08:09:24 +0000 |
| commit | cc079c3af2624066686c2941f65f07f3aa609d23 (patch) | |
| tree | 5bb716f19daac445a512f19028556bf988fdeda2 /src/librustc_resolve | |
| parent | 6cd43f6ee92fa3a235482fa28c5ac2c799018b8a (diff) | |
| download | rust-cc079c3af2624066686c2941f65f07f3aa609d23.tar.gz rust-cc079c3af2624066686c2941f65f07f3aa609d23.zip | |
Refactor away `ImportResolvingError`.
Diffstat (limited to 'src/librustc_resolve')
| -rw-r--r-- | src/librustc_resolve/resolve_imports.rs | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 04702d02555..bde175bcd6f 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -342,12 +342,6 @@ impl<'a> Resolver<'a> { } } -struct ImportResolvingError<'a> { - import_directive: &'a ImportDirective<'a>, - span: Span, - help: String, -} - struct ImportResolver<'a, 'b: 'a> { resolver: &'a mut Resolver<'b>, } @@ -416,34 +410,33 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { self.finalize_resolutions_in(module); } - let mut errors = Vec::new(); + let mut errors = false; for i in 0 .. self.determined_imports.len() { let import = self.determined_imports[i]; if let Failed(err) = self.finalize_import(import) { + errors = true; let (span, help) = match err { Some((span, msg)) => (span, format!(". {}", msg)), None => (import.span, String::new()), }; - errors.push(ImportResolvingError { - import_directive: import, - span: span, - help: help, - }); + + // If the error is a single failed import then create a "fake" import + // resolution for it so that later resolve stages won't complain. + self.import_dummy_binding(import); + let path = import_path_to_string(&import.module_path, &import.subclass); + let error = ResolutionError::UnresolvedImport(Some((&path, &help))); + resolve_error(self.resolver, span, error); } } // Report unresolved imports only if no hard error was already reported // to avoid generating multiple errors on the same import. - if errors.len() == 0 { + if !errors { if let Some(import) = self.indeterminate_imports.iter().next() { let error = ResolutionError::UnresolvedImport(None); resolve_error(self.resolver, import.span, error); } } - - for e in errors { - self.import_resolving_error(e) - } } // Define a "dummy" resolution containing a Def::Err as a placeholder for a @@ -462,19 +455,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { } } - /// Resolves an `ImportResolvingError` into the correct enum discriminant - /// and passes that on to `resolve_error`. - fn import_resolving_error(&mut self, e: ImportResolvingError<'b>) { - // If the error is a single failed import then create a "fake" import - // resolution for it so that later resolve stages won't complain. - self.import_dummy_binding(e.import_directive); - let path = import_path_to_string(&e.import_directive.module_path, - &e.import_directive.subclass); - resolve_error(self.resolver, - e.span, - ResolutionError::UnresolvedImport(Some((&path, &e.help)))); - } - /// Attempts to resolve the given import. The return value indicates /// failure if we're certain the name does not exist, indeterminate if we /// don't know whether the name exists at the moment due to other |
