]> git.lizzy.rs Git - rust.git/commitdiff
When an import fails to resolve, make the error message say
authorgareth <gareth@gareth-N56VM.(none)>
Thu, 27 Dec 2012 19:54:34 +0000 (19:54 +0000)
committergareth <gareth@gareth-N56VM.(none)>
Sat, 29 Dec 2012 11:15:54 +0000 (11:15 +0000)
which import it actually was. This makes debugging imports
like: use aa::{x, y, z} easier (for issue #2914).

src/librustc/middle/resolve.rs

index acaf668969c631c3f5197309eeed7b3c3fed588d..cdc41bc9da6ea128afed4c9ca4488806b998874e 100644 (file)
@@ -2086,8 +2086,11 @@ fn resolve_imports_for_module(module_: @Module) {
             match self.resolve_import_for_module(module_, import_directive) {
                 Failed => {
                     // We presumably emitted an error. Continue.
-                    self.session.span_err(import_directive.span,
-                                          ~"failed to resolve import");
+                    let idents = import_directive.module_path.get();
+                    let msg = fmt!("failed to resolve import: %s",
+                                   self.import_path_to_str(idents,
+                                   *import_directive.subclass));
+                    self.session.span_err(import_directive.span, msg);
                 }
                 Indeterminate => {
                     // Bail out. We'll come around next time.
@@ -2117,6 +2120,26 @@ fn idents_to_str(idents: ~[ident]) -> ~str {
         // XXX: Shouldn't copy here. We need string builder functionality.
         return result;
     }
+    
+    fn import_directive_subclass_to_str(subclass: ImportDirectiveSubclass)
+                                                                     -> ~str {
+        match subclass {
+            SingleImport(_target, source, _ns) => self.session.str_of(source),
+            GlobImport => ~"*"
+        }
+    }
+    
+    fn import_path_to_str(idents: ~[ident], subclass: ImportDirectiveSubclass)
+                                                                     -> ~str {
+        if idents.is_empty() {
+            self.import_directive_subclass_to_str(subclass)
+        } else {
+            fmt!("%s::%s",
+                 self.idents_to_str(idents),
+                 self.import_directive_subclass_to_str(subclass))
+        }
+    }
+    
     /**
      * Attempts to resolve the given import. The return value indicates
      * failure if we're certain the name does not exist, indeterminate if we