@@ -1116,6 +1116,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11161116 s. push_normal ( ty. to_string ( ) ) ;
11171117 }
11181118
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+
11191128 // process starts here
11201129 match ( t1. kind ( ) , t2. kind ( ) ) {
11211130 ( & ty:: Adt ( def1, sub1) , & ty:: Adt ( def2, sub2) ) => {
@@ -1368,15 +1377,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13681377 values
13691378 }
13701379
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) ;
13741383 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 ) ,
13771386 ) ;
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) ;
13801389 let same_path = path1 == path2;
13811390 values. 0 . push ( path1, !same_path) ;
13821391 values. 1 . push ( path2, !same_path) ;
@@ -1388,26 +1397,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13881397 values
13891398 }
13901399
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) ;
13931402 let mut values = (
1394- DiagnosticStyledString :: normal ( "[fn item {" . to_string ( ) ) ,
1403+ fn_def_pretty_prefix ( self . tcx , did1 ) ,
13951404 DiagnosticStyledString :: new ( ) ,
13961405 ) ;
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) ) ;
13981407 values. 0 . push_normal ( "}: " ) ;
13991408 self . cmp_fn_sig ( & sig1, sig2, & mut values, true ) ;
14001409 values. 0 . push_normal ( "]" ) ;
14011410 values
14021411 }
14031412
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) ;
14061415 let mut values = (
14071416 DiagnosticStyledString :: new ( ) ,
1408- DiagnosticStyledString :: normal ( "[fn item {" . to_string ( ) ) ,
1417+ fn_def_pretty_prefix ( self . tcx , did2 ) ,
14091418 ) ;
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) ) ;
14111420 values. 1 . push_normal ( "}: " ) ;
14121421 self . cmp_fn_sig ( sig1, & sig2, & mut values, true ) ;
14131422 values. 1 . push_normal ( "]" ) ;
0 commit comments