@@ -824,9 +824,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
824824 fn cmp_fn_sig (
825825 & self ,
826826 sig1 : & ty:: PolyFnSig < ' tcx > ,
827- fn_def1 : Option < ( DefId , & ' tcx [ ty:: GenericArg < ' tcx > ] ) > ,
827+ fn_def1 : Option < ( DefId , Option < & ' tcx [ ty:: GenericArg < ' tcx > ] > ) > ,
828828 sig2 : & ty:: PolyFnSig < ' tcx > ,
829- fn_def2 : Option < ( DefId , & ' tcx [ ty:: GenericArg < ' tcx > ] ) > ,
829+ fn_def2 : Option < ( DefId , Option < & ' tcx [ ty:: GenericArg < ' tcx > ] > ) > ,
830830 ) -> ( DiagStyledString , DiagStyledString ) {
831831 let sig1 = & ( self . normalize_fn_sig ) ( * sig1) ;
832832 let sig2 = & ( self . normalize_fn_sig ) ( * sig2) ;
@@ -944,23 +944,23 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
944944 ( values. 1 ) . 0 . extend ( x2. 0 ) ;
945945 }
946946
947- let fmt = |( did, args) | format ! ( " {{{}}}" , self . tcx. def_path_str_with_args( did, args) ) ;
947+ let fmt = |did, args| format ! ( " {{{}}}" , self . tcx. def_path_str_with_args( did, args) ) ;
948948
949949 match ( fn_def1, fn_def2) {
950- ( None , None ) => { }
951- ( Some ( fn_def1) , Some ( fn_def2) ) => {
952- let path1 = fmt ( fn_def1) ;
953- let path2 = fmt ( fn_def2) ;
950+ ( Some ( ( fn_def1, Some ( fn_args1) ) ) , Some ( ( fn_def2, Some ( fn_args2) ) ) ) => {
951+ let path1 = fmt ( fn_def1, fn_args1) ;
952+ let path2 = fmt ( fn_def2, fn_args2) ;
954953 let same_path = path1 == path2;
955954 values. 0 . push ( path1, !same_path) ;
956955 values. 1 . push ( path2, !same_path) ;
957956 }
958- ( Some ( fn_def1) , None ) => {
959- values. 0 . push_highlighted ( fmt ( fn_def1) ) ;
957+ ( Some ( ( fn_def1, Some ( fn_args1 ) ) ) , None ) => {
958+ values. 0 . push_highlighted ( fmt ( fn_def1, fn_args1 ) ) ;
960959 }
961- ( None , Some ( fn_def2) ) => {
962- values. 1 . push_highlighted ( fmt ( fn_def2) ) ;
960+ ( None , Some ( ( fn_def2, Some ( fn_args2 ) ) ) ) => {
961+ values. 1 . push_highlighted ( fmt ( fn_def2, fn_args2 ) ) ;
963962 }
963+ _ => { }
964964 }
965965
966966 values
@@ -1351,17 +1351,22 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
13511351 ( ty:: FnDef ( did1, args1) , ty:: FnDef ( did2, args2) ) => {
13521352 let sig1 = self . tcx . fn_sig ( * did1) . instantiate ( self . tcx , args1) ;
13531353 let sig2 = self . tcx . fn_sig ( * did2) . instantiate ( self . tcx , args2) ;
1354- self . cmp_fn_sig ( & sig1, Some ( ( * did1, args1) ) , & sig2, Some ( ( * did2, args2) ) )
1354+ self . cmp_fn_sig (
1355+ & sig1,
1356+ Some ( ( * did1, Some ( args1) ) ) ,
1357+ & sig2,
1358+ Some ( ( * did2, Some ( args2) ) ) ,
1359+ )
13551360 }
13561361
13571362 ( ty:: FnDef ( did1, args1) , ty:: FnPtr ( sig_tys2, hdr2) ) => {
13581363 let sig1 = self . tcx . fn_sig ( * did1) . instantiate ( self . tcx , args1) ;
1359- self . cmp_fn_sig ( & sig1, Some ( ( * did1, args1) ) , & sig_tys2. with ( * hdr2) , None )
1364+ self . cmp_fn_sig ( & sig1, Some ( ( * did1, Some ( args1) ) ) , & sig_tys2. with ( * hdr2) , None )
13601365 }
13611366
13621367 ( ty:: FnPtr ( sig_tys1, hdr1) , ty:: FnDef ( did2, args2) ) => {
13631368 let sig2 = self . tcx . fn_sig ( * did2) . instantiate ( self . tcx , args2) ;
1364- self . cmp_fn_sig ( & sig_tys1. with ( * hdr1) , None , & sig2, Some ( ( * did2, args2) ) )
1369+ self . cmp_fn_sig ( & sig_tys1. with ( * hdr1) , None , & sig2, Some ( ( * did2, Some ( args2) ) ) )
13651370 }
13661371
13671372 ( ty:: FnPtr ( sig_tys1, hdr1) , ty:: FnPtr ( sig_tys2, hdr2) ) => {
@@ -1543,7 +1548,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15431548 ( false , Mismatch :: Fixed ( "existential projection" ) )
15441549 }
15451550 } ;
1546- let Some ( vals) = self . values_str ( values) else {
1551+ let Some ( vals) = self . values_str ( values, cause ) else {
15471552 // Derived error. Cancel the emitter.
15481553 // NOTE(eddyb) this was `.cancel()`, but `diag`
15491554 // is borrowed, so we can't fully defuse it.
@@ -1969,7 +1974,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19691974 } )
19701975 | ObligationCauseCode :: BlockTailExpression ( .., source) ) = code
19711976 && let hir:: MatchSource :: TryDesugar ( _) = source
1972- && let Some ( ( expected_ty, found_ty, _) ) = self . values_str ( trace. values )
1977+ && let Some ( ( expected_ty, found_ty, _) ) = self . values_str ( trace. values , & trace . cause )
19731978 {
19741979 suggestions. push ( TypeErrorAdditionalDiags :: TryCannotConvert {
19751980 found : found_ty. content ( ) ,
@@ -2096,6 +2101,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
20962101 fn values_str (
20972102 & self ,
20982103 values : ValuePairs < ' tcx > ,
2104+ cause : & ObligationCause < ' tcx > ,
20992105 ) -> Option < ( DiagStyledString , DiagStyledString , Option < PathBuf > ) > {
21002106 match values {
21012107 ValuePairs :: Regions ( exp_found) => self . expected_found_str ( exp_found) ,
@@ -2120,7 +2126,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21202126 if exp_found. references_error ( ) {
21212127 return None ;
21222128 }
2123- let ( exp, fnd) = self . cmp_fn_sig ( & exp_found. expected , None , & exp_found. found , None ) ;
2129+ let ( fn_def1, fn_def2) = if let ObligationCauseCode :: CompareImplItem {
2130+ impl_item_def_id,
2131+ trait_item_def_id,
2132+ ..
2133+ } = * cause. code ( )
2134+ {
2135+ ( Some ( ( trait_item_def_id, None ) ) , Some ( ( impl_item_def_id. to_def_id ( ) , None ) ) )
2136+ } else {
2137+ ( None , None )
2138+ } ;
2139+
2140+ let ( exp, fnd) =
2141+ self . cmp_fn_sig ( & exp_found. expected , fn_def1, & exp_found. found , fn_def2) ;
21242142 Some ( ( exp, fnd, None ) )
21252143 }
21262144 }
0 commit comments