about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-12-30 15:58:20 -0800
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-12-30 15:58:20 -0800
commit08d9c5be2f75bd034ca3e820fdad8e202b321307 (patch)
treee2d9133d406113e32ebaf4962f9ea46664202324 /src
parent4dde334b474e51154f22d4e497fd66d1b0abb6b3 (diff)
parent624421aa3d5d09fd59834c524f1909120685232d (diff)
Merge pull request #4312 from Dretch/issue-2914
Work towards fixing issue #2914
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/resolve.rs83
1 files changed, 35 insertions, 48 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index acaf668969c..ffb696ec4f9 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -2086,8 +2086,11 @@ impl Resolver {
             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.
@@ -2103,20 +2106,29 @@ impl Resolver {
     }
 
     fn idents_to_str(idents: ~[ident]) -> ~str {
-        // XXX: str::connect should do this.
-        let mut result = ~"";
-        let mut first = true;
-        for idents.each() |ident| {
-            if first {
-                first = false;
-            } else {
-                result += ~"::";
-            }
-            result += self.session.str_of(*ident);
-        }
-        // XXX: Shouldn't copy here. We need string builder functionality.
-        return result;
+        let ident_strs = idents.map(|&ident| self.session.str_of(ident));
+        return str::connect(ident_strs, "::");
     }
+
+    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
@@ -4501,17 +4513,14 @@ impl Resolver {
                         // Write the result into the def map.
                         debug!("(resolving type) writing resolution for `%s` \
                                 (id %d)",
-                               connect(path.idents.map(
-                                   |x| self.session.str_of(*x)), ~"::"),
+                               self.idents_to_str(path.idents),
                                path_id);
                         self.record_def(path_id, def);
                     }
                     None => {
                         self.session.span_err
                             (ty.span, fmt!("use of undeclared type name `%s`",
-                                           connect(path.idents.map(
-                                               |x| self.session.str_of(*x)),
-                                                   ~"::")));
+                                           self.idents_to_str(path.idents)));
                     }
                 }
             }
@@ -4705,9 +4714,7 @@ impl Resolver {
                             self.session.span_err(
                                 path.span,
                                 fmt!("`%s` does not name a structure",
-                                     connect(path.idents.map(
-                                         |x| self.session.str_of(*x)),
-                                             ~"::")));
+                                     self.idents_to_str(path.idents)));
                         }
                     }
                 }
@@ -5103,14 +5110,11 @@ impl Resolver {
                     Some(def) => {
                         // Write the result into the def map.
                         debug!("(resolving expr) resolved `%s`",
-                               connect(path.idents.map(
-                                   |x| self.session.str_of(*x)), ~"::"));
+                               self.idents_to_str(path.idents));
                         self.record_def(expr.id, def);
                     }
                     None => {
-                        let wrong_name =
-                            connect(path.idents.map(
-                                |x| self.session.str_of(*x)), ~"::") ;
+                        let wrong_name = self.idents_to_str(path.idents);
                         if self.name_exists_in_scope_struct(wrong_name) {
                             self.session.span_err(expr.span,
                                         fmt!("unresolved name: `%s`. \
@@ -5170,9 +5174,7 @@ impl Resolver {
                         self.session.span_err(
                             path.span,
                             fmt!("`%s` does not name a structure",
-                                 connect(path.idents.map(
-                                     |x| self.session.str_of(*x)),
-                                         ~"::")));
+                                 self.idents_to_str(path.idents)));
                     }
                 }
 
@@ -5491,7 +5493,7 @@ impl Resolver {
     // hit.
     //
 
-    /// A somewhat inefficient routine to print out the name of a module.
+    /// A somewhat inefficient routine to obtain the name of a module.
     fn module_to_str(module_: @Module) -> ~str {
         let idents = DVec();
         let mut current_module = module_;
@@ -5514,22 +5516,7 @@ impl Resolver {
         if idents.len() == 0 {
             return ~"???";
         }
-
-        let mut string = ~"";
-        let mut i = idents.len() - 1;
-        loop {
-            if i < idents.len() - 1 {
-                string += ~"::";
-            }
-            string += self.session.str_of(idents.get_elt(i));
-
-            if i == 0 {
-                break;
-            }
-            i -= 1;
-        }
-
-        return string;
+        return self.idents_to_str(vec::reversed(idents.get()));
     }
 
     fn dump_module(module_: @Module) {