Skip to content

Commit 9cd8d7a

Browse files
committed
Factor write_ty out of function checking functions
1 parent 2172064 commit 9cd8d7a

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/librustc_typeck/check/callee.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use CrateCtxt;
1515
use middle::cstore::LOCAL_CRATE;
1616
use hir::def::Def;
1717
use hir::def_id::DefId;
18-
use rustc::infer;
18+
use rustc::{infer, traits};
1919
use rustc::ty::{self, LvaluePreference, Ty};
2020
use syntax::parse::token;
2121
use syntax::ptr::P;
@@ -56,7 +56,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5656
let callee_ty = autoderef.unambiguous_final_ty();
5757
autoderef.finalize(LvaluePreference::NoPreference, Some(callee_expr));
5858

59-
match result {
59+
let output = match result {
6060
None => {
6161
// this will report an error since original_callee_ty is not a fn
6262
self.confirm_builtin_call(call_expr, original_callee_ty, arg_exprs, expected)
@@ -74,7 +74,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
7474
self.confirm_overloaded_call(call_expr, callee_expr,
7575
arg_exprs, expected, method_callee)
7676
}
77-
}
77+
};
78+
79+
// we must check that return type of called functions is WF:
80+
self.register_wf_obligation(output, call_expr.span, traits::MiscObligation);
81+
82+
output
7883
}
7984

8085
fn try_overloaded_call_step(&self,
@@ -244,7 +249,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
244249
fn_sig.variadic,
245250
TupleArgumentsFlag::DontTupleArguments);
246251

247-
self.write_ty(call_expr.id, fn_sig.output)
252+
fn_sig.output
248253
}
249254

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

274-
self.write_ty(call_expr.id, fn_sig.output)
279+
fn_sig.output
275280
}
276281

277282
fn confirm_overloaded_call(&self,
@@ -288,10 +293,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
288293
arg_exprs,
289294
TupleArgumentsFlag::TupleArguments,
290295
expected);
291-
let ty = self.write_ty(call_expr.id, output_type);
292296

293297
self.write_overloaded_call_method_map(call_expr, method_callee);
294-
ty
298+
output_type
295299
}
296300

297301
fn write_overloaded_call_method_map(&self,

src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
28472847
DontTupleArguments,
28482848
expected);
28492849

2850-
self.write_ty(expr.id, ret_ty)
2850+
ret_ty
28512851
}
28522852

28532853
// A generic function for checking the then and else in an if
@@ -3541,13 +3541,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
35413541
}
35423542
hir::ExprCall(ref callee, ref args) => {
35433543
let ret_ty = self.check_call(expr, &callee, &args[..], expected);
3544-
3545-
// we must check that return type of called functions is WF:
3546-
self.register_wf_obligation(ret_ty, expr.span, traits::MiscObligation);
3547-
ret_ty
3544+
self.write_ty(id, ret_ty)
35483545
}
35493546
hir::ExprMethodCall(name, ref tps, ref args) => {
3550-
self.check_method_call(expr, name, &args[..], &tps[..], expected, lvalue_pref)
3547+
let ret_ty = self.check_method_call(expr, name, &args[..], &tps[..], expected, lvalue_pref);
3548+
self.write_ty(id, ret_ty)
35513549
}
35523550
hir::ExprCast(ref e, ref t) => {
35533551
if let hir::TyFixedLengthVec(_, ref count_expr) = t.node {

0 commit comments

Comments
 (0)