Skip to content

Commit cc2b8a4

Browse files
committed
---
yaml --- r: 56685 b: refs/heads/try c: 1745a2c h: refs/heads/master i: 56683: 82eacf2 v: v3
1 parent 71c885f commit cc2b8a4

File tree

6 files changed

+87
-936
lines changed

6 files changed

+87
-936
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: c6949b3669d23a1694b964108f21d5200c985cb5
5+
refs/heads/try: 1745a2cd08d1aa7437ec3d080c9ca85434b54cf5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/middle/typeck/check/mod.rs

Lines changed: 86 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,9 +1122,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
11221122
unifier: &fn()) {
11231123
debug!(">> typechecking %s", fcx.expr_to_str(expr));
11241124

1125-
// A generic function to factor out common logic from call and
1126-
// overloaded operations
1127-
fn check_call_inner(
1125+
fn check_argument_types(
11281126
fcx: @mut FnCtxt,
11291127
sp: span,
11301128
call_expr_id: ast::node_id,
@@ -1134,18 +1132,24 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
11341132
sugar: ast::CallSugar,
11351133
deref_args: DerefArgs) -> ty::t
11361134
{
1135+
/*!
1136+
*
1137+
* Generic function that factors out common logic from
1138+
* function calls, method calls and overloaded operators.
1139+
*/
1140+
11371141
let tcx = fcx.ccx.tcx;
11381142

11391143
// Replace all region parameters in the arguments and return
11401144
// type with fresh region variables.
11411145

1142-
debug!("check_call_inner: before universal quant., in_fty=%s",
1146+
debug!("check_argument_types: before universal quant., in_fty=%s",
11431147
fcx.infcx().ty_to_str(in_fty));
11441148

1145-
let formal_tys;
1149+
let sty = structure_of(fcx, sp, in_fty);
11461150

11471151
// FIXME(#3678) For now, do not permit calls to C abi functions.
1148-
match structure_of(fcx, sp, in_fty) {
1152+
match sty {
11491153
ty::ty_bare_fn(ty::BareFnTy {abis, _}) => {
11501154
if !abis.is_rust() {
11511155
tcx.sess.span_err(
@@ -1157,68 +1161,65 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
11571161
_ => {}
11581162
}
11591163

1160-
// This is subtle: we expect `fty` to be a function type, which
1161-
// normally introduce a level of binding. In this case, we want to
1162-
// process the types bound by the function but not by any nested
1163-
// functions. Therefore, we match one level of structure.
1164-
let ret_ty = match structure_of(fcx, sp, in_fty) {
1165-
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) |
1166-
ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => {
1167-
let (_, _, sig) =
1168-
replace_bound_regions_in_fn_sig(
1169-
tcx, @Nil, None, sig,
1170-
|_br| fcx.infcx().next_region_var(
1171-
sp, call_expr_id));
1172-
1173-
let supplied_arg_count = args.len();
1174-
1175-
// Grab the argument types, supplying fresh type variables
1176-
// if the wrong number of arguments were supplied
1177-
let expected_arg_count = sig.inputs.len();
1178-
formal_tys = if expected_arg_count == supplied_arg_count {
1179-
sig.inputs.map(|a| a.ty)
1180-
} else {
1181-
let suffix = match sugar {
1182-
ast::NoSugar => "",
1183-
ast::DoSugar => " (including the closure passed by \
1184-
the `do` keyword)",
1185-
ast::ForSugar => " (including the closure passed by \
1186-
the `for` keyword)"
1187-
};
1188-
let msg = fmt!("this function takes %u parameter%s but \
1189-
%u parameter%s supplied%s",
1190-
expected_arg_count,
1191-
if expected_arg_count == 1 {""}
1192-
else {"s"},
1193-
supplied_arg_count,
1194-
if supplied_arg_count == 1 {" was"}
1195-
else {"s were"},
1196-
suffix);
1197-
1198-
tcx.sess.span_err(sp, msg);
1199-
1200-
vec::from_fn(supplied_arg_count, |_| ty::mk_err(tcx))
1201-
};
1202-
1203-
sig.output
1204-
}
1205-
1164+
// Extract the function signature from `in_fty`.
1165+
let sig = match sty {
1166+
ty::ty_bare_fn(ty::BareFnTy {sig: sig, _}) |
1167+
ty::ty_closure(ty::ClosureTy {sig: sig, _}) => sig,
12061168
_ => {
12071169
fcx.type_error_message(sp, |actual| {
1208-
fmt!("expected function or foreign function but \
1170+
fmt!("expected function but \
12091171
found `%s`", actual) }, in_fty, None);
12101172

12111173
// check each arg against "error", in order to set up
12121174
// all the node type bindings
1213-
formal_tys = args.map(|_x| ty::mk_err(tcx));
1214-
ty::mk_err(tcx)
1175+
FnSig {bound_lifetime_names: opt_vec::Empty,
1176+
inputs: args.map(|_x| ty::arg {mode: ast::expl(ast::by_copy),
1177+
ty: ty::mk_err(tcx)}),
1178+
output: ty::mk_err(tcx)}
12151179
}
12161180
};
12171181

1218-
debug!("check_call_inner: after universal quant., \
1219-
formal_tys=%? ret_ty=%s",
1182+
// Replace any bound regions that appear in the function
1183+
// signature with region variables
1184+
let (_, _, sig) =
1185+
replace_bound_regions_in_fn_sig(
1186+
tcx, @Nil, None, &sig,
1187+
|_br| fcx.infcx().next_region_var(
1188+
sp, call_expr_id));
1189+
1190+
// Grab the argument types, supplying fresh type variables
1191+
// if the wrong number of arguments were supplied
1192+
let supplied_arg_count = args.len();
1193+
let expected_arg_count = sig.inputs.len();
1194+
let formal_tys = if expected_arg_count == supplied_arg_count {
1195+
sig.inputs.map(|a| a.ty)
1196+
} else {
1197+
let suffix = match sugar {
1198+
ast::NoSugar => "",
1199+
ast::DoSugar => " (including the closure passed by \
1200+
the `do` keyword)",
1201+
ast::ForSugar => " (including the closure passed by \
1202+
the `for` keyword)"
1203+
};
1204+
let msg = fmt!("this function takes %u parameter%s but \
1205+
%u parameter%s supplied%s",
1206+
expected_arg_count,
1207+
if expected_arg_count == 1 {""}
1208+
else {"s"},
1209+
supplied_arg_count,
1210+
if supplied_arg_count == 1 {" was"}
1211+
else {"s were"},
1212+
suffix);
1213+
1214+
tcx.sess.span_err(sp, msg);
1215+
1216+
vec::from_elem(supplied_arg_count, ty::mk_err(tcx))
1217+
};
1218+
1219+
debug!("check_argument_types: after universal quant., \
1220+
formal_tys=%? sig.output=%s",
12201221
formal_tys.map(|t| fcx.infcx().ty_to_str(*t)),
1221-
fcx.infcx().ty_to_str(ret_ty));
1222+
fcx.infcx().ty_to_str(sig.output));
12221223

12231224
// Check the arguments.
12241225
// We do this in a pretty awful way: first we typecheck any arguments
@@ -1269,7 +1270,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
12691270
}
12701271
}
12711272

1272-
ret_ty
1273+
sig.output
12731274
}
12741275

12751276
// A generic function for checking assignment expressions
@@ -1284,43 +1285,23 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
12841285
// The callee checks for bot / err, we don't need to
12851286
}
12861287

1287-
// A generic function for doing all of the checking for call or
1288-
// method expressions
1289-
fn check_call_or_method(fcx: @mut FnCtxt,
1290-
sp: span,
1291-
call_expr_id: ast::node_id,
1292-
fn_ty: ty::t,
1293-
expr: @ast::expr,
1294-
args: &[@ast::expr],
1295-
sugar: ast::CallSugar)
1296-
{
1297-
1298-
// Call the generic checker.
1299-
let ret_ty = check_call_inner(fcx, sp, call_expr_id,
1300-
fn_ty, expr, args, sugar,
1301-
DontDerefArgs);
1302-
// Pull the return type out of the type of the function.
1303-
fcx.write_ty(call_expr_id, ret_ty);
1304-
// Callee checks for bot and err, no need for that
1305-
}
1306-
13071288
// A generic function for doing all of the checking for call expressions
13081289
fn check_call(fcx: @mut FnCtxt,
1309-
sp: span,
1310-
call_expr_id: ast::node_id,
1290+
call_expr: @ast::expr,
13111291
f: @ast::expr,
13121292
args: &[@ast::expr],
13131293
sugar: ast::CallSugar) {
13141294
// Index expressions need to be handled separately, to inform them
13151295
// that they appear in call position.
1316-
let mut _bot = check_expr(fcx, f);
1317-
check_call_or_method(fcx,
1318-
sp,
1319-
call_expr_id,
1320-
fcx.expr_ty(f),
1321-
f,
1322-
args,
1323-
sugar)
1296+
check_expr(fcx, f);
1297+
1298+
// Call the generic checker.
1299+
let ret_ty = check_argument_types(fcx, call_expr.span, call_expr.id,
1300+
fcx.expr_ty(f), f, args, sugar,
1301+
DontDerefArgs);
1302+
1303+
// Pull the return type out of the type of the function.
1304+
fcx.write_ty(call_expr.id, ret_ty);
13241305
}
13251306

13261307
// Checks a method call.
@@ -1369,13 +1350,14 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
13691350
}
13701351
}
13711352

1372-
check_call_or_method(fcx,
1373-
expr.span,
1374-
expr.id,
1375-
fcx.node_ty(expr.callee_id),
1376-
expr,
1377-
args,
1378-
sugar)
1353+
// Call the generic checker.
1354+
let fn_ty = fcx.node_ty(expr.callee_id);
1355+
let ret_ty = check_argument_types(fcx, expr.span, expr.id,
1356+
fn_ty, expr, args, sugar,
1357+
DontDerefArgs);
1358+
1359+
// Pull the return type out of the type of the function.
1360+
fcx.write_ty(expr.id, ret_ty);
13791361
}
13801362

13811363
// A generic function for checking the then and else in an if
@@ -1423,20 +1405,20 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
14231405
let method_ty = fcx.node_ty(op_ex.callee_id);
14241406
let method_map = fcx.inh.method_map;
14251407
method_map.insert(op_ex.id, *origin);
1426-
check_call_inner(fcx, op_ex.span,
1427-
op_ex.id, method_ty,
1428-
op_ex, args,
1429-
ast::NoSugar, deref_args)
1408+
check_argument_types(fcx, op_ex.span,
1409+
op_ex.id, method_ty,
1410+
op_ex, args,
1411+
ast::NoSugar, deref_args)
14301412
}
14311413
_ => {
14321414
let tcx = fcx.tcx();
14331415
unbound_method();
14341416
// Check the args anyway
14351417
// so we get all the error messages
14361418
let expected_ty = ty::mk_err(tcx);
1437-
check_call_inner(fcx, op_ex.span, op_ex.id,
1438-
expected_ty, op_ex, args,
1439-
ast::NoSugar, deref_args);
1419+
check_argument_types(fcx, op_ex.span, op_ex.id,
1420+
expected_ty, op_ex, args,
1421+
ast::NoSugar, deref_args);
14401422
ty::mk_err(tcx)
14411423
}
14421424
}
@@ -2546,7 +2528,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
25462528
fcx.write_ty(id, fcx.node_ty(b.node.id));
25472529
}
25482530
ast::expr_call(f, ref args, sugar) => {
2549-
check_call(fcx, expr.span, expr.id, f, *args, sugar);
2531+
check_call(fcx, expr, f, *args, sugar);
25502532
let f_ty = fcx.expr_ty(f);
25512533
let (args_bot, args_err) = args.foldl((false, false),
25522534
|&(rest_bot, rest_err), a| {

0 commit comments

Comments
 (0)