@@ -775,7 +775,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
775
775
776
776
// First, check if we just need to wrap some arguments in a tuple.
777
777
if let Some ( ( mismatch_idx, terr) ) =
778
- compatibility_diagonal. iter ( ) . enumerate ( ) . find_map ( |( i, c) | {
778
+ compatibility_diagonal. iter_enumerated ( ) . find_map ( |( i, c) | {
779
779
if let Compatibility :: Incompatible ( Some ( terr) ) = c {
780
780
Some ( ( i, * terr) )
781
781
} else {
@@ -787,24 +787,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
787
787
// Do we have as many extra provided arguments as the tuple's length?
788
788
// If so, we might have just forgotten to wrap some args in a tuple.
789
789
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 ( ) )
791
791
// If the tuple is unit, we're not actually wrapping any arguments.
792
792
&& !tys. is_empty ( )
793
793
&& provided_arg_tys. len ( ) == formal_and_expected_inputs. len ( ) - 1 + tys. len ( )
794
794
{
795
795
// 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) ) ;
800
801
801
802
let mut satisfied = true ;
802
803
// Check if the newly wrapped tuple + rest of the arguments are compatible.
803
804
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 ) ) ,
808
809
) {
809
810
if !self . may_coerce ( provided_ty, * expected_ty) {
810
811
satisfied = false ;
@@ -816,20 +817,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
816
817
// Take some care with spans, so we don't suggest wrapping a macro's
817
818
// innards in parenthesis, for example.
818
819
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
823
821
{
824
822
let mut err;
825
823
if tys. len ( ) == 1 {
826
824
// A tuple wrap suggestion actually occurs within,
827
825
// so don't do anything special here.
828
826
err = self . err_ctxt ( ) . report_and_explain_type_error (
829
827
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 ,
833
831
) ,
834
832
self . param_env ,
835
833
terr,
@@ -868,7 +866,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
868
866
callee_ty,
869
867
call_expr,
870
868
None ,
871
- Some ( mismatch_idx) ,
869
+ Some ( mismatch_idx. as_usize ( ) ) ,
872
870
& matched_inputs,
873
871
& formal_and_expected_inputs,
874
872
is_method,
@@ -2615,7 +2613,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2615
2613
}
2616
2614
2617
2615
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 )
2619
2617
. sort_string ( self . tcx ) ;
2620
2618
let label = if idxs_matched == params_with_generics. len ( ) - 1 {
2621
2619
format ! (
0 commit comments