@@ -824,9 +824,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
824
824
fn cmp_fn_sig (
825
825
& self ,
826
826
sig1 : & ty:: PolyFnSig < ' tcx > ,
827
- fn_def1 : Option < ( DefId , & ' tcx [ ty:: GenericArg < ' tcx > ] ) > ,
827
+ fn_def1 : Option < ( DefId , Option < & ' tcx [ ty:: GenericArg < ' tcx > ] > ) > ,
828
828
sig2 : & ty:: PolyFnSig < ' tcx > ,
829
- fn_def2 : Option < ( DefId , & ' tcx [ ty:: GenericArg < ' tcx > ] ) > ,
829
+ fn_def2 : Option < ( DefId , Option < & ' tcx [ ty:: GenericArg < ' tcx > ] > ) > ,
830
830
) -> ( DiagStyledString , DiagStyledString ) {
831
831
let sig1 = & ( self . normalize_fn_sig ) ( * sig1) ;
832
832
let sig2 = & ( self . normalize_fn_sig ) ( * sig2) ;
@@ -944,23 +944,23 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
944
944
( values. 1 ) . 0 . extend ( x2. 0 ) ;
945
945
}
946
946
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) ) ;
948
948
949
949
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) ;
954
953
let same_path = path1 == path2;
955
954
values. 0 . push ( path1, !same_path) ;
956
955
values. 1 . push ( path2, !same_path) ;
957
956
}
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 ) ) ;
960
959
}
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 ) ) ;
963
962
}
963
+ _ => { }
964
964
}
965
965
966
966
values
@@ -1351,17 +1351,22 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1351
1351
( ty:: FnDef ( did1, args1) , ty:: FnDef ( did2, args2) ) => {
1352
1352
let sig1 = self . tcx . fn_sig ( * did1) . instantiate ( self . tcx , args1) ;
1353
1353
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
+ )
1355
1360
}
1356
1361
1357
1362
( ty:: FnDef ( did1, args1) , ty:: FnPtr ( sig_tys2, hdr2) ) => {
1358
1363
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 )
1360
1365
}
1361
1366
1362
1367
( ty:: FnPtr ( sig_tys1, hdr1) , ty:: FnDef ( did2, args2) ) => {
1363
1368
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) ) ) )
1365
1370
}
1366
1371
1367
1372
( ty:: FnPtr ( sig_tys1, hdr1) , ty:: FnPtr ( sig_tys2, hdr2) ) => {
@@ -1543,7 +1548,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1543
1548
( false , Mismatch :: Fixed ( "existential projection" ) )
1544
1549
}
1545
1550
} ;
1546
- let Some ( vals) = self . values_str ( values) else {
1551
+ let Some ( vals) = self . values_str ( values, cause ) else {
1547
1552
// Derived error. Cancel the emitter.
1548
1553
// NOTE(eddyb) this was `.cancel()`, but `diag`
1549
1554
// is borrowed, so we can't fully defuse it.
@@ -1968,7 +1973,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1968
1973
} )
1969
1974
| ObligationCauseCode :: BlockTailExpression ( .., source) ) = code
1970
1975
&& 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 )
1972
1977
{
1973
1978
suggestions. push ( TypeErrorAdditionalDiags :: TryCannotConvert {
1974
1979
found : found_ty. content ( ) ,
@@ -2097,6 +2102,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
2097
2102
fn values_str (
2098
2103
& self ,
2099
2104
values : ValuePairs < ' tcx > ,
2105
+ cause : & ObligationCause < ' tcx > ,
2100
2106
) -> Option < ( DiagStyledString , DiagStyledString , Option < PathBuf > ) > {
2101
2107
match values {
2102
2108
ValuePairs :: Regions ( exp_found) => self . expected_found_str ( exp_found) ,
@@ -2121,7 +2127,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
2121
2127
if exp_found. references_error ( ) {
2122
2128
return None ;
2123
2129
}
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) ;
2125
2143
Some ( ( exp, fnd, None ) )
2126
2144
}
2127
2145
}
0 commit comments