Skip to content

Commit 16f5850

Browse files
committed
---
yaml --- r: 15345 b: refs/heads/try c: 2c56ba7 h: refs/heads/master i: 15343: 577314b v: v3
1 parent d9f82bd commit 16f5850

File tree

12 files changed

+106
-46
lines changed

12 files changed

+106
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: ce8023b9aca841e965228cf9dc4ba5cb27c9457c
5+
refs/heads/try: 2c56ba7e4338b8c6c99c8f16cc96939ebd03f735
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/middle/infer.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl unify_methods for infer_ctxt {
493493
if b == r {
494494
self.uok()
495495
} else {
496-
err(ty::terr_regions_differ(false, b, a))
496+
err(ty::terr_regions_differ(b, a))
497497
}
498498
}
499499
}
@@ -521,21 +521,23 @@ impl unify_methods for infer_ctxt {
521521
}
522522
}
523523

524-
/* mk_subty passes the "smaller" type as the first argument
525-
and the "bigger" type as the second -- so the first arg
526-
is the actual type, and the second is the expected type */
527-
fn flds(a: ty::field, e: ty::field) -> ures {
528-
if e.ident != a.ident {
529-
ret self.uerr(ty::terr_record_fields(e.ident, a.ident));
524+
fn flds(a: ty::field, b: ty::field) -> ures {
525+
if b.ident != a.ident {
526+
// Note: the error object expects the "expected" field to
527+
// come first, which is generally the supertype (b).
528+
ret self.uerr(ty::terr_record_fields(b.ident, a.ident));
529+
}
530+
531+
self.mts(a.mt, b.mt).chain_err {|err|
532+
self.uerr(ty::terr_in_field(@err, a.ident))
530533
}
531-
self.mts(a.mt, e.mt)
532534
}
533535

534536
fn tps(as: [ty::t], bs: [ty::t]) -> ures {
535537
if check vec::same_length(as, bs) {
536538
iter2(as, bs) {|a, b| self.tys(a, b) }
537539
} else {
538-
self.uerr(ty::terr_ty_param_size(as.len(), bs.len()))
540+
self.uerr(ty::terr_ty_param_size(bs.len(), as.len()))
539541
}
540542
}
541543

@@ -544,7 +546,7 @@ impl unify_methods for infer_ctxt {
544546
(_, ast::proto_any) { self.uok() }
545547
(ast::proto_bare, _) { self.uok() }
546548
(_, _) if a == b { self.uok() }
547-
_ { self.uerr(ty::terr_proto_mismatch(a, b)) }
549+
_ { self.uerr(ty::terr_proto_mismatch(b, a)) }
548550
}
549551
}
550552

@@ -558,7 +560,7 @@ impl unify_methods for infer_ctxt {
558560
this check is necessary to ensure that the
559561
annotation in an object method matches the
560562
declared object type */
561-
self.uerr(ty::terr_ret_style_mismatch(a_ret_style, b_ret_style))
563+
self.uerr(ty::terr_ret_style_mismatch(b_ret_style, a_ret_style))
562564
} else {
563565
self.uok()
564566
}
@@ -672,7 +674,7 @@ impl unify_methods for infer_ctxt {
672674
self.constrs(a, b)
673675
}
674676
} else {
675-
self.uerr(ty::terr_constr_len(as.len(), bs.len()))
677+
self.uerr(ty::terr_constr_len(bs.len(), as.len()))
676678
}
677679
}
678680

@@ -713,7 +715,7 @@ impl unify_methods for infer_ctxt {
713715
if ty::mach_sty(cfg, a) == ty::mach_sty(cfg, b) {
714716
self.uok()
715717
} else {
716-
self.uerr(ty::terr_mismatch)
718+
self.uerr(ty::terr_sorts(b, a))
717719
}
718720
}
719721

@@ -757,16 +759,16 @@ impl unify_methods for infer_ctxt {
757759
self.flds(a, b)
758760
}
759761
} else {
760-
ret self.uerr(ty::terr_record_size(a_fields.len(),
761-
b_fields.len()));
762+
ret self.uerr(ty::terr_record_size(b_fields.len(),
763+
a_fields.len()));
762764
}
763765
}
764766

