@@ -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 } ;
7+ use rustc_hir:: { ExprKind , HirId , Item , ItemKind , Mod , Node , Pat , PatKind , QPath } ;
88use rustc_middle:: hir:: nested_filter;
99use rustc_middle:: ty:: TyCtxt ;
1010use rustc_span:: hygiene:: MacroKind ;
@@ -170,7 +170,7 @@ impl SpanMapVisitor<'_> {
170170 true
171171 }
172172
173- fn handle_call ( & mut self , hir_id : HirId , expr_hir_id : Option < HirId > , span : Span ) {
173+ fn infer_id ( & mut self , hir_id : HirId , expr_hir_id : Option < HirId > , span : Span ) {
174174 let hir = self . tcx . hir ( ) ;
175175 let body_id = hir. enclosing_body_owner ( hir_id) ;
176176 // FIXME: this is showing error messages for parts of the code that are not
@@ -189,6 +189,27 @@ 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+ }
192213}
193214
194215impl < ' tcx > Visitor < ' tcx > for SpanMapVisitor < ' tcx > {
@@ -206,6 +227,10 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
206227 intravisit:: walk_path ( self , path) ;
207228 }
208229
230+ fn visit_pat ( & mut self , p : & Pat < ' tcx > ) {
231+ self . handle_pat ( p) ;
232+ }
233+
209234 fn visit_mod ( & mut self , m : & ' tcx Mod < ' tcx > , span : Span , id : HirId ) {
210235 // To make the difference between "mod foo {}" and "mod foo;". In case we "import" another
211236 // file, we want to link to it. Otherwise no need to create a link.
@@ -228,9 +253,9 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
228253 fn visit_expr ( & mut self , expr : & ' tcx rustc_hir:: Expr < ' tcx > ) {
229254 match expr. kind {
230255 ExprKind :: MethodCall ( segment, ..) => {
231- self . handle_call ( segment. hir_id , Some ( expr. hir_id ) , segment. ident . span )
256+ self . infer_id ( segment. hir_id , Some ( expr. hir_id ) , segment. ident . span )
232257 }
233- ExprKind :: Call ( call, ..) => self . handle_call ( call. hir_id , None , call. span ) ,
258+ ExprKind :: Call ( call, ..) => self . infer_id ( call. hir_id , None , call. span ) ,
234259 _ => {
235260 if self . handle_macro ( expr. span ) {
236261 // We don't want to go deeper into the macro.
0 commit comments