@@ -775,7 +775,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
775775
776776 // First, check if we just need to wrap some arguments in a tuple.
777777 if let Some ( ( mismatch_idx, terr) ) =
778- compatibility_diagonal. iter ( ) . enumerate ( ) . find_map ( |( i, c) | {
778+ compatibility_diagonal. iter_enumerated ( ) . find_map ( |( i, c) | {
779779 if let Compatibility :: Incompatible ( Some ( terr) ) = c {
780780 Some ( ( i, * terr) )
781781 } else {
@@ -787,24 +787,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
787787 // Do we have as many extra provided arguments as the tuple's length?
788788 // If so, we might have just forgotten to wrap some args in a tuple.
789789 if let Some ( ty:: Tuple ( tys) ) =
790- formal_and_expected_inputs. get ( mismatch_idx. into ( ) ) . map ( |tys| tys. 1 . kind ( ) )
790+ formal_and_expected_inputs. get ( mismatch_idx. to_expected_idx ( ) ) . map ( |tys| tys. 1 . kind ( ) )
791791 // If the tuple is unit, we're not actually wrapping any arguments.
792792 && !tys. is_empty ( )
793793 && provided_arg_tys. len ( ) == formal_and_expected_inputs. len ( ) - 1 + tys. len ( )
794794 {
795795 // Wrap up the N provided arguments starting at this position in a tuple.
796- let provided_as_tuple = Ty :: new_tup_from_iter (
797- tcx,
798- provided_arg_tys. iter ( ) . map ( |( ty, _) | * ty) . skip ( mismatch_idx) . take ( tys. len ( ) ) ,
799- ) ;
796+ let provided_args_to_tuple = & provided_arg_tys[ mismatch_idx..] ;
797+ let ( provided_args_to_tuple, provided_args_after_tuple) =
798+ provided_args_to_tuple. split_at ( tys. len ( ) ) ;
799+ let provided_as_tuple =
800+ Ty :: new_tup_from_iter ( tcx, provided_args_to_tuple. iter ( ) . map ( |& ( ty, _) | ty) ) ;
800801
801802 let mut satisfied = true ;
802803 // Check if the newly wrapped tuple + rest of the arguments are compatible.
803804 for ( ( _, expected_ty) , provided_ty) in std:: iter:: zip (
804- formal_and_expected_inputs. iter ( ) . skip ( mismatch_idx ) ,
805- [ provided_as_tuple] . into_iter ( ) . chain (
806- provided_arg_tys . iter ( ) . map ( | ( ty , _ ) | * ty ) . skip ( mismatch_idx + tys . len ( ) ) ,
807- ) ,
805+ formal_and_expected_inputs[ mismatch_idx . to_expected_idx ( ) .. ] . iter ( ) ,
806+ [ provided_as_tuple]
807+ . into_iter ( )
808+ . chain ( provided_args_after_tuple . iter ( ) . map ( | & ( ty , _ ) | ty ) ) ,
808809 ) {
809810 if !self . may_coerce ( provided_ty, * expected_ty) {
810811 satisfied = false ;
@@ -816,20 +817,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
816817 // Take some care with spans, so we don't suggest wrapping a macro's
817818 // innards in parenthesis, for example.
818819 if satisfied
819- && let Some ( ( _, lo) ) =
820- provided_arg_tys. get ( ProvidedIdx :: from_usize ( mismatch_idx) )
821- && let Some ( ( _, hi) ) =
822- provided_arg_tys. get ( ProvidedIdx :: from_usize ( mismatch_idx + tys. len ( ) - 1 ) )
820+ && let & [ ( _, hi @ lo) ] | & [ ( _, lo) , .., ( _, hi) ] = provided_args_to_tuple
823821 {
824822 let mut err;
825823 if tys. len ( ) == 1 {
826824 // A tuple wrap suggestion actually occurs within,
827825 // so don't do anything special here.
828826 err = self . err_ctxt ( ) . report_and_explain_type_error (
829827 mk_trace (
830- * lo,
831- formal_and_expected_inputs[ mismatch_idx. into ( ) ] ,
832- provided_arg_tys[ mismatch_idx. into ( ) ] . 0 ,
828+ lo,
829+ formal_and_expected_inputs[ mismatch_idx. to_expected_idx ( ) ] ,
830+ provided_arg_tys[ mismatch_idx] . 0 ,
833831 ) ,
834832 self . param_env ,
835833 terr,
@@ -868,7 +866,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
868866 callee_ty,
869867 call_expr,
870868 None ,
871- Some ( mismatch_idx) ,
869+ Some ( mismatch_idx. as_usize ( ) ) ,
872870 & matched_inputs,
873871 & formal_and_expected_inputs,
874872 is_method,
@@ -2615,7 +2613,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26152613 }
26162614
26172615 let expected_display_type = self
2618- . resolve_vars_if_possible ( formal_and_expected_inputs[ idx. into ( ) ] . 1 )
2616+ . resolve_vars_if_possible ( formal_and_expected_inputs[ idx] . 1 )
26192617 . sort_string ( self . tcx ) ;
26202618 let label = if idxs_matched == params_with_generics. len ( ) - 1 {
26212619 format ! (
0 commit comments