@@ -1116,6 +1116,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1116
1116
s. push_normal ( ty. to_string ( ) ) ;
1117
1117
}
1118
1118
1119
+ fn fn_def_pretty_prefix ( tcx : TyCtxt < ' _ > , did : DefId ) -> DiagnosticStyledString {
1120
+ let description = match tcx. def_kind ( did) {
1121
+ hir:: def:: DefKind :: Ctor ( _, hir:: def:: CtorKind :: Fn ) => "constructor of" ,
1122
+ hir:: def:: DefKind :: Fn => "fn item" ,
1123
+ _ => unreachable ! ( ) ,
1124
+ } ;
1125
+ DiagnosticStyledString :: normal ( format ! ( "[{description} {{" ) )
1126
+ }
1127
+
1119
1128
// process starts here
1120
1129
match ( t1. kind ( ) , t2. kind ( ) ) {
1121
1130
( & ty:: Adt ( def1, sub1) , & ty:: Adt ( def2, sub2) ) => {
@@ -1368,15 +1377,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1368
1377
values
1369
1378
}
1370
1379
1371
- ( ty:: FnDef ( did1, substs1) , ty:: FnDef ( did2, substs2) ) => {
1372
- let sig1 = self . tcx . bound_fn_sig ( * did1) . subst ( self . tcx , substs1) ;
1373
- let sig2 = self . tcx . bound_fn_sig ( * did2) . subst ( self . tcx , substs2) ;
1380
+ ( & ty:: FnDef ( did1, substs1) , & ty:: FnDef ( did2, substs2) ) => {
1381
+ let sig1 = self . tcx . bound_fn_sig ( did1) . subst ( self . tcx , substs1) ;
1382
+ let sig2 = self . tcx . bound_fn_sig ( did2) . subst ( self . tcx , substs2) ;
1374
1383
let mut values = (
1375
- DiagnosticStyledString :: normal ( "[fn item {" . to_string ( ) ) ,
1376
- DiagnosticStyledString :: normal ( "[fn item {" . to_string ( ) ) ,
1384
+ fn_def_pretty_prefix ( self . tcx , did1 ) ,
1385
+ fn_def_pretty_prefix ( self . tcx , did2 ) ,
1377
1386
) ;
1378
- let path1 = self . tcx . def_path_str_with_substs ( * did1, substs1) ;
1379
- let path2 = self . tcx . def_path_str_with_substs ( * did2, substs2) ;
1387
+ let path1 = self . tcx . def_path_str_with_substs ( did1, substs1) ;
1388
+ let path2 = self . tcx . def_path_str_with_substs ( did2, substs2) ;
1380
1389
let same_path = path1 == path2;
1381
1390
values. 0 . push ( path1, !same_path) ;
1382
1391
values. 1 . push ( path2, !same_path) ;
@@ -1388,26 +1397,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1388
1397
values
1389
1398
}
1390
1399
1391
- ( ty:: FnDef ( did1, substs1) , ty:: FnPtr ( sig2) ) => {
1392
- let sig1 = self . tcx . bound_fn_sig ( * did1) . subst ( self . tcx , substs1) ;
1400
+ ( & ty:: FnDef ( did1, substs1) , ty:: FnPtr ( sig2) ) => {
1401
+ let sig1 = self . tcx . bound_fn_sig ( did1) . subst ( self . tcx , substs1) ;
1393
1402
let mut values = (
1394
- DiagnosticStyledString :: normal ( "[fn item {" . to_string ( ) ) ,
1403
+ fn_def_pretty_prefix ( self . tcx , did1 ) ,
1395
1404
DiagnosticStyledString :: new ( ) ,
1396
1405
) ;
1397
- values. 0 . push_highlighted ( self . tcx . def_path_str_with_substs ( * did1, substs1) ) ;
1406
+ values. 0 . push_highlighted ( self . tcx . def_path_str_with_substs ( did1, substs1) ) ;
1398
1407
values. 0 . push_normal ( "}: " ) ;
1399
1408
self . cmp_fn_sig ( & sig1, sig2, & mut values, true ) ;
1400
1409
values. 0 . push_normal ( "]" ) ;
1401
1410
values
1402
1411
}
1403
1412
1404
- ( ty:: FnPtr ( sig1) , ty:: FnDef ( did2, substs2) ) => {
1405
- let sig2 = self . tcx . bound_fn_sig ( * did2) . subst ( self . tcx , substs2) ;
1413
+ ( ty:: FnPtr ( sig1) , & ty:: FnDef ( did2, substs2) ) => {
1414
+ let sig2 = self . tcx . bound_fn_sig ( did2) . subst ( self . tcx , substs2) ;
1406
1415
let mut values = (
1407
1416
DiagnosticStyledString :: new ( ) ,
1408
- DiagnosticStyledString :: normal ( "[fn item {" . to_string ( ) ) ,
1417
+ fn_def_pretty_prefix ( self . tcx , did2 ) ,
1409
1418
) ;
1410
- values. 1 . push_highlighted ( self . tcx . def_path_str_with_substs ( * did2, substs2) ) ;
1419
+ values. 1 . push_highlighted ( self . tcx . def_path_str_with_substs ( did2, substs2) ) ;
1411
1420
values. 1 . push_normal ( "}: " ) ;
1412
1421
self . cmp_fn_sig ( sig1, & sig2, & mut values, true ) ;
1413
1422
values. 1 . push_normal ( "]" ) ;
0 commit comments