From 13801f60b26009991cd6880b6b40fae9265a8280 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 4 Apr 2013 17:14:59 -0400 Subject: [PATCH] rustc: Be careful about calls to fn types that contain nested errors --- src/librustc/middle/typeck/check/mod.rs | 33 +++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 957259e7d172a..c3ec2d14d83d0 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1135,22 +1135,23 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, sugar: ast::CallSugar, deref_args: DerefArgs) -> ty::t { - match ty::get(method_fn_ty).sty { - ty::ty_bare_fn(ref fty) => { - check_argument_types(fcx, sp, fty.sig.inputs, callee_expr, - args, sugar, deref_args); - fty.sig.output - } - ty::ty_err => { - let err_inputs = err_args(fcx.tcx(), args.len()); - check_argument_types(fcx, sp, err_inputs, callee_expr, - args, sugar, deref_args); - method_fn_ty - } - _ => { - fcx.tcx().sess.span_bug( - sp, - fmt!("Method without bare fn type")); + if ty::type_is_error(method_fn_ty) { + let err_inputs = err_args(fcx.tcx(), args.len()); + check_argument_types(fcx, sp, err_inputs, callee_expr, + args, sugar, deref_args); + method_fn_ty + } else { + match ty::get(method_fn_ty).sty { + ty::ty_bare_fn(ref fty) => { + check_argument_types(fcx, sp, fty.sig.inputs, callee_expr, + args, sugar, deref_args); + fty.sig.output + } + _ => { + fcx.tcx().sess.span_bug( + sp, + fmt!("Method without bare fn type")); + } } } }