@@ -773,7 +773,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
773
773
774
774
// First, check if we just need to wrap some arguments in a tuple.
775
775
if let Some ( ( mismatch_idx, terr) ) =
776
- compatibility_diagonal. iter ( ) . enumerate ( ) . find_map ( |( i, c) | {
776
+ compatibility_diagonal. iter_enumerated ( ) . find_map ( |( i, c) | {
777
777
if let Compatibility :: Incompatible ( Some ( terr) ) = c {
778
778
Some ( ( i, * terr) )
779
779
} else {
@@ -785,24 +785,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
785
785
// Do we have as many extra provided arguments as the tuple's length?
786
786
// If so, we might have just forgotten to wrap some args in a tuple.
787
787
if let Some ( ty:: Tuple ( tys) ) =
788
- formal_and_expected_inputs. get ( mismatch_idx. into ( ) ) . map ( |tys| tys. 1 . kind ( ) )
788
+ formal_and_expected_inputs. get ( mismatch_idx. to_expected_idx ( ) ) . map ( |tys| tys. 1 . kind ( ) )
789
789
// If the tuple is unit, we're not actually wrapping any arguments.
790
790
&& !tys. is_empty ( )
791
791
&& provided_arg_tys. len ( ) == formal_and_expected_inputs. len ( ) - 1 + tys. len ( )
792
792
{
793
793
// Wrap up the N provided arguments starting at this position in a tuple.
794
- let provided_as_tuple = Ty :: new_tup_from_iter (
795
- tcx,
796
- provided_arg_tys. iter ( ) . map ( |( ty, _) | * ty) . skip ( mismatch_idx) . take ( tys. len ( ) ) ,
797
- ) ;
794
+ let provided_args_to_tuple = & provided_arg_tys[ mismatch_idx..] . raw ;
795
+ let ( provided_args_to_tuple, provided_args_after_tuple) =
796
+ provided_arg_tys. split_at ( tys. len ( ) ) ;
797
+ let provided_as_tuple =
798
+ Ty :: new_tup_from_iter ( tcx, provided_args_to_tuple. iter ( ) . map ( |& ( ty, _) | ty) ) ;
798
799
799
800
let mut satisfied = true ;
800
801
// Check if the newly wrapped tuple + rest of the arguments are compatible.
801
802
for ( ( _, expected_ty) , provided_ty) in std:: iter:: zip (
802
- formal_and_expected_inputs. iter ( ) . skip ( mismatch_idx ) ,
803
- [ provided_as_tuple] . into_iter ( ) . chain (
804
- provided_arg_tys . iter ( ) . map ( | ( ty , _ ) | * ty ) . skip ( mismatch_idx + tys . len ( ) ) ,
805
- ) ,
803
+ formal_and_expected_inputs[ mismatch_idx . to_expected_idx ( ) .. ] . iter ( ) ,
804
+ [ provided_as_tuple]
805
+ . into_iter ( )
806
+ . chain ( provided_args_after_tuple . iter ( ) . map ( | & ( ty , _ ) | ty ) ) ,
806
807
) {
807
808
if !self . may_coerce ( provided_ty, * expected_ty) {
808
809
satisfied = false ;
@@ -814,10 +815,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
814
815
// Take some care with spans, so we don't suggest wrapping a macro's
815
816
// innards in parenthesis, for example.
816
817
if satisfied
817
- && let Some ( ( _, lo) ) =
818
- provided_arg_tys. get ( ProvidedIdx :: from_usize ( mismatch_idx) )
819
- && let Some ( ( _, hi) ) =
820
- provided_arg_tys. get ( ProvidedIdx :: from_usize ( mismatch_idx + tys. len ( ) - 1 ) )
818
+ && let Some ( ( _, lo) ) = provided_arg_tys. get ( mismatch_idx)
819
+ // Note: `provided_args_to_tuple` is not empty since `tys` is also not empty
820
+ && let Some ( & ( _, hi) ) = provided_args_to_tuple. last ( )
821
821
{
822
822
let mut err;
823
823
if tys. len ( ) == 1 {
@@ -826,8 +826,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
826
826
err = self . err_ctxt ( ) . report_and_explain_type_error (
827
827
mk_trace (
828
828
* lo,
829
- formal_and_expected_inputs[ mismatch_idx. into ( ) ] ,
830
- provided_arg_tys[ mismatch_idx. into ( ) ] . 0 ,
829
+ formal_and_expected_inputs[ mismatch_idx. to_expected_idx ( ) ] ,
830
+ provided_arg_tys[ mismatch_idx] . 0 ,
831
831
) ,
832
832
self . param_env ,
833
833
terr,
@@ -866,7 +866,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
866
866
callee_ty,
867
867
call_expr,
868
868
None ,
869
- Some ( mismatch_idx) ,
869
+ Some ( mismatch_idx. as_usize ( ) ) ,
870
870
& matched_inputs,
871
871
& formal_and_expected_inputs,
872
872
is_method,
@@ -2648,7 +2648,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2648
2648
}
2649
2649
2650
2650
let expected_display_type = self
2651
- . resolve_vars_if_possible ( formal_and_expected_inputs[ idx. into ( ) ] . 1 )
2651
+ . resolve_vars_if_possible ( formal_and_expected_inputs[ idx] . 1 )
2652
2652
. sort_string ( self . tcx ) ;
2653
2653
let label = if idxs_matched == params_with_generics. len ( ) - 1 {
2654
2654
format ! (
0 commit comments