Skip to content

Commit

Permalink
Factor write_ty out of function checking functions
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Sep 5, 2016
1 parent 2172064 commit 9cd8d7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/librustc_typeck/check/callee.rs
Expand Up @@ -15,7 +15,7 @@ use CrateCtxt;
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;
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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)
Expand All @@ -74,7 +74,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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,
Expand Down Expand Up @@ -244,7 +249,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn_sig.variadic,
TupleArgumentsFlag::DontTupleArguments);

self.write_ty(call_expr.id, fn_sig.output)
fn_sig.output
}

fn confirm_deferred_closure_call(&self,
Expand All @@ -271,7 +276,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn_sig.variadic,
TupleArgumentsFlag::TupleArguments);

self.write_ty(call_expr.id, fn_sig.output)
fn_sig.output
}

fn confirm_overloaded_call(&self,
Expand All @@ -288,10 +293,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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,
Expand Down
10 changes: 4 additions & 6 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -2847,7 +2847,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
DontTupleArguments,
expected);

self.write_ty(expr.id, ret_ty)
ret_ty
}

// A generic function for checking the then and else in an if
Expand Down Expand Up @@ -3541,13 +3541,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
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 {
Expand Down

0 comments on commit 9cd8d7a

Please sign in to comment.