@@ -6,6 +6,7 @@ use crate::infer::{Subtype, TyCtxtInferExt, ValuePairs};
66use crate :: traits:: ObligationCauseCode :: CompareImplMethodObligation ;
77use rustc_errors:: ErrorReported ;
88use rustc_hir as hir;
9+ use rustc_hir:: def:: Res ;
910use rustc_hir:: def_id:: DefId ;
1011use rustc_hir:: intravisit:: Visitor ;
1112use rustc_middle:: ty:: error:: ExpectedFound ;
@@ -124,15 +125,17 @@ impl Visitor<'tcx> for TypeParamSpanVisitor<'tcx> {
124125
125126 fn visit_ty ( & mut self , arg : & ' tcx hir:: Ty < ' tcx > ) {
126127 match arg. kind {
127- hir:: TyKind :: Slice ( _) | hir:: TyKind :: Tup ( _) | hir:: TyKind :: Array ( ..) => {
128- hir:: intravisit:: walk_ty ( self , arg) ;
128+ hir:: TyKind :: Rptr ( _, ref mut_ty) => {
129+ // We don't want to suggest looking into borrowing `&T` or `&Self`.
130+ hir:: intravisit:: walk_ty ( self , mut_ty. ty ) ;
131+ return ;
129132 }
130133 hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , path) ) => match & path. segments {
131134 [ segment]
132135 if segment
133136 . res
134137 . map ( |res| match res {
135- hir :: def :: Res :: Def ( hir:: def:: DefKind :: TyParam , _) => true ,
138+ Res :: SelfTy ( _ , _ ) | Res :: Def ( hir:: def:: DefKind :: TyParam , _) => true ,
136139 _ => false ,
137140 } )
138141 . unwrap_or ( false ) =>
@@ -143,5 +146,6 @@ impl Visitor<'tcx> for TypeParamSpanVisitor<'tcx> {
143146 } ,
144147 _ => { }
145148 }
149+ hir:: intravisit:: walk_ty ( self , arg) ;
146150 }
147151}
0 commit comments