From: Jeffrey Seyfried Date: Thu, 18 Aug 2016 03:39:48 +0000 (+0000) Subject: Refactor away `ImportResolvingError`. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=cc079c3af2624066686c2941f65f07f3aa609d23;p=rust.git Refactor away `ImportResolvingError`. --- 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 @@ fn update_resolution(&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