about summary refs log tree commit diff
path: root/src/comp/middle
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2011-07-13 15:30:30 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2011-07-13 15:30:30 -0700
commit04b239f3cb9d4b62488dc2d219e9bd9a242bdf8f (patch)
treea947b3c65d71fc7aedba30b9ea3f230cae7d8d5d /src/comp/middle
parent6b86dcde676ad0640e4a35f33ef0e49429cdc9b7 (diff)
downloadrust-04b239f3cb9d4b62488dc2d219e9bd9a242bdf8f.tar.gz
rust-04b239f3cb9d4b62488dc2d219e9bd9a242bdf8f.zip
Use more precise spans in error messages for bad FRU exprs
The type error message for an expression using FRU where a field
expression had the wrong type was using the span for the entire
expression. Fixed it to use the span for the individual field.

Closes #628.
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/typeck.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 9a7cf357996..bfbd00b6cd7 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -4,6 +4,7 @@ import ast::mutability;
 import ast::local_def;
 import ast::path_to_str;
 import ast::respan;
+import ast::spanned;
 import syntax::walk;
 import metadata::csearch;
 import driver::session;
@@ -2177,16 +2178,21 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
                 case (none) {/* no-op */ }
                 case (some(?b_0)) { check_expr(fcx, b_0); }
             }
-            let field[] fields_t = ~[];
+            let (spanned[field])[] fields_t = ~[];
             for (ast::field f in fields) {
                 check_expr(fcx, f.node.expr);
                 auto expr_t = expr_ty(fcx.ccx.tcx, f.node.expr);
                 auto expr_mt = rec(ty=expr_t, mut=f.node.mut);
-                fields_t += ~[rec(ident=f.node.ident, mt=expr_mt)];
+                // for the most precise error message,
+                // should be f.node.expr.span, not f.span
+                fields_t += ~[respan(f.node.expr.span,
+                                     rec(ident=f.node.ident, mt=expr_mt))];
             }
             alt (base) {
                 case (none) {
-                    auto typ = ty::mk_rec(fcx.ccx.tcx, fields_t);
+                    fn get_node(&spanned[field] f) -> field { f.node }
+                    auto typ = ty::mk_rec(fcx.ccx.tcx, 
+                                          ivec::map(get_node, fields_t));
                     write::ty_only_fixup(fcx, id, typ);
                 }
                 case (some(?bexpr)) {
@@ -2202,20 +2208,20 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
                         }
                     }
                     write::ty_only_fixup(fcx, id, bexpr_t);
-                    for (ty::field f in fields_t) {
+                    for (spanned[ty::field] f in fields_t) {
                         auto found = false;
                         for (ty::field bf in base_fields) {
-                            if (str::eq(f.ident, bf.ident)) {
-                                demand::simple(fcx, expr.span, bf.mt.ty,
-                                               f.mt.ty);
+                            if (str::eq(f.node.ident, bf.ident)) {
+                                demand::simple(fcx, f.span, bf.mt.ty,
+                                               f.node.mt.ty);
                                 found = true;
                             }
                         }
                         if (!found) {
-                            fcx.ccx.tcx.sess.span_fatal(expr.span,
+                            fcx.ccx.tcx.sess.span_fatal(f.span,
                                                       "unknown field in \
                                                        record update: "
-                                                      + f.ident);
+                                                      + f.node.ident);
                         }
                     }
                 }