@@ -824,9 +824,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
824824fn cmp_fn_sig (
825825& self ,
826826sig1 : & ty:: PolyFnSig < ' tcx > ,
827- fn_def1 : Option < ( DefId , & ' tcx [ ty:: GenericArg < ' tcx > ] ) > ,
827+ fn_def1 : Option < ( DefId , Option < & ' tcx [ ty:: GenericArg < ' tcx > ] > ) > ,
828828sig2 : & 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 ) {
831831let sig1 = & ( self . normalize_fn_sig ) ( * sig1) ;
832832let 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
949949match ( 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) ;
954953let 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) ) => {
13521352let sig1 = self . tcx . fn_sig ( * did1) . instantiate ( self . tcx , args1) ;
13531353let 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) ) => {
13581363let 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) ) => {
13631368let 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.
@@ -1968,7 +1973,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19681973} )
19691974 | ObligationCauseCode :: BlockTailExpression ( .., source) ) = code
19701975 && let hir:: MatchSource :: TryDesugar ( _) = source
1971- && let Some ( ( expected_ty, found_ty, _) ) = self . values_str ( trace. values )
1976+ && let Some ( ( expected_ty, found_ty, _) ) = self . values_str ( trace. values , & trace . cause )
19721977{
19731978 suggestions. push ( TypeErrorAdditionalDiags :: TryCannotConvert {
19741979found : found_ty. content ( ) ,
@@ -2097,6 +2102,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
20972102fn values_str (
20982103& self ,
20992104values : ValuePairs < ' tcx > ,
2105+ cause : & ObligationCause < ' tcx > ,
21002106) -> Option < ( DiagStyledString , DiagStyledString , Option < PathBuf > ) > {
21012107match values {
21022108ValuePairs :: Regions ( exp_found) => self . expected_found_str ( exp_found) ,
@@ -2121,7 +2127,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21212127if exp_found. references_error ( ) {
21222128return None ;
21232129}
2124- let ( exp, fnd) = self . cmp_fn_sig ( & exp_found. expected , None , & exp_found. found , None ) ;
2130+ let ( fn_def1, fn_def2) = if let ObligationCauseCode :: CompareImplItem {
2131+ impl_item_def_id,
2132+ trait_item_def_id,
2133+ ..
2134+ } = * cause. code ( )
2135+ {
2136+ ( Some ( ( trait_item_def_id, None ) ) , Some ( ( impl_item_def_id. to_def_id ( ) , None ) ) )
2137+ } else {
2138+ ( None , None )
2139+ } ;
2140+
2141+ let ( exp, fnd) =
2142+ self . cmp_fn_sig ( & exp_found. expected , fn_def1, & exp_found. found , fn_def2) ;
21252143Some ( ( exp, fnd, None ) )
21262144}
21272145}
0 commit comments