about summary refs log tree commit diff
path: root/src/rustc
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-03-15 19:19:32 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-03-15 19:19:32 -0700
commite464e2ba56d4f995fca23350f4761787c78073f9 (patch)
tree1b0cd6daa2608d98404f895106a5589c2d77ce15 /src/rustc
parent4ea3b0b89cd24c6910b89410916118f7eb71a302 (diff)
downloadrust-e464e2ba56d4f995fca23350f4761787c78073f9.tar.gz
rust-e464e2ba56d4f995fca23350f4761787c78073f9.zip
rustc: Describe why regions failed to unify as part of the type error message
Diffstat (limited to 'src/rustc')
-rw-r--r--src/rustc/middle/ty.rs22
-rw-r--r--src/rustc/middle/typeck.rs6
-rw-r--r--src/rustc/util/ppaux.rs14
3 files changed, 26 insertions, 16 deletions
diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs
index 0e017f3f011..3518a4d1f0e 100644
--- a/src/rustc/middle/ty.rs
+++ b/src/rustc/middle/ty.rs
@@ -8,6 +8,7 @@ import syntax::ast_util;
 import syntax::codemap::span;
 import metadata::csearch;
 import util::common::*;
+import util::ppaux::region_to_str;
 import util::ppaux::ty_to_str;
 import util::ppaux::ty_constr_to_str;
 import syntax::print::pprust::*;
@@ -295,7 +296,7 @@ enum type_err {
     terr_mode_mismatch(mode, mode),
     terr_constr_len(uint, uint),
     terr_constr_mismatch(@type_constr, @type_constr),
-    terr_regions_differ,
+    terr_regions_differ(bool /* variance */, region, region),
 }
 
 enum param_bound {
@@ -1916,7 +1917,7 @@ mod unify {
               ret if e_region == a_region {
                   nxt(e_region)
               } else {
-                  err(terr_regions_differ)
+                  err(terr_regions_differ(true, e_region, a_region))
               };
             }
         }
@@ -1925,7 +1926,7 @@ mod unify {
             ret if sub == super {
                 nxt(super)
             } else {
-                err(terr_regions_differ)
+                err(terr_regions_differ(true, super, sub))
             };
         }
 
@@ -1936,7 +1937,7 @@ mod unify {
         if region::scope_contains(cx.tcx.region_map, subscope, superscope) {
             ret nxt(super);
         }
-        ret err(terr_regions_differ);
+        ret err(terr_regions_differ(false, sub, super));
     }
 
     fn unify_field<T:copy>(
@@ -2160,7 +2161,7 @@ fn same_type(cx: ctxt, a: t, b: t) -> bool {
     }
 }
 
-fn type_err_to_str(err: type_err) -> str {
+fn type_err_to_str(cx: ctxt, err: type_err) -> str {
     alt err {
       terr_mismatch { ret "types differ"; }
       terr_ret_style_mismatch(expect, actual) {
@@ -2212,8 +2213,15 @@ fn type_err_to_str(err: type_err) -> str {
                 " but found one with constraint " +
                 ty_constr_to_str(a_constr);
       }
-      terr_regions_differ {
-        ret "inconsistent pointer lifetimes"
+      terr_regions_differ(true, region_a, region_b) {
+        ret #fmt("reference lifetime %s does not match reference lifetime %s",
+                 region_to_str(cx, region_a), region_to_str(cx, region_b));
+      }
+      terr_regions_differ(false, subregion, superregion) {
+        ret #fmt("references with lifetime %s do not outlive references with \
+                  lifetime %s",
+                 region_to_str(cx, subregion),
+                 region_to_str(cx, superregion));
       }
     }
 }
diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs
index 3a26f01fe9e..e518704b1b3 100644
--- a/src/rustc/middle/typeck.rs
+++ b/src/rustc/middle/typeck.rs
@@ -767,7 +767,7 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
           result::err(err) {
             tcx.sess.span_err(sp, "method `" + if_m.ident +
                               "` has an incompatible type: " +
-                              ty::type_err_to_str(err));
+                              ty::type_err_to_str(tcx, err));
             impl_fty
           }
           result::ok(tp) { tp }
@@ -1154,7 +1154,9 @@ mod demand {
                                           ty_to_str(fcx.ccx.tcx, e_err) +
                                           "` but found `" +
                                           ty_to_str(fcx.ccx.tcx, a_err) +
-                                          "` (" + ty::type_err_to_str(err) +
+                                          "` (" +
+                                          ty::type_err_to_str(fcx.ccx.tcx,
+                                                              err) +
                                           ")");
             ret mk_result(fcx, expected, ty_param_subst_var_ids);
           }
diff --git a/src/rustc/util/ppaux.rs b/src/rustc/util/ppaux.rs
index d6411338e74..885ac9d7fbe 100644
--- a/src/rustc/util/ppaux.rs
+++ b/src/rustc/util/ppaux.rs
@@ -12,19 +12,19 @@ import driver::session::session;
 
 fn region_to_str(cx: ctxt, region: region) -> str {
     alt region {
-      re_named(_)   { "<name>."   }     // TODO: include name
-      re_caller(_)  { "<caller>." }
+      re_named(_)   { "<name>" }    // TODO: include name
+      re_caller(_)  { "<caller>" }
       re_block(node_id) {
         alt cx.items.get(node_id) {
             ast_map::node_block(blk) {
-                #fmt("<block at %s>.", codemap::span_to_str(blk.span,
-                                                            cx.sess.codemap))
+                #fmt("<block at %s>", codemap::span_to_str(blk.span,
+                                                           cx.sess.codemap))
             }
             _ { cx.sess.bug("re_block refers to non-block") }
         }
       }
-      re_self(_)    { "self."     }
-      re_inferred   { ""          }
+      re_self(_)    { "self" }
+      re_inferred   { "" }
     }
 }
 
@@ -121,7 +121,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
       ty_box(tm) { "@" + mt_to_str(cx, tm) }
       ty_uniq(tm) { "~" + mt_to_str(cx, tm) }
       ty_ptr(tm) { "*" + mt_to_str(cx, tm) }
-      ty_rptr(r, tm) { "&" + region_to_str(cx, r) + mt_to_str(cx, tm) }
+      ty_rptr(r, tm) { "&" + region_to_str(cx, r) + "." + mt_to_str(cx, tm) }
       ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }
       ty_type { "type" }
       ty_rec(elems) {