@@ -1116,13 +1116,23 @@ 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) {
1119
+ fn fn_def_pretty_prefixes < const N : usize > (
1120
+ tcx : TyCtxt < ' _ > ,
1121
+ dids : [ DefId ; N ] ,
1122
+ ) -> [ DiagnosticStyledString ; N ] {
1123
+ assert ! ( N == 1 || N == 2 ) ;
1124
+ let descriptions = dids. map ( |did| match tcx. def_kind ( did) {
1121
1125
hir:: def:: DefKind :: Ctor ( _, hir:: def:: CtorKind :: Fn ) => "constructor of" ,
1122
1126
hir:: def:: DefKind :: Fn => "fn item" ,
1123
1127
_ => unreachable ! ( ) ,
1124
- } ;
1125
- DiagnosticStyledString :: normal ( format ! ( "[{description} {{" ) )
1128
+ } ) ;
1129
+ let highlight = N == 1 || descriptions[ 0 ] != descriptions[ 1 ] ;
1130
+ descriptions. map ( |description| {
1131
+ let mut styled_string = DiagnosticStyledString :: normal ( "[" ) ;
1132
+ styled_string. push ( description. to_string ( ) , highlight) ;
1133
+ styled_string. push_normal ( " {" ) ;
1134
+ styled_string
1135
+ } )
1126
1136
}
1127
1137
1128
1138
// process starts here
@@ -1380,10 +1390,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1380
1390
( & ty:: FnDef ( did1, substs1) , & ty:: FnDef ( did2, substs2) ) => {
1381
1391
let sig1 = self . tcx . bound_fn_sig ( did1) . subst ( self . tcx , substs1) ;
1382
1392
let sig2 = self . tcx . bound_fn_sig ( did2) . subst ( self . tcx , substs2) ;
1383
- let mut values = (
1384
- fn_def_pretty_prefix ( self . tcx , did1) ,
1385
- fn_def_pretty_prefix ( self . tcx , did2) ,
1386
- ) ;
1393
+ let [ v1, v2] = fn_def_pretty_prefixes ( self . tcx , [ did1, did2] ) ;
1394
+ let mut values = ( v1, v2) ;
1387
1395
let path1 = self . tcx . def_path_str_with_substs ( did1, substs1) ;
1388
1396
let path2 = self . tcx . def_path_str_with_substs ( did2, substs2) ;
1389
1397
let same_path = path1 == path2;
@@ -1399,10 +1407,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1399
1407
1400
1408
( & ty:: FnDef ( did1, substs1) , ty:: FnPtr ( sig2) ) => {
1401
1409
let sig1 = self . tcx . bound_fn_sig ( did1) . subst ( self . tcx , substs1) ;
1402
- let mut values = (
1403
- fn_def_pretty_prefix ( self . tcx , did1) ,
1404
- DiagnosticStyledString :: new ( ) ,
1405
- ) ;
1410
+ let [ v1] = fn_def_pretty_prefixes ( self . tcx , [ did1] ) ;
1411
+ let mut values = ( v1, DiagnosticStyledString :: new ( ) ) ;
1406
1412
values. 0 . push_highlighted ( self . tcx . def_path_str_with_substs ( did1, substs1) ) ;
1407
1413
values. 0 . push_normal ( "}: " ) ;
1408
1414
self . cmp_fn_sig ( & sig1, sig2, & mut values, true ) ;
@@ -1412,10 +1418,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1412
1418
1413
1419
( ty:: FnPtr ( sig1) , & ty:: FnDef ( did2, substs2) ) => {
1414
1420
let sig2 = self . tcx . bound_fn_sig ( did2) . subst ( self . tcx , substs2) ;
1415
- let mut values = (
1416
- DiagnosticStyledString :: new ( ) ,
1417
- fn_def_pretty_prefix ( self . tcx , did2) ,
1418
- ) ;
1421
+ let [ v2] = fn_def_pretty_prefixes ( self . tcx , [ did2] ) ;
1422
+ let mut values = ( DiagnosticStyledString :: new ( ) , v2) ;
1419
1423
values. 1 . push_highlighted ( self . tcx . def_path_str_with_substs ( did2, substs2) ) ;
1420
1424
values. 1 . push_normal ( "}: " ) ;
1421
1425
self . cmp_fn_sig ( sig1, & sig2, & mut values, true ) ;
0 commit comments