@@ -4,9 +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:: {
8- ExprKind , HirId , Item , ItemKind , Mod , Node , Pat , PatExpr , PatExprKind , PatKind , QPath ,
9- } ;
7+ use rustc_hir:: { ExprKind , HirId , Item , ItemKind , Mod , Node , QPath } ;
108use rustc_middle:: hir:: nested_filter;
119use rustc_middle:: ty:: TyCtxt ;
1210use rustc_span:: hygiene:: MacroKind ;
@@ -189,31 +187,6 @@ impl SpanMapVisitor<'_> {
189187 self . matches . insert ( span, link) ;
190188 }
191189 }
192-
193- fn handle_pat ( & mut self , p : & Pat < ' _ > ) {
194- let mut check_qpath = |qpath, hir_id| match qpath {
195- QPath :: TypeRelative ( _, path) if matches ! ( path. res, Res :: Err ) => {
196- self . infer_id ( path. hir_id , Some ( hir_id) , qpath. span ( ) ) ;
197- }
198- QPath :: Resolved ( _, path) => self . handle_path ( path) ,
199- _ => { }
200- } ;
201- match p. kind {
202- PatKind :: Binding ( _, _, _, Some ( p) ) => self . handle_pat ( p) ,
203- PatKind :: Struct ( qpath, _, _) | PatKind :: TupleStruct ( qpath, _, _) => {
204- check_qpath ( qpath, p. hir_id )
205- }
206- PatKind :: Expr ( PatExpr { kind : PatExprKind :: Path ( qpath) , hir_id, .. } ) => {
207- check_qpath ( * qpath, * hir_id)
208- }
209- PatKind :: Or ( pats) => {
210- for pat in pats {
211- self . handle_pat ( pat) ;
212- }
213- }
214- _ => { }
215- }
216- }
217190}
218191
219192impl < ' tcx > Visitor < ' tcx > for SpanMapVisitor < ' tcx > {
@@ -231,8 +204,36 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
231204 intravisit:: walk_path ( self , path) ;
232205 }
233206
234- fn visit_pat ( & mut self , p : & Pat < ' tcx > ) {
235- self . handle_pat ( p) ;
207+ fn visit_qpath ( & mut self , qpath : & QPath < ' tcx > , id : HirId , span : Span ) {
208+ match * qpath {
209+ QPath :: TypeRelative ( qself, path) => {
210+ if matches ! ( path. res, Res :: Err ) {
211+ let tcx = self . tcx ;
212+ let hir = tcx. hir ( ) ;
213+ let body_id = hir. enclosing_body_owner ( id) ;
214+ let typeck_results = tcx. typeck_body ( hir. body_owned_by ( body_id) . id ( ) ) ;
215+ let path = rustc_hir:: Path {
216+ // We change the span to not include parens.
217+ span : span. with_hi ( path. ident . span . hi ( ) ) ,
218+ res : typeck_results. qpath_res ( qpath, id) ,
219+ segments : & [ ] ,
220+ } ;
221+ self . handle_path ( & path) ;
222+ } else {
223+ self . infer_id ( path. hir_id , Some ( id) , span) ;
224+ }
225+
226+ rustc_ast:: visit:: try_visit!( self . visit_ty( qself) ) ;
227+ self . visit_path_segment ( path) ;
228+ }
229+ QPath :: Resolved ( maybe_qself, path) => {
230+ self . handle_path ( path) ;
231+
232+ rustc_ast:: visit:: visit_opt!( self , visit_ty, maybe_qself) ;
233+ self . visit_path ( path, id)
234+ }
235+ _ => { }
236+ }
236237 }
237238
238239 fn visit_mod ( & mut self , m : & ' tcx Mod < ' tcx > , span : Span , id : HirId ) {
0 commit comments