765767
(ty::ty_tup(a_tys), ty::ty_tup(b_tys)) {
766768
if check vec::same_length(a_tys, b_tys) {
767769
iter2(a_tys, b_tys) {|a,b| self.tys(a,b) }
768770
} else {
769-
self.uerr(ty::terr_tuple_size(a_tys.len(), b_tys.len()))
771+
self.uerr(ty::terr_tuple_size(b_tys.len(), a_tys.len()))
770772
}
771773
}
772774

@@ -780,7 +782,7 @@ impl unify_methods for infer_ctxt {
780782
}
781783
}
782784

783-
_ { self.uerr(ty::terr_mismatch) }
785+
_ { self.uerr(ty::terr_sorts(b, a)) }
784786
}
785787
}
786788
}
@@ -1066,7 +1068,7 @@ fn c_tuptys<C:combine>(self: C, as: [ty::t], bs: [ty::t])
10661068
if check vec::same_length(as, bs) {
10671069
map2(as, bs) {|a, b| self.c_tys(a, b) }
10681070
} else {
1069-
err(ty::terr_tuple_size(as.len(), bs.len()))
1071+
err(ty::terr_tuple_size(bs.len(), as.len()))
10701072
}
10711073
}
10721074

@@ -1077,7 +1079,7 @@ fn c_tps<C:combine>(self: C, _did: ast::def_id, as: [ty::t], bs: [ty::t])
10771079
if check vec::same_length(as, bs) {
10781080
map2(as, bs) {|a,b| self.c_tys(a, b) }
10791081
} else {
1080-
err(ty::terr_ty_param_size(as.len(), bs.len()))
1082+
err(ty::terr_ty_param_size(bs.len(), as.len()))
10811083
}
10821084
}
10831085

@@ -1087,17 +1089,17 @@ fn c_fieldvecs<C:combine>(self: C, as: [ty::field], bs: [ty::field])
10871089
if check vec::same_length(as, bs) {
10881090
map2(as, bs) {|a,b| c_flds(self, a, b) }
10891091
} else {
1090-
err(ty::terr_record_size(as.len(), bs.len()))
1092+
err(ty::terr_record_size(bs.len(), as.len()))
10911093
}
10921094
}
10931095

1094-
fn c_flds<C:combine>(self: C, e: ty::field, a: ty::field) -> cres<ty::field> {
1095-
if e.ident == a.ident {
1096-
self.c_mts(e.mt, a.mt).chain {|mt|
1097-
ok({ident: e.ident, mt: mt})
1096+
fn c_flds<C:combine>(self: C, a: ty::field, b: ty::field) -> cres<ty::field> {
1097+
if a.ident == b.ident {
1098+
self.c_mts(a.mt, b.mt).chain {|mt|
1099+
ok({ident: a.ident, mt: mt})
10981100
}
10991101
} else {
1100-
err(ty::terr_record_fields(e.ident, a.ident))
1102+
err(ty::terr_record_fields(b.ident, a.ident))
11011103
}
11021104
}
11031105

@@ -1196,7 +1198,7 @@ fn c_tys<C:combine>(
11961198
if ty::mach_sty(cfg, a) == ty::mach_sty(cfg, b) {
11971199
ok(a)
11981200
} else {
1199-
err(ty::terr_mismatch)
1201+
err(ty::terr_sorts(b, a))
12001202
}
12011203
}
12021204

@@ -1293,7 +1295,7 @@ fn c_tys<C:combine>(
12931295
}
12941296
}
12951297

1296-
_ { err(ty::terr_mismatch) }
1298+
_ { err(ty::terr_sorts(b, a)) }
12971299
}
12981300
}
12991301
}
@@ -1350,14 +1352,14 @@ fn c_regions<C:combine>(
13501352
#debug["... no, %s != %s.",
13511353
a.to_str(self.infcx()),
13521354
b.to_str(self.infcx())];
1353-
err(ty::terr_regions_differ(false, b, a))
1355+
err(ty::terr_regions_differ(b, a))
13541356
}
13551357
}
13561358

