]> git.lizzy.rs Git - rust.git/commitdiff
Refactor away `ImportResolvingError`.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 18 Aug 2016 03:39:48 +0000 (03:39 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 18 Aug 2016 08:09:24 +0000 (08:09 +0000)
src/librustc_resolve/resolve_imports.rs

index 04702d02555e1daec11fc70bfa830674cf22a2ef..bde175bcd6f196add9f24acbc20637995e56baa4 100644 (file)
@@ -342,12 +342,6 @@ fn update_resolution<T, F>(&mut self, module: Module<'a>, name: Name, ns: Namesp
     }
 }
 
-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 @@ fn resolve_imports(&mut self) {
             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 @@ fn import_dummy_binding(&mut self, directive: &'b ImportDirective<'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