@@ -569,6 +569,25 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
569
569
}
570
570
}
571
571
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
+
572
591
match ( & t1. sty , & t2. sty ) {
573
592
( & ty:: TyAdt ( def1, sub1) , & ty:: TyAdt ( def2, sub2) ) => {
574
593
let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
@@ -688,45 +707,24 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
688
707
}
689
708
690
709
// 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) => {
692
711
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 ) ;
699
713
values. 1 . push_normal ( format ! ( "{}" , t2) ) ;
700
714
values
701
715
}
702
- ( _, & ty:: TyRef ( _ , ref tnm2) ) if equals ( & t1, & tnm2. ty ) => {
716
+ ( _, & ty:: TyRef ( r2 , ref tnm2) ) if equals ( & t1, & tnm2. ty ) => {
703
717
let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
704
- values. 1 . push_highlighted ( format ! ( "&{}" , if tnm2. mutbl == hir:: MutMutable {
705
- "mut "
706
- } else {
707
- ""
708
- } ) ) ;
709
718
values. 0 . push_normal ( format ! ( "{}" , t1) ) ;
710
- values . 1 . push_normal ( format ! ( "{}" , tnm2. ty ) ) ;
719
+ push_ty_ref ( & r2 , tnm2, & mut values . 1 ) ;
711
720
values
712
721
}
713
722
714
723
// 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 ) => {
716
725
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 ) ;
730
728
values
731
729
}
732
730
0 commit comments