Skip to content

Commit

Permalink
Make write_ty and friends return adjusted type
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Sep 5, 2016
1 parent 91f057d commit 0ddf060
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 146 deletions.
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -371,7 +371,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
discrim: &'gcx hir::Expr,
arms: &'gcx [hir::Arm],
expected: Expectation<'tcx>,
match_src: hir::MatchSource) {
match_src: hir::MatchSource) -> Ty<'tcx> {
let tcx = self.tcx;

// Not entirely obvious: if matches may create ref bindings, we
Expand Down Expand Up @@ -480,7 +480,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};
}

self.write_ty(expr.id, result_ty);
self.write_ty(expr.id, result_ty)
}
}

Expand Down
23 changes: 12 additions & 11 deletions src/librustc_typeck/check/callee.rs
Expand Up @@ -45,7 +45,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
call_expr: &'gcx hir::Expr,
callee_expr: &'gcx hir::Expr,
arg_exprs: &'gcx [P<hir::Expr>],
expected: Expectation<'tcx>)
expected: Expectation<'tcx>) -> Ty<'tcx>
{
self.check_expr(callee_expr);
let original_callee_ty = self.expr_ty(callee_expr);
Expand All @@ -60,20 +60,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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);
self.confirm_builtin_call(call_expr, original_callee_ty, arg_exprs, expected)
}

Some(CallStep::Builtin) => {
self.confirm_builtin_call(call_expr, callee_ty, arg_exprs, expected);
self.confirm_builtin_call(call_expr, callee_ty, arg_exprs, expected)
}

Some(CallStep::DeferredClosure(fn_sig)) => {
self.confirm_deferred_closure_call(call_expr, arg_exprs, expected, fn_sig);
self.confirm_deferred_closure_call(call_expr, arg_exprs, expected, fn_sig)
}

Some(CallStep::Overloaded(method_callee)) => {
self.confirm_overloaded_call(call_expr, callee_expr,
arg_exprs, expected, method_callee);
arg_exprs, expected, method_callee)
}
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
call_expr: &hir::Expr,
callee_ty: Ty<'tcx>,
arg_exprs: &'gcx [P<hir::Expr>],
expected: Expectation<'tcx>)
expected: Expectation<'tcx>) -> Ty<'tcx>
{
let error_fn_sig;

Expand Down Expand Up @@ -245,14 +245,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn_sig.variadic,
TupleArgumentsFlag::DontTupleArguments);

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

fn confirm_deferred_closure_call(&self,
call_expr: &hir::Expr,
arg_exprs: &'gcx [P<hir::Expr>],
expected: Expectation<'tcx>,
fn_sig: ty::FnSig<'tcx>)
fn_sig: ty::FnSig<'tcx>) -> Ty<'tcx>
{
// `fn_sig` is the *signature* of the cosure being called. We
// don't know the full details yet (`Fn` vs `FnMut` etc), but we
Expand All @@ -272,15 +272,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn_sig.variadic,
TupleArgumentsFlag::TupleArguments);

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

fn confirm_overloaded_call(&self,
call_expr: &hir::Expr,
callee_expr: &'gcx hir::Expr,
arg_exprs: &'gcx [P<hir::Expr>],
expected: Expectation<'tcx>,
method_callee: ty::MethodCallee<'tcx>)
method_callee: ty::MethodCallee<'tcx>) -> Ty<'tcx>
{
let output_type =
self.check_method_argument_types(call_expr.span,
Expand All @@ -289,9 +289,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
arg_exprs,
TupleArgumentsFlag::TupleArguments,
expected);
self.write_call(call_expr, output_type);
let ty = self.write_ty(call_expr.id, output_type);

self.write_overloaded_call_method_map(call_expr, method_callee);
ty
}

fn write_overloaded_call_method_map(&self,
Expand Down
8 changes: 5 additions & 3 deletions src/librustc_typeck/check/closure.rs
Expand Up @@ -24,7 +24,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
_capture: hir::CaptureClause,
decl: &'gcx hir::FnDecl,
body: &'gcx hir::Block,
expected: Expectation<'tcx>) {
expected: Expectation<'tcx>) -> Ty<'tcx> {
debug!("check_expr_closure(expr={:?},expected={:?})",
expr,
expected);
Expand All @@ -44,7 +44,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
opt_kind: Option<ty::ClosureKind>,
decl: &'gcx hir::FnDecl,
body: &'gcx hir::Block,
expected_sig: Option<ty::FnSig<'tcx>>) {
expected_sig: Option<ty::FnSig<'tcx>>) -> Ty<'tcx> {
let expr_def_id = self.tcx.map.local_def_id(expr.id);

debug!("check_closure opt_kind={:?} expected_sig={:?}",
Expand All @@ -70,7 +70,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.parameter_environment.free_substs,
upvar_tys);

self.write_ty(expr.id, closure_type);
let ty = self.write_ty(expr.id, closure_type);

let fn_sig = self.tcx.liberate_late_bound_regions(
self.tcx.region_maps.call_site_extent(expr.id, body.id), &fn_ty.sig);
Expand All @@ -93,6 +93,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(kind) => { self.tables.borrow_mut().closure_kinds.insert(expr_def_id, kind); }
None => { }
}

ty
}

fn deduce_expectations_from_expected_type(&self, expected_ty: Ty<'tcx>)
Expand Down

0 comments on commit 0ddf060

Please sign in to comment.