Skip to content

Commit 01cb104

Browse files
committed
update pprinter to understand ret type of block, add warnings
1 parent 6a90140 commit 01cb104

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/comp/middle/typeck.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,10 @@ fn check_expr_fn_with_unifier(fcx: @fn_ctxt,
15121512
let fty = ty_of_fn_decl(tcx, m_check_tyvar(fcx), decl,
15131513
proto, [], none).ty;
15141514

1515+
log #fmt("check_expr_fn_with_unifier %s fty=%s",
1516+
expr_to_str(expr),
1517+
ty_to_str(tcx, fty));
1518+
15151519
write::ty_only_fixup(fcx, expr.id, fty);
15161520

15171521
// Unify the type of the function with the expected type before we
@@ -1521,9 +1525,6 @@ fn check_expr_fn_with_unifier(fcx: @fn_ctxt,
15211525
unify(fcx, expr.span, expected, fty);
15221526

15231527
check_fn1(fcx.ccx, decl, proto, body, expr.id, some(fcx));
1524-
if proto == ast::proto_block {
1525-
write::ty_only_fixup(fcx, expr.id, expected);
1526-
}
15271528
}
15281529

15291530
fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
@@ -1979,11 +1980,20 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
19791980
// Take the prototype from the expected type, but default to block:
19801981
let proto = alt ty::struct(tcx, expected) {
19811982
ty::ty_fn(proto, _, _, _, _) { proto }
1982-
_ { ast::proto_block }
1983+
_ {
1984+
fcx.ccx.tcx.sess.span_warn(
1985+
expr.span,
1986+
"unable to infer kind of closure, defaulting to block");
1987+
ast::proto_block
1988+
}
19831989
};
1990+
log #fmt("checking expr_fn_block %s expected=%s",
1991+
expr_to_str(expr),
1992+
ty_to_str(tcx, expected));
19841993
check_expr_fn_with_unifier(fcx, expr, decl,
19851994
proto, body,
19861995
unify, expected);
1996+
write::ty_only_fixup(fcx, id, expected);
19871997
}
19881998
ast::expr_block(b) {
19891999
// If this is an unchecked block, turn off purity-checking

src/comp/syntax/print/pprust.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,11 @@ fn print_fn_block_args(s: ps, decl: ast::fn_decl) {
11611161
}
11621162
commasep(s, inconsistent, decl.inputs, print_arg);
11631163
word(s.s, "|");
1164+
if decl.output.node != ast::ty_infer {
1165+
space_if_not_bol(s);
1166+
word_space(s, "->");
1167+
print_type(s, decl.output);
1168+
}
11641169
maybe_print_comment(s, decl.output.span.lo);
11651170
}
11661171

0 commit comments

Comments
 (0)