Skip to content

Commit f6525a6

Browse files
Enable "jump to def" feature on patterns
1 parent 7029347 commit f6525a6

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/librustdoc/html/render/span_map.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
66
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};
88
use rustc_middle::hir::nested_filter;
99
use rustc_middle::ty::TyCtxt;
1010
use rustc_span::hygiene::MacroKind;
@@ -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.handle_call(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

194215
impl<'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.

0 commit comments

Comments
 (0)