@@ -315,13 +315,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
315
315
316
316
assert_eq ! ( expected_input_tys. len( ) , formal_input_tys. len( ) ) ;
317
317
318
+ let provided_arg_count: usize = provided_args. len ( ) ;
319
+
318
320
// Keep track of the fully coerced argument types
319
- let mut final_arg_types: Vec < ( usize , Ty < ' _ > , Ty < ' _ > ) > = vec ! [ ] ;
321
+ let mut final_arg_types: Vec < Option < ( Ty < ' _ > , Ty < ' _ > ) > > = vec ! [ None ; provided_arg_count ] ;
320
322
321
323
// We introduce a helper function to demand that a given argument satisfy a given input
322
324
// This is more complicated than just checking type equality, as arguments could be coerced
323
325
// This version writes those types back so further type checking uses the narrowed types
324
- let demand_compatible = |idx, final_arg_types : & mut Vec < ( usize , Ty < ' tcx > , Ty < ' tcx > ) > | {
326
+ let demand_compatible = |idx, final_arg_types : & mut Vec < Option < ( Ty < ' tcx > , Ty < ' tcx > ) > > | {
325
327
let formal_input_ty: Ty < ' tcx > = formal_input_tys[ idx] ;
326
328
let expected_input_ty: Ty < ' tcx > = expected_input_tys[ idx] ;
327
329
let provided_arg = & provided_args[ idx] ;
@@ -340,7 +342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
340
342
let coerced_ty = expectation. only_has_type ( self ) . unwrap_or ( formal_input_ty) ;
341
343
342
344
// Keep track of these for below
343
- final_arg_types. push ( ( idx, checked_ty, coerced_ty) ) ;
345
+ final_arg_types[ idx] = Some ( ( checked_ty, coerced_ty) ) ;
344
346
345
347
// Cause selection errors caused by resolving a single argument to point at the
346
348
// argument and not the call. This is otherwise redundant with the `demand_coerce`
@@ -975,7 +977,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
975
977
fn point_at_arg_instead_of_call_if_possible (
976
978
& self ,
977
979
errors : & mut Vec < traits:: FulfillmentError < ' tcx > > ,
978
- final_arg_types : & [ ( usize , Ty < ' tcx > , Ty < ' tcx > ) ] ,
980
+ final_arg_types : & [ Option < ( Ty < ' tcx > , Ty < ' tcx > ) > ] ,
979
981
expr : & ' tcx hir:: Expr < ' tcx > ,
980
982
call_sp : Span ,
981
983
args : & ' tcx [ hir:: Expr < ' tcx > ] ,
@@ -1030,8 +1032,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1030
1032
// `FulfillmentError`.
1031
1033
let mut referenced_in = final_arg_types
1032
1034
. iter ( )
1033
- . map ( |& ( i, checked_ty, _) | ( i, checked_ty) )
1034
- . chain ( final_arg_types. iter ( ) . map ( |& ( i, _, coerced_ty) | ( i, coerced_ty) ) )
1035
+ . enumerate ( )
1036
+ . filter_map ( |( i, arg) | match arg {
1037
+ Some ( ( checked_ty, coerce_ty) ) => Some ( [ ( i, * checked_ty) , ( i, * coerce_ty) ] ) ,
1038
+ _ => None ,
1039
+ } )
1040
+ . flatten ( )
1035
1041
. flat_map ( |( i, ty) | {
1036
1042
let ty = self . resolve_vars_if_possible ( ty) ;
1037
1043
// We walk the argument type because the argument's type could have
0 commit comments