13571359
(ty::re_default, _) |
13581360
(_, ty::re_default) {
13591361
// actually a compiler bug, I think.
1360-
err(ty::terr_regions_differ(false, b, a))
1362+
err(ty::terr_regions_differ(b, a))
13611363
}
13621364
}
13631365
}
@@ -1480,7 +1482,7 @@ impl of combine for lub {
14801482
let rm = self.infcx().tcx.region_map;
14811483
alt region::nearest_common_ancestor(rm, a_id, b_id) {
14821484
some(r_id) { ok(ty::re_scope(r_id)) }
1483-
_ { err(ty::terr_regions_differ(false, b, a)) }
1485+
_ { err(ty::terr_regions_differ(b, a)) }
14841486
}
14851487
}
14861488
}
@@ -1623,7 +1625,7 @@ impl of combine for glb {
16231625
alt region::nearest_common_ancestor(rm, a_id, b_id) {
16241626
some(r_id) if a_id == r_id { ok(b) }
16251627
some(r_id) if b_id == r_id { ok(a) }
1626-
_ { err(ty::terr_regions_differ(false, b, a)) }
1628+
_ { err(ty::terr_regions_differ(b, a)) }
16271629
}
16281630
}
16291631
}

branches/try/src/rustc/middle/ty.rs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ enum type_err {
341341
terr_mode_mismatch(mode, mode),
342342
terr_constr_len(uint, uint),
343343
terr_constr_mismatch(@type_constr, @type_constr),
344-
terr_regions_differ(bool /* variance */, region, region),
344+
terr_regions_differ(region, region),
345+
terr_in_field(@type_err, str),
346+
terr_sorts(t, t)
345347
}
346348

347349
enum param_bound {
@@ -1837,6 +1839,33 @@ fn set_default_mode(cx: ctxt, m: ast::mode, m_def: ast::rmode) {
18371839
}
18381840
}
18391841

1842+
fn ty_sort_str(cx: ctxt, t: t) -> str {
1843+
alt get(t).struct {
1844+
ty_nil | ty_bot | ty_bool | ty_int(_) |
1845+
ty_uint(_) | ty_float(_) | ty_str | ty_type | ty_opaque_box |
1846+
ty_opaque_closure_ptr(_) {
1847+
ty_to_str(cx, t)
1848+
}
1849+
1850+
ty_enum(_, _) { "enum" }
1851+
ty_box(_) { "@-ptr" }
1852+
ty_uniq(_) { "~-ptr" }
1853+
ty_vec(_) { "vector" }
1854+
ty_ptr(_) { "*-ptr" }
1855+
ty_rptr(_, _) { "&-ptr" }
1856+
ty_rec(_) { "record" }
1857+
ty_fn(_) { "fn" }
1858+
ty_iface(_, _) { "iface" }
1859+
ty_class(_, _) { "class" }
1860+
ty_res(_, _, _) { "resource" }
1861+
ty_tup(_) { "tuple" }
1862+
ty_var(_) { "variable" }
1863+
ty_param(_, _) { "type parameter" }
1864+
ty_self(_) { "self" }
1865+
ty_constr(t, _) { ty_sort_str(cx, t) }
1866+
}
1867+
}
1868+
18401869
fn type_err_to_str(cx: ctxt, err: type_err) -> str {
18411870
alt err {
18421871
terr_mismatch { ret "types differ"; }
@@ -1876,8 +1905,8 @@ fn type_err_to_str(cx: ctxt, err: type_err) -> str {
18761905
}
18771906
terr_record_mutability { ret "record elements differ in mutability"; }
18781907
terr_record_fields(e_fld, a_fld) {
1879-
ret "expected a record with field '" + e_fld +
1880-
"' but found one with field '" + a_fld + "'";
1908+
ret "expected a record with field `" + e_fld +
1909+
"` but found one with field `" + a_fld + "`";
18811910
}
18821911
terr_arg_count { ret "incorrect number of function parameters"; }
18831912
terr_mode_mismatch(e_mode, a_mode) {
@@ -1894,16 +1923,18 @@ fn type_err_to_str(cx: ctxt, err: type_err) -> str {
18941923
" but found one with constraint " +
18951924
ty_constr_to_str(a_constr);
18961925
}
1897-
terr_regions_differ(true, region_a, region_b) {
1898-
ret #fmt("reference lifetime %s does not match reference lifetime %s",
1899-
region_to_str(cx, region_a), region_to_str(cx, region_b));
1900-
}
1901-
terr_regions_differ(false, subregion, superregion) {
1926+
terr_regions_differ(subregion, superregion) {
19021927
ret #fmt("references with lifetime %s do not outlive references with \
19031928
lifetime %s",
19041929
region_to_str(cx, subregion),
19051930
region_to_str(cx, superregion));
19061931
}
1932+
terr_in_field(err, fname) {
1933+
ret #fmt("in field `%s`, %s", fname, type_err_to_str(cx, *err));
1934+
}
1935+
terr_sorts(exp, act) {
1936+
ret #fmt("%s vs %s", ty_sort_str(cx, exp), ty_sort_str(cx, act));
1937+
}
19071938
}
19081939
}
19091940

