@@ -824,7 +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
828
sig2 : & ty:: PolyFnSig < ' tcx > ,
829
+ fn_def2 : Option < ( DefId , & ' tcx [ ty:: GenericArg < ' tcx > ] ) > ,
828
830
) -> ( DiagStyledString , DiagStyledString ) {
829
831
let sig1 = & ( self . normalize_fn_sig ) ( * sig1) ;
830
832
let sig2 = & ( self . normalize_fn_sig ) ( * sig2) ;
@@ -930,6 +932,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
930
932
( values. 1 ) . 0 . extend ( x2. 0 ) ;
931
933
}
932
934
935
+ let fmt = |( did, args) | format ! ( " {{{}}}" , self . tcx. def_path_str_with_args( did, args) ) ;
936
+
937
+ match ( fn_def1, fn_def2) {
938
+ ( None , None ) => { }
939
+ ( Some ( fn_def1) , Some ( fn_def2) ) => {
940
+ let path1 = fmt ( fn_def1) ;
941
+ let path2 = fmt ( fn_def2) ;
942
+ let same_path = path1 == path2;
943
+ values. 0 . push ( path1, !same_path) ;
944
+ values. 1 . push ( path2, !same_path) ;
945
+ }
946
+ ( Some ( fn_def1) , None ) => {
947
+ values. 0 . push_highlighted ( fmt ( fn_def1) ) ;
948
+ }
949
+ ( None , Some ( fn_def2) ) => {
950
+ values. 1 . push_highlighted ( fmt ( fn_def2) ) ;
951
+ }
952
+ }
953
+
933
954
values
934
955
}
935
956
@@ -1318,36 +1339,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1318
1339
( ty:: FnDef ( did1, args1) , ty:: FnDef ( did2, args2) ) => {
1319
1340
let sig1 = self . tcx . fn_sig ( * did1) . instantiate ( self . tcx , args1) ;
1320
1341
let sig2 = self . tcx . fn_sig ( * did2) . instantiate ( self . tcx , args2) ;
1321
- let mut values = self . cmp_fn_sig ( & sig1, & sig2) ;
1322
- let path1 = format ! ( " {{{}}}" , self . tcx. def_path_str_with_args( * did1, args1) ) ;
1323
- let path2 = format ! ( " {{{}}}" , self . tcx. def_path_str_with_args( * did2, args2) ) ;
1324
- let same_path = path1 == path2;
1325
- values. 0 . push ( path1, !same_path) ;
1326
- values. 1 . push ( path2, !same_path) ;
1327
- values
1342
+ self . cmp_fn_sig ( & sig1, Some ( ( * did1, args1) ) , & sig2, Some ( ( * did2, args2) ) )
1328
1343
}
1329
1344
1330
1345
( ty:: FnDef ( did1, args1) , ty:: FnPtr ( sig_tys2, hdr2) ) => {
1331
1346
let sig1 = self . tcx . fn_sig ( * did1) . instantiate ( self . tcx , args1) ;
1332
- let mut values = self . cmp_fn_sig ( & sig1, & sig_tys2. with ( * hdr2) ) ;
1333
- values. 0 . push_highlighted ( format ! (
1334
- " {{{}}}" ,
1335
- self . tcx. def_path_str_with_args( * did1, args1)
1336
- ) ) ;
1337
- values
1347
+ self . cmp_fn_sig ( & sig1, Some ( ( * did1, args1) ) , & sig_tys2. with ( * hdr2) , None )
1338
1348
}
1339
1349
1340
1350
( ty:: FnPtr ( sig_tys1, hdr1) , ty:: FnDef ( did2, args2) ) => {
1341
1351
let sig2 = self . tcx . fn_sig ( * did2) . instantiate ( self . tcx , args2) ;
1342
- let mut values = self . cmp_fn_sig ( & sig_tys1. with ( * hdr1) , & sig2) ;
1343
- values
1344
- . 1
1345
- . push_normal ( format ! ( " {{{}}}" , self . tcx. def_path_str_with_args( * did2, args2) ) ) ;
1346
- values
1352
+ self . cmp_fn_sig ( & sig_tys1. with ( * hdr1) , None , & sig2, Some ( ( * did2, args2) ) )
1347
1353
}
1348
1354
1349
1355
( ty:: FnPtr ( sig_tys1, hdr1) , ty:: FnPtr ( sig_tys2, hdr2) ) => {
1350
- self . cmp_fn_sig ( & sig_tys1. with ( * hdr1) , & sig_tys2. with ( * hdr2) )
1356
+ self . cmp_fn_sig ( & sig_tys1. with ( * hdr1) , None , & sig_tys2. with ( * hdr2) , None )
1351
1357
}
1352
1358
1353
1359
_ => {
@@ -2102,7 +2108,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
2102
2108
if exp_found. references_error ( ) {
2103
2109
return None ;
2104
2110
}
2105
- let ( exp, fnd) = self . cmp_fn_sig ( & exp_found. expected , & exp_found. found ) ;
2111
+ let ( exp, fnd) = self . cmp_fn_sig ( & exp_found. expected , None , & exp_found. found , None ) ;
2106
2112
Some ( ( exp, fnd, None ) )
2107
2113
}
2108
2114
}
0 commit comments