@@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
44use rustc_hir:: def:: { DefKind , Res } ;
55use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
66use rustc_hir:: intravisit:: { self , Visitor } ;
7- use rustc_hir:: { ExprKind , HirId , Item , ItemKind , Mod , Node , Pat , PatKind , QPath } ;
7+ use rustc_hir:: { ExprKind , HirId , Item , ItemKind , Mod , Node , QPath } ;
88use rustc_middle:: hir:: nested_filter;
99use rustc_middle:: ty:: TyCtxt ;
1010use rustc_span:: hygiene:: MacroKind ;
@@ -189,27 +189,6 @@ impl SpanMapVisitor<'_> {
189189 self . matches . insert ( span, link) ;
190190 }
191191 }
192-
193- fn handle_pat ( & mut self , p : & Pat < ' _ > ) {
194- match p. kind {
195- PatKind :: Binding ( _, _, _, Some ( p) ) => self . handle_pat ( p) ,
196- PatKind :: Struct ( qpath, _, _)
197- | PatKind :: TupleStruct ( qpath, _, _)
198- | PatKind :: Path ( qpath) => match qpath {
199- QPath :: TypeRelative ( _, path) if matches ! ( path. res, Res :: Err ) => {
200- self . infer_id ( path. hir_id , Some ( p. hir_id ) , qpath. span ( ) ) ;
201- }
202- QPath :: Resolved ( _, path) => self . handle_path ( path) ,
203- _ => { }
204- } ,
205- PatKind :: Or ( pats) => {
206- for pat in pats {
207- self . handle_pat ( pat) ;
208- }
209- }
210- _ => { }
211- }
212- }
213192}
214193
215194impl < ' tcx > Visitor < ' tcx > for SpanMapVisitor < ' tcx > {
@@ -227,8 +206,36 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
227206 intravisit:: walk_path ( self , path) ;
228207 }
229208
230- fn visit_pat ( & mut self , p : & Pat < ' tcx > ) {
231- self . handle_pat ( p) ;
209+ fn visit_qpath ( & mut self , qpath : & QPath < ' tcx > , id : HirId , span : Span ) {
210+ match * qpath {
211+ QPath :: TypeRelative ( qself, path) => {
212+ if matches ! ( path. res, Res :: Err ) {
213+ let tcx = self . tcx ;
214+ let hir = tcx. hir ( ) ;
215+ let body_id = hir. enclosing_body_owner ( id) ;
216+ let typeck_results = tcx. typeck_body ( hir. body_owned_by ( body_id) . id ( ) ) ;
217+ let path = rustc_hir:: Path {
218+ // We change the span to not include parens.
219+ span : span. with_hi ( path. ident . span . hi ( ) ) ,
220+ res : typeck_results. qpath_res ( qpath, id) ,
221+ segments : & [ ] ,
222+ } ;
223+ self . handle_path ( & path) ;
224+ } else {
225+ self . infer_id ( path. hir_id , Some ( id) , span) ;
226+ }
227+
228+ rustc_ast:: visit:: try_visit!( self . visit_ty( qself) ) ;
229+ self . visit_path_segment ( path) ;
230+ }
231+ QPath :: Resolved ( maybe_qself, path) => {
232+ self . handle_path ( path) ;
233+
234+ rustc_ast:: visit:: visit_opt!( self , visit_ty, maybe_qself) ;
235+ self . visit_path ( path, id)
236+ }
237+ _ => { }
238+ }
232239 }
233240
234241 fn visit_mod ( & mut self , m : & ' tcx Mod < ' tcx > , span : Span , id : HirId ) {
0 commit comments