@@ -569,6 +569,25 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
569569 }
570570 }
571571
572+ fn push_ty_ref < ' tcx > ( r : & ty:: Region < ' tcx > ,
573+ tnm : & ty:: TypeAndMut < ' tcx > ,
574+ s : & mut DiagnosticStyledString ) {
575+ let r = & format ! ( "{}" , r) ;
576+ s. push_highlighted ( format ! ( "&{}{}{}" ,
577+ r,
578+ if r == "" {
579+ ""
580+ } else {
581+ " "
582+ } ,
583+ if tnm. mutbl == hir:: MutMutable {
584+ "mut "
585+ } else {
586+ ""
587+ } ) ) ;
588+ s. push_normal ( format ! ( "{}" , tnm. ty) ) ;
589+ }
590+
572591 match ( & t1. sty , & t2. sty ) {
573592 ( & ty:: TyAdt ( def1, sub1) , & ty:: TyAdt ( def2, sub2) ) => {
574593 let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
@@ -688,45 +707,24 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
688707 }
689708
690709 // When finding T != &T, hightlight only the borrow
691- ( & ty:: TyRef ( _ , ref tnm1) , _) if equals ( & tnm1. ty , & t2) => {
710+ ( & ty:: TyRef ( r1 , ref tnm1) , _) if equals ( & tnm1. ty , & t2) => {
692711 let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
693- values. 0 . push_highlighted ( format ! ( "&{}" , if tnm1. mutbl == hir:: MutMutable {
694- "mut "
695- } else {
696- ""
697- } ) ) ;
698- values. 0 . push_normal ( format ! ( "{}" , tnm1. ty) ) ;
712+ push_ty_ref ( & r1, tnm1, & mut values. 0 ) ;
699713 values. 1 . push_normal ( format ! ( "{}" , t2) ) ;
700714 values
701715 }
702- ( _, & ty:: TyRef ( _ , ref tnm2) ) if equals ( & t1, & tnm2. ty ) => {
716+ ( _, & ty:: TyRef ( r2 , ref tnm2) ) if equals ( & t1, & tnm2. ty ) => {
703717 let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
704- values. 1 . push_highlighted ( format ! ( "&{}" , if tnm2. mutbl == hir:: MutMutable {
705- "mut "
706- } else {
707- ""
708- } ) ) ;
709718 values. 0 . push_normal ( format ! ( "{}" , t1) ) ;
710- values . 1 . push_normal ( format ! ( "{}" , tnm2. ty ) ) ;
719+ push_ty_ref ( & r2 , tnm2, & mut values . 1 ) ;
711720 values
712721 }
713722
714723 // When encountering &T != &mut T, highlight only the borrow
715- ( & ty:: TyRef ( _ , ref tnm1) , & ty:: TyRef ( _ , ref tnm2) ) if equals ( & tnm1. ty , & tnm2. ty ) => {
724+ ( & ty:: TyRef ( r1 , ref tnm1) , & ty:: TyRef ( r2 , ref tnm2) ) if equals ( & tnm1. ty , & tnm2. ty ) => {
716725 let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
717- values. 0 . push_highlighted ( format ! ( "&{}" , if tnm1. mutbl == hir:: MutMutable {
718- "mut "
719- } else {
720- ""
721- } ) ) ;
722- values. 1 . push_highlighted ( format ! ( "&{}" , if tnm2. mutbl == hir:: MutMutable {
723- "mut "
724- } else {
725- ""
726- } ) ) ;
727-
728- values. 0 . push_normal ( format ! ( "{}" , tnm1. ty) ) ;
729- values. 1 . push_normal ( format ! ( "{}" , tnm2. ty) ) ;
726+ push_ty_ref ( & r1, tnm1, & mut values. 0 ) ;
727+ push_ty_ref ( & r2, tnm2, & mut values. 1 ) ;
730728 values
731729 }
732730
0 commit comments