@@ -555,6 +555,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
555
555
fn cmp ( & self , t1 : Ty < ' tcx > , t2 : Ty < ' tcx > )
556
556
-> ( DiagnosticStyledString , DiagnosticStyledString )
557
557
{
558
+ fn equals < ' tcx > ( a : & Ty < ' tcx > , b : & Ty < ' tcx > ) -> bool {
559
+ match ( & a. sty , & b. sty ) {
560
+ ( a, b) if * a == * b => true ,
561
+ ( & ty:: TyInt ( _) , & ty:: TyInfer ( ty:: InferTy :: IntVar ( _) ) ) |
562
+ ( & ty:: TyInfer ( ty:: InferTy :: IntVar ( _) ) , & ty:: TyInt ( _) ) |
563
+ ( & ty:: TyInfer ( ty:: InferTy :: IntVar ( _) ) , & ty:: TyInfer ( ty:: InferTy :: IntVar ( _) ) ) |
564
+ ( & ty:: TyFloat ( _) , & ty:: TyInfer ( ty:: InferTy :: FloatVar ( _) ) ) |
565
+ ( & ty:: TyInfer ( ty:: InferTy :: FloatVar ( _) ) , & ty:: TyFloat ( _) ) |
566
+ ( & ty:: TyInfer ( ty:: InferTy :: FloatVar ( _) ) ,
567
+ & ty:: TyInfer ( ty:: InferTy :: FloatVar ( _) ) ) => true ,
568
+ _ => false ,
569
+ }
570
+ }
571
+
558
572
match ( & t1. sty , & t2. sty ) {
559
573
( & ty:: TyAdt ( def1, sub1) , & ty:: TyAdt ( def2, sub2) ) => {
560
574
let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
@@ -672,6 +686,50 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
672
686
DiagnosticStyledString :: highlighted ( format ! ( "{}" , t2) ) )
673
687
}
674
688
}
689
+
690
+ // When finding T != &T, hightlight only the borrow
691
+ ( & ty:: TyRef ( _, ref tnm1) , _) if equals ( & tnm1. ty , & t2) => {
692
+ 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) ) ;
699
+ values. 1 . push_normal ( format ! ( "{}" , t2) ) ;
700
+ values
701
+ }
702
+ ( _, & ty:: TyRef ( _, ref tnm2) ) if equals ( & t1, & tnm2. ty ) => {
703
+ 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
+ values. 0 . push_normal ( format ! ( "{}" , t1) ) ;
710
+ values. 1 . push_normal ( format ! ( "{}" , tnm2. ty) ) ;
711
+ values
712
+ }
713
+
714
+ // When encountering &T != &mut T, highlight only the borrow
715
+ ( & ty:: TyRef ( _, ref tnm1) , & ty:: TyRef ( _, ref tnm2) ) if equals ( & tnm1. ty , & tnm2. ty ) => {
716
+ 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) ) ;
730
+ values
731
+ }
732
+
675
733
_ => {
676
734
if t1 == t2 {
677
735
// The two types are the same, elide and don't highlight.
0 commit comments