From 734166f41c3c5ba48498df0133383a451e7fdb3e Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 20 Apr 2012 18:47:01 -0700 Subject: [PATCH] Print out return type correctly in typestate error message In the "not all paths return" error message, typestate was printing the AST type from the fn decl, not the ty::t type. This ended in tears when the AST return type was "ty_infer". Now it looks up the function node ID's type and uses util::ppaux::ty_to_str instead. Closes #2163. --- src/rustc/middle/tstate/ck.rs | 14 ++++++++------ src/test/compile-fail/issue-2163.rs | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 src/test/compile-fail/issue-2163.rs diff --git a/src/rustc/middle/tstate/ck.rs b/src/rustc/middle/tstate/ck.rs index c04d9ad1e75..a8c06cd322a 100644 --- a/src/rustc/middle/tstate/ck.rs +++ b/src/rustc/middle/tstate/ck.rs @@ -7,7 +7,8 @@ import middle::ty; import tstate::ann::{precond, prestate, implies, ann_precond, ann_prestate}; import aux::*; -import syntax::print::pprust::ty_to_str; + +import util::ppaux::ty_to_str; import bitvectors::*; import annotate::annotate_crate; import collect_locals::mk_f_to_fn_info; @@ -116,13 +117,14 @@ fn check_states_against_conditions(fcx: fn_ctxt, !ty::type_is_nil(ty::ty_fn_ret(ty::node_id_to_type( fcx.ccx.tcx, id))) && f_decl.cf == return_val { + let fn_ty = ty::node_id_to_type(fcx.ccx.tcx, id); fcx.ccx.tcx.sess.span_err(f_body.span, - "in function " + fcx.name + - ", not all control paths \ - return a value"); + #fmt("in function `%s`, not all control paths \ + return a value", fcx.name)); fcx.ccx.tcx.sess.span_fatal(f_decl.output.span, - "see declared return type of '" + - ty_to_str(f_decl.output) + "'"); + #fmt("see function return type of `%s`", + ty_to_str(fcx.ccx.tcx, + ty::ty_fn_ret(fn_ty)))); } else if f_decl.cf == noreturn { // check that this really always fails diff --git a/src/test/compile-fail/issue-2163.rs b/src/test/compile-fail/issue-2163.rs new file mode 100644 index 00000000000..89437289ebc --- /dev/null +++ b/src/test/compile-fail/issue-2163.rs @@ -0,0 +1,5 @@ +fn main(s: [str]) { + let a = []; + vec::each(a) { |x| //! ERROR in function `anon`, not all control paths + } //! ERROR see function return type of `bool` +}