@@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
4
4
use rustc_hir:: def:: { DefKind , Res } ;
5
5
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
6
6
use 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 } ;
8
8
use rustc_middle:: hir:: nested_filter;
9
9
use rustc_middle:: ty:: TyCtxt ;
10
10
use rustc_span:: hygiene:: MacroKind ;
@@ -170,7 +170,7 @@ impl SpanMapVisitor<'_> {
170
170
true
171
171
}
172
172
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 ) {
174
174
let hir = self . tcx . hir ( ) ;
175
175
let body_id = hir. enclosing_body_owner ( hir_id) ;
176
176
// FIXME: this is showing error messages for parts of the code that are not
@@ -189,6 +189,27 @@ impl SpanMapVisitor<'_> {
189
189
self . matches . insert ( span, link) ;
190
190
}
191
191
}
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
+ }
192
213
}
193
214
194
215
impl < ' tcx > Visitor < ' tcx > for SpanMapVisitor < ' tcx > {
@@ -206,6 +227,10 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
206
227
intravisit:: walk_path ( self , path) ;
207
228
}
208
229
230
+ fn visit_pat ( & mut self , p : & Pat < ' tcx > ) {
231
+ self . handle_pat ( p) ;
232
+ }
233
+
209
234
fn visit_mod ( & mut self , m : & ' tcx Mod < ' tcx > , span : Span , id : HirId ) {
210
235
// To make the difference between "mod foo {}" and "mod foo;". In case we "import" another
211
236
// 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> {
228
253
fn visit_expr ( & mut self , expr : & ' tcx rustc_hir:: Expr < ' tcx > ) {
229
254
match expr. kind {
230
255
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 )
232
257
}
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 ) ,
234
259
_ => {
235
260
if self . handle_macro ( expr. span ) {
236
261
// We don't want to go deeper into the macro.
0 commit comments