Skip to content

Commit 6bb1e22

Browse files
committed
New WF condition requires checking that argument types are WF
on every call. This ensures that implies bounds are reasonable (the older code only checked that the values provided had WF types, but we also must know that the formal types of the arguments are WF.)
1 parent 8d98877 commit 6bb1e22

File tree

1 file changed

+16
-8
lines changed
  • src/librustc_typeck/check

1 file changed

+16
-8
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,12 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
24322432
1
24332433
};
24342434

2435+
// All the input types from the fn signature must outlive the call
2436+
// so as to validate implied bounds.
2437+
for &fn_input_ty in fn_inputs {
2438+
fcx.register_wf_obligation(fn_input_ty, sp, traits::MiscObligation);
2439+
}
2440+
24352441
let mut expected_arg_tys = expected_arg_tys;
24362442
let expected_arg_count = fn_inputs.len();
24372443
let formal_tys = if tuple_arguments == TupleArguments {
@@ -3541,16 +3547,18 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
35413547
}
35423548
ast::ExprCall(ref callee, ref args) => {
35433549
callee::check_call(fcx, expr, &**callee, &args[..], expected);
3550+
3551+
// we must check that return type of called functions is WF:
3552+
let ret_ty = fcx.expr_ty(expr);
3553+
fcx.register_wf_obligation(ret_ty, expr.span, traits::MiscObligation);
35443554
}
35453555
ast::ExprMethodCall(ident, ref tps, ref args) => {
3546-
check_method_call(fcx, expr, ident, &args[..], &tps[..], expected, lvalue_pref);
3547-
let arg_tys = args.iter().map(|a| fcx.expr_ty(&**a));
3548-
let args_err = arg_tys.fold(false,
3549-
|rest_err, a| {
3550-
rest_err || a.references_error()});
3551-
if args_err {
3552-
fcx.write_error(id);
3553-
}
3556+
check_method_call(fcx, expr, ident, &args[..], &tps[..], expected, lvalue_pref);
3557+
let arg_tys = args.iter().map(|a| fcx.expr_ty(&**a));
3558+
let args_err = arg_tys.fold(false, |rest_err, a| rest_err || a.references_error());
3559+
if args_err {
3560+
fcx.write_error(id);
3561+
}
35543562
}
35553563
ast::ExprCast(ref e, ref t) => {
35563564
if let ast::TyFixedLengthVec(_, ref count_expr) = t.node {

0 commit comments

Comments
 (0)