Factor write_ty out of function checking functions

This commit is contained in:
Andrew Cann
2016-08-18 23:52:05 +08:00
parent 21720641dc
commit 9cd8d7a24f
2 changed files with 15 additions and 13 deletions
+11 -7
View File
@@ -15,7 +15,7 @@
use middle::cstore::LOCAL_CRATE;
use hir::def::Def;
use hir::def_id::DefId;
use rustc::infer;
use rustc::{infer, traits};
use rustc::ty::{self, LvaluePreference, Ty};
use syntax::parse::token;
use syntax::ptr::P;
@@ -56,7 +56,7 @@ pub fn check_call(&self,
let callee_ty = autoderef.unambiguous_final_ty();
autoderef.finalize(LvaluePreference::NoPreference, Some(callee_expr));
match result {
let output = match result {
None => {
// this will report an error since original_callee_ty is not a fn
self.confirm_builtin_call(call_expr, original_callee_ty, arg_exprs, expected)
@@ -74,7 +74,12 @@ pub fn check_call(&self,
self.confirm_overloaded_call(call_expr, callee_expr,
arg_exprs, expected, method_callee)
}
}
};
// we must check that return type of called functions is WF:
self.register_wf_obligation(output, call_expr.span, traits::MiscObligation);
output
}
fn try_overloaded_call_step(&self,
@@ -244,7 +249,7 @@ fn confirm_builtin_call(&self,
fn_sig.variadic,
TupleArgumentsFlag::DontTupleArguments);
self.write_ty(call_expr.id, fn_sig.output)
fn_sig.output
}
fn confirm_deferred_closure_call(&self,
@@ -271,7 +276,7 @@ fn confirm_deferred_closure_call(&self,
fn_sig.variadic,
TupleArgumentsFlag::TupleArguments);
self.write_ty(call_expr.id, fn_sig.output)
fn_sig.output
}
fn confirm_overloaded_call(&self,
@@ -288,10 +293,9 @@ fn confirm_overloaded_call(&self,
arg_exprs,
TupleArgumentsFlag::TupleArguments,
expected);
let ty = self.write_ty(call_expr.id, output_type);
self.write_overloaded_call_method_map(call_expr, method_callee);
ty
output_type
}
fn write_overloaded_call_method_map(&self,
+4 -6
View File
@@ -2847,7 +2847,7 @@ fn check_method_call(&self,
DontTupleArguments,
expected);
self.write_ty(expr.id, ret_ty)
ret_ty
}
// A generic function for checking the then and else in an if
@@ -3541,13 +3541,11 @@ fn check_expr_with_expectation_and_lvalue_pref(&self,
}
hir::ExprCall(ref callee, ref args) => {
let ret_ty = self.check_call(expr, &callee, &args[..], expected);
// we must check that return type of called functions is WF:
self.register_wf_obligation(ret_ty, expr.span, traits::MiscObligation);
ret_ty
self.write_ty(id, ret_ty)
}
hir::ExprMethodCall(name, ref tps, ref args) => {
self.check_method_call(expr, name, &args[..], &tps[..], expected, lvalue_pref)
let ret_ty = self.check_method_call(expr, name, &args[..], &tps[..], expected, lvalue_pref);
self.write_ty(id, ret_ty)
}
hir::ExprCast(ref e, ref t) => {
if let hir::TyFixedLengthVec(_, ref count_expr) = t.node {