diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 6b69dba49ae..924be466fae 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -2009,9 +2009,8 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (none) { auto nil = ty::mk_nil(scx.fcx.ccx.tcx); if (!are_compatible(scx, scx.fcx.ret_ty, nil)) { - // TODO: span_err - scx.fcx.ccx.tcx.sess.err("ret; in function " + - "returning non-nil"); + scx.fcx.ccx.tcx.sess.span_err(expr.span, + "ret; in function returning non-nil"); } write::bot_ty(scx.fcx.ccx.tcx, a.id); diff --git a/src/test/compile-fail/ret-non-nil.rs b/src/test/compile-fail/ret-non-nil.rs new file mode 100644 index 00000000000..9d1435fb15b --- /dev/null +++ b/src/test/compile-fail/ret-non-nil.rs @@ -0,0 +1,14 @@ +// error-pattern: ret; in function returning non-nil + +fn f() { + ret; +} + +fn g() -> int { + ret; +} + +fn main() { + f(); + g(); +}