@@ -1294,6 +1294,26 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1294
1294
// The callee checks for bot / err, we don't need to
1295
1295
}
1296
1296
1297
+ fn write_call ( fcx : @mut FnCtxt ,
1298
+ call_expr : @ast:: expr ,
1299
+ output : ty:: t ,
1300
+ sugar : ast:: CallSugar ) {
1301
+ let ret_ty = match sugar {
1302
+ ast:: ForSugar => {
1303
+ match ty:: get ( output) . sty {
1304
+ ty:: ty_bool => { }
1305
+ _ => fcx. type_error_message ( call_expr. span , |actual| {
1306
+ fmt ! ( "expected `for` closure to return `bool`, \
1307
+ but found `%s`", actual) } ,
1308
+ output, None )
1309
+ }
1310
+ ty:: mk_nil ( )
1311
+ }
1312
+ _ => output
1313
+ } ;
1314
+ fcx. write_ty ( call_expr. id , ret_ty) ;
1315
+ }
1316
+
1297
1317
// A generic function for doing all of the checking for call expressions
1298
1318
fn check_call ( fcx : @mut FnCtxt ,
1299
1319
call_expr : @ast:: expr ,
@@ -1344,8 +1364,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1344
1364
check_argument_types ( fcx, call_expr. span , fn_sig. inputs , f,
1345
1365
args, sugar, DontDerefArgs ) ;
1346
1366
1347
- // Pull the return type out of the type of the function.
1348
- fcx. write_ty ( call_expr. id , fn_sig. output ) ;
1367
+ write_call ( fcx, call_expr, fn_sig. output , sugar) ;
1349
1368
}
1350
1369
1351
1370
// Checks a method call.
@@ -1401,8 +1420,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
1401
1420
fn_ty, expr, args, sugar,
1402
1421
DontDerefArgs ) ;
1403
1422
1404
- // Pull the return type out of the type of the function.
1405
- fcx. write_ty ( expr. id , ret_ty) ;
1423
+ write_call ( fcx, expr, ret_ty, sugar) ;
1406
1424
}
1407
1425
1408
1426
// A generic function for checking the then and else in an if
0 commit comments