branches/try/src/test/compile-fail/bad-bang-ann-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
fn bad_bang(i: uint) -> ! {
55
ret 7u;
6-
//!^ ERROR expected `_|_` but found `uint` (types differ)
6+
//!^ ERROR expected `_|_` but found `uint`
77
}
88

99
fn main() { bad_bang(5u); }

branches/try/src/test/compile-fail/bad-bang-ann.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
fn bad_bang(i: uint) -> ! {
55
if i < 0u { } else { fail; }
6-
//!^ ERROR expected `_|_` but found `()` (types differ)
6+
//!^ ERROR expected `_|_` but found `()`
77
}
88

99
fn main() { bad_bang(5u); }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn f() -> ! {
2-
3 //! ERROR expected `_|_` but found `int` (types differ)
2+
3 //! ERROR expected `_|_` but found `int`
33
}
44
fn main() { }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn g() -> ! { fail; }
22
fn f() -> ! {
3-
ret 42; //! ERROR expected `_|_` but found `int` (types differ)
3+
ret 42; //! ERROR expected `_|_` but found `int`
44
g(); //! WARNING unreachable statement
55
}
66
fn main() { }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn f() -> ! {
2-
ret 42; //! ERROR expected `_|_` but found `int` (types differ)
2+
ret 42; //! ERROR expected `_|_` but found `int`
33
fail; //! WARNING unreachable statement
44
}
55
fn main() { }

branches/try/src/test/compile-fail/loop-does-not-diverge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn forever() -> ! {
44
loop {
55
break;
66
}
7-
ret 42; //! ERROR expected `_|_` but found `int` (types differ)
7+
ret 42; //! ERROR expected `_|_` but found `int`
88
}
99

1010
fn main() {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type foo = {a: int};
2+
type bar = {b: int};
3+
4+
fn want_foo(f: foo) {}
5+
fn have_bar(b: bar) {
6+
want_foo(b); //! ERROR expected a record with field `a`
7+
}
8+
9+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type foo = {a: int, b: int};
2+
type bar = {a: int, b: uint};
3+
4+
fn want_foo(f: foo) {}
5+
fn have_bar(b: bar) {
6+
want_foo(b); //! ERROR (in field `b`, int vs uint)
7+
}
8+
9+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type foo = {a: int, b: int};
2+
type bar = @foo;
3+
4+
fn want_foo(f: foo) {}
5+
fn have_bar(b: bar) {
6+
want_foo(b); //! ERROR (record vs @-ptr)
7+
}
8+
9+
fn main() {}

0 commit comments

Comments
 (0)