Skip to content

Commit 1254209

Browse files
committed
---
yaml --- r: 5267 b: refs/heads/master c: 51dae63 h: refs/heads/master i: 5265: 92eeeed 5263: 18d9e65 v: v3
1 parent d796fe4 commit 1254209

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c1c083cd66dd2a6dd46dac3e68210227a67331ab
2+
refs/heads/master: 51dae63c44f7d82886436c9e90a3e26aa591d9af

trunk/src/comp/metadata/tyencode.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ fn enc_ty_fn(w: io::writer, cx: @ctxt, args: [ty::arg], out: ty::t,
218218
} else { w.write_char(';'); }
219219
enc_constr(w, cx, c);
220220
}
221-
alt cf { noreturn. { w.write_char('!'); } _ { enc_ty(w, cx, out); } }
221+
alt cf {
222+
noreturn. { w.write_char('!'); }
223+
_ { enc_ty(w, cx, out); }
224+
}
222225
}
223226

224227
// FIXME less copy-and-paste

trunk/src/comp/middle/ty.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ type constr = constr_general<uint>;
279279
// Data structures used in type unification
280280
tag type_err {
281281
terr_mismatch;
282-
terr_controlflow_mismatch;
282+
terr_ret_style_mismatch(ast::ret_style, ast::ret_style);
283283
terr_box_mutability;
284284
terr_vec_mutability;
285285
terr_tuple_size(uint, uint);
@@ -1952,26 +1952,13 @@ mod unify {
19521952
_expected_constrs: [@constr], actual_constrs: [@constr]) ->
19531953
result {
19541954
if e_proto != a_proto { ret ures_err(terr_mismatch); }
1955-
alt expected_cf {
1956-
ast::return_val. { }
1957-
// ok
1958-
ast::noreturn. {
1959-
alt actual_cf {
1960-
ast::noreturn. {
1961-
// ok
1962-
1963-
}
1964-
_ {
1965-
/* even though typestate checking is mostly
1966-
responsible for checking control flow annotations,
1967-
this check is necessary to ensure that the
1968-
annotation in an object method matches the
1969-
declared object type */
1970-
1971-
ret ures_err(terr_controlflow_mismatch);
1972-
}
1973-
}
1974-
}
1955+
if actual_cf != ast::noreturn && actual_cf != expected_cf {
1956+
/* even though typestate checking is mostly
1957+
responsible for checking control flow annotations,
1958+
this check is necessary to ensure that the
1959+
annotation in an object method matches the
1960+
declared object type */
1961+
ret ures_err(terr_ret_style_mismatch(expected_cf, actual_cf));
19751962
}
19761963
let t =
19771964
unify_fn_common(cx, expected, actual, expected_inputs,
@@ -2470,9 +2457,16 @@ mod unify {
24702457
fn type_err_to_str(err: ty::type_err) -> str {
24712458
alt err {
24722459
terr_mismatch. { ret "types differ"; }
2473-
terr_controlflow_mismatch. {
2474-
ret "returning function used where non-returning function" +
2475-
" was expected";
2460+
terr_ret_style_mismatch(expect, actual) {
2461+
fn to_str(s: ast::ret_style) -> str {
2462+
alt s {
2463+
ast::noreturn. { "non-returning" }
2464+
ast::return_val. { "return-by-value" }
2465+
ast::return_ref. { "return-by-reference" }
2466+
}
2467+
}
2468+
ret to_str(actual) + " function found where " + to_str(expect) +
2469+
" function was expected";
24762470
}
24772471
terr_box_mutability. { ret "boxed values differ in mutability"; }
24782472
terr_vec_mutability. { ret "vectors differ in mutability"; }

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,7 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl, constrs: [@ast::constr]) {
12241224
if decl.output.node != ast::ty_nil {
12251225
space_if_not_bol(s);
12261226
word_space(s, "->");
1227+
if decl.cf == ast::return_ref { word(s.s, "&"); }
12271228
print_type(s, decl.output);
12281229
}
12291230
}
@@ -1419,9 +1420,11 @@ fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
14191420
space_if_not_bol(s);
14201421
ibox(s, indent_unit);
14211422
word_space(s, "->");
1422-
alt cf {
1423-
ast::return_val. { print_type(s, output); }
1424-
ast::noreturn. { word_nbsp(s, "!"); }
1423+
if cf == ast::noreturn {
1424+
word_nbsp(s, "!")
1425+
} else {
1426+
if cf == ast::return_ref { word(s.s, "&"); }
1427+
print_type(s, output);
14251428
}
14261429
end(s);
14271430
}

trunk/src/comp/util/ppaux.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
5858
s += str::connect(strs, ", ");
5959
s += ")";
6060
if struct(cx, output) != ty_nil {
61-
alt cf {
62-
ast::noreturn. { s += " -> !"; }
63-
ast::return_val. { s += " -> " + ty_to_str(cx, output); }
61+
s += " -> ";
62+
if cf == ast::noreturn {
63+
s += "!";
64+
} else {
65+
if cf == ast::return_ref { s += "&"; }
66+
s += ty_to_str(cx, output);
6467
}
6568
}
6669
s += constrs_str(constrs);

0 commit comments

Comments
 (0)