@@ -445,16 +445,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
445
445
let found_errors = !errors. is_empty ( ) ;
446
446
447
447
errors. drain_filter ( |error| {
448
- let Error :: Invalid ( input_idx, arg_idx, Compatibility :: Incompatible ( error ) ) = error else { return false } ;
448
+ let Error :: Invalid ( input_idx, arg_idx, Compatibility :: Incompatible ( Some ( e ) ) ) = error else { return false } ;
449
449
let expected_ty = expected_input_tys[ * arg_idx] ;
450
- let provided_ty = final_arg_types[ * input_idx] . map ( |ty| ty. 0 ) . unwrap ( ) ;
450
+ let provided_ty = final_arg_types[ * input_idx] . map ( |ty| ty. 0 ) . unwrap_or_else ( || tcx . ty_error ( ) ) ;
451
451
let cause = & self . misc ( provided_args[ * input_idx] . span ) ;
452
452
let trace = TypeTrace :: types ( cause, true , expected_ty, provided_ty) ;
453
- if let Some ( e) = error {
454
- if !matches ! ( trace. cause. as_failure_code( e) , FailureCode :: Error0308 ( _) ) {
455
- self . report_and_explain_type_error ( trace, e) . emit ( ) ;
456
- return true ;
457
- }
453
+ if !matches ! ( trace. cause. as_failure_code( e) , FailureCode :: Error0308 ( _) ) {
454
+ self . report_and_explain_type_error ( trace, e) . emit ( ) ;
455
+ return true ;
458
456
}
459
457
false
460
458
} ) ;
@@ -585,7 +583,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
585
583
) ) = errors. iter ( ) . next ( )
586
584
{
587
585
let expected_ty = expected_input_tys[ * arg_idx] ;
588
- let provided_ty = final_arg_types[ * arg_idx] . map ( |ty| ty. 0 ) . unwrap ( ) ;
586
+ let provided_ty = final_arg_types[ * input_idx]
587
+ . map ( |ty| ty. 0 )
588
+ . unwrap_or_else ( || tcx. ty_error ( ) ) ;
589
589
let expected_ty = self . resolve_vars_if_possible ( expected_ty) ;
590
590
let provided_ty = self . resolve_vars_if_possible ( provided_ty) ;
591
591
let cause = & self . misc ( provided_args[ * input_idx] . span ) ;
@@ -595,7 +595,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
595
595
& mut err,
596
596
& provided_args[ * input_idx] ,
597
597
provided_ty,
598
- final_arg_types[ * input_idx] . map ( |ty| ty. 1 ) . unwrap ( ) ,
598
+ final_arg_types[ * input_idx]
599
+ . map ( |ty| ty. 1 )
600
+ . unwrap_or_else ( || tcx. ty_error ( ) ) ,
599
601
None ,
600
602
None ,
601
603
) ;
@@ -652,7 +654,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
652
654
match error {
653
655
Error :: Invalid ( input_idx, arg_idx, compatibility) => {
654
656
let expected_ty = expected_input_tys[ arg_idx] ;
655
- let provided_ty = final_arg_types[ input_idx] . map ( |ty| ty. 0 ) . unwrap ( ) ;
657
+ let provided_ty = final_arg_types[ input_idx]
658
+ . map ( |ty| ty. 0 )
659
+ . unwrap_or_else ( || tcx. ty_error ( ) ) ;
656
660
let expected_ty = self . resolve_vars_if_possible ( expected_ty) ;
657
661
let provided_ty = self . resolve_vars_if_possible ( provided_ty) ;
658
662
if let Compatibility :: Incompatible ( error) = & compatibility {
@@ -674,8 +678,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
674
678
self . emit_coerce_suggestions (
675
679
& mut err,
676
680
& provided_args[ input_idx] ,
677
- final_arg_types[ input_idx] . map ( |ty| ty. 0 ) . unwrap ( ) ,
678
- final_arg_types[ input_idx] . map ( |ty| ty. 1 ) . unwrap ( ) ,
681
+ provided_ty,
682
+ // FIXME(compiler-errors): expected_ty?
683
+ final_arg_types[ input_idx]
684
+ . map ( |ty| ty. 1 )
685
+ . unwrap_or_else ( || tcx. ty_error ( ) ) ,
679
686
None ,
680
687
None ,
681
688
) ;
@@ -860,7 +867,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
860
867
let first_expected_ty =
861
868
self . resolve_vars_if_possible ( expected_input_tys[ arg_idx] ) ;
862
869
let first_provided_ty = if let Some ( ( ty, _) ) = final_arg_types[ input_idx] {
863
- format ! ( ",found `{}`" , ty)
870
+ format ! ( ", found `{}`" , ty)
864
871
} else {
865
872
String :: new ( )
866
873
} ;
@@ -872,7 +879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
872
879
self . resolve_vars_if_possible ( expected_input_tys[ other_arg_idx] ) ;
873
880
let other_provided_ty =
874
881
if let Some ( ( ty, _) ) = final_arg_types[ other_input_idx] {
875
- format ! ( ",found `{}`" , ty)
882
+ format ! ( ", found `{}`" , ty)
876
883
} else {
877
884
String :: new ( )
878
885
} ;
@@ -888,14 +895,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
888
895
Error :: Permutation ( args) => {
889
896
for ( dst_arg, dest_input) in args {
890
897
let expected_ty =
891
- self . resolve_vars_if_possible ( expected_input_tys[ dest_input ] ) ;
892
- let provided_ty = if let Some ( ( ty, _) ) = final_arg_types[ dst_arg ] {
893
- format ! ( ",found `{}`" , ty)
898
+ self . resolve_vars_if_possible ( expected_input_tys[ dst_arg ] ) ;
899
+ let provided_ty = if let Some ( ( ty, _) ) = final_arg_types[ dest_input ] {
900
+ format ! ( ", found `{}`" , ty)
894
901
} else {
895
902
String :: new ( )
896
903
} ;
897
904
labels. push ( (
898
- provided_args[ dst_arg ] . span ,
905
+ provided_args[ dest_input ] . span ,
899
906
format ! ( "expected `{}`{}" , expected_ty, provided_ty) ,
900
907
) ) ;
901
908
}
0 commit comments