about summary refs log tree commit diff
path: root/src/comp/util
diff options
context:
space:
mode:
authorMichael Sullivan <sully@msully.net>2011-08-18 17:59:17 -0700
committerMichael Sullivan <sully@msully.net>2011-08-18 18:13:18 -0700
commitf8ac788d66fbf045a7dc1417d05ddf31671fa090 (patch)
treef701f9a42c29daf9c32b512ca369d5880ffa3a20 /src/comp/util
parent4a894dae8ec784480cc7d8b127a79f9418e8fa7d (diff)
downloadrust-f8ac788d66fbf045a7dc1417d05ddf31671fa090.tar.gz
rust-f8ac788d66fbf045a7dc1417d05ddf31671fa090.zip
Print tag names in type error messages. Closes #834.
Diffstat (limited to 'src/comp/util')
-rw-r--r--src/comp/util/ppaux.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs
index 33556b8f1d1..76df85015ef 100644
--- a/src/comp/util/ppaux.rs
+++ b/src/comp/util/ppaux.rs
@@ -18,6 +18,8 @@ import pp::zerobreak;
 import pp::hardbreak;
 import ast::ty_mach_to_str;
 import syntax::ast;
+import middle::ast_map;
+import metadata::csearch;
 
 fn mode_str(m: &ty::mode) -> str {
     alt m {
@@ -35,6 +37,17 @@ fn fn_ident_to_string(id: ast::node_id, i: &ast::fn_ident) -> str {
     ret alt i { none. { "anon" + int::str(id) } some(s) { s } };
 }
 
+fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str {
+    if (id.crate != ast::local_crate) {
+        str::connect(cx.ext_map.get(id), "::")
+    } else {
+        alt cx.items.find(id.node) {
+          some(ast_map::node_item(it)) { it.ident }
+          _ { fail "get_id_ident: can't find item in ast_map" }
+        }
+    }
+}
+
 fn ty_to_str(cx: &ctxt, typ: &t) -> str {
     fn fn_input_to_str(cx: &ctxt, input: &{mode: middle::ty::mode, ty: t}) ->
        str {
@@ -105,9 +118,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
         s += "(" + str::connect(strs, ",") + ")";
       }
       ty_tag(id, tps) {
-        // The user should never see this if the cname is set properly!
-
-        s += "<tag#" + int::str(id.crate) + ":" + int::str(id.node) + ">";
+        s += get_id_ident(cx, id);
         if vec::len::<t>(tps) > 0u {
             let strs: [str] = ~[];
             for typ: t in tps { strs += ~[ty_to_str(cx, typ)]; }
@@ -128,8 +139,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
         s += "obj {\n\t" + str::connect(strs, "\n\t") + "\n}";
       }
       ty_res(id, _, _) {
-        s +=
-            "<resource#" + int::str(id.node) + ":" + int::str(id.crate) + ">";
+        s += get_id_ident(cx, id);
       }
       ty_var(v) { s += "<T" + int::str(v) + ">"; }
       ty_param(id,_) {