Skip to content

Commit c9c1d86

Browse files
committed
rustc: Report type errors in terms of the actual types involved, not type variables
1 parent 5318248 commit c9c1d86

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/comp/middle/typeck.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,14 @@ fn count_boxes(&@fn_ctxt fcx, &span sp, &ty::t t) -> uint {
896896
}
897897

898898

899+
fn resolve_type_vars_if_possible(&@fn_ctxt fcx, ty::t typ) -> ty::t {
900+
alt (ty::unify::fixup_vars(fcx.ccx.tcx, fcx.var_bindings, typ)) {
901+
case (fix_ok(?new_type)) { ret new_type; }
902+
case (fix_err(_)) { ret typ; }
903+
}
904+
}
905+
906+
899907
// Demands - procedures that require that two types unify and emit an error
900908
// message if they don't.
901909

@@ -956,10 +964,13 @@ mod demand {
956964
}
957965

958966
case (ures_err(?err)) {
967+
auto e_err = resolve_type_vars_if_possible(fcx, expected_1);
968+
auto a_err = resolve_type_vars_if_possible(fcx, actual_1);
969+
959970
fcx.ccx.tcx.sess.span_err
960971
(sp, "mismatched types: expected "
961-
+ ty_to_str(fcx.ccx.tcx, expected_1) + " but found "
962-
+ ty_to_str(fcx.ccx.tcx, actual_1) + " ("
972+
+ ty_to_str(fcx.ccx.tcx, e_err) + " but found "
973+
+ ty_to_str(fcx.ccx.tcx, a_err) + " ("
963974
+ ty::type_err_to_str(err) + ")");
964975

965976
// TODO: In the future, try returning "expected", reporting

0 commit comments

Comments
 (0)