@@ -445,16 +445,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
445445 let found_errors = !errors. is_empty ( ) ;
446446
447447 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 } ;
449449 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 ( ) ) ;
451451 let cause = & self . misc ( provided_args[ * input_idx] . span ) ;
452452 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 ;
458456 }
459457 false
460458 } ) ;
@@ -585,7 +583,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
585583 ) ) = errors. iter ( ) . next ( )
586584 {
587585 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 ( ) ) ;
589589 let expected_ty = self . resolve_vars_if_possible ( expected_ty) ;
590590 let provided_ty = self . resolve_vars_if_possible ( provided_ty) ;
591591 let cause = & self . misc ( provided_args[ * input_idx] . span ) ;
@@ -595,7 +595,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
595595 & mut err,
596596 & provided_args[ * input_idx] ,
597597 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 ( ) ) ,
599601 None ,
600602 None ,
601603 ) ;
@@ -652,7 +654,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
652654 match error {
653655 Error :: Invalid ( input_idx, arg_idx, compatibility) => {
654656 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 ( ) ) ;
656660 let expected_ty = self . resolve_vars_if_possible ( expected_ty) ;
657661 let provided_ty = self . resolve_vars_if_possible ( provided_ty) ;
658662 if let Compatibility :: Incompatible ( error) = & compatibility {
@@ -674,8 +678,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
674678 self . emit_coerce_suggestions (
675679 & mut err,
676680 & 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 ( ) ) ,
679686 None ,
680687 None ,
681688 ) ;
@@ -860,7 +867,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
860867 let first_expected_ty =
861868 self . resolve_vars_if_possible ( expected_input_tys[ arg_idx] ) ;
862869 let first_provided_ty = if let Some ( ( ty, _) ) = final_arg_types[ input_idx] {
863- format ! ( ",found `{}`" , ty)
870+ format ! ( ", found `{}`" , ty)
864871 } else {
865872 String :: new ( )
866873 } ;
@@ -872,7 +879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
872879 self . resolve_vars_if_possible ( expected_input_tys[ other_arg_idx] ) ;
873880 let other_provided_ty =
874881 if let Some ( ( ty, _) ) = final_arg_types[ other_input_idx] {
875- format ! ( ",found `{}`" , ty)
882+ format ! ( ", found `{}`" , ty)
876883 } else {
877884 String :: new ( )
878885 } ;
@@ -888,14 +895,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
888895 Error :: Permutation ( args) => {
889896 for ( dst_arg, dest_input) in args {
890897 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)
894901 } else {
895902 String :: new ( )
896903 } ;
897904 labels. push ( (
898- provided_args[ dst_arg ] . span ,
905+ provided_args[ dest_input ] . span ,
899906 format ! ( "expected `{}`{}" , expected_ty, provided_ty) ,
900907 ) ) ;
901908 }
0 commit comments