Skip to content

Commit

Permalink
Fix items with generics not having their jump to def link generated
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 18, 2024
1 parent 8ea0257 commit 786b747
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/librustdoc/html/render/span_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub(crate) fn collect_spans_and_sources(
include_sources: bool,
generate_link_to_definition: bool,
) -> (FxIndexMap<PathBuf, String>, FxHashMap<Span, LinkFromSrc>) {
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };

if include_sources {
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };

if generate_link_to_definition {
tcx.hir().walk_toplevel_module(&mut visitor);
}
Expand Down Expand Up @@ -76,7 +76,22 @@ impl<'tcx> SpanMapVisitor<'tcx> {
} else {
LinkFromSrc::External(def_id)
};
self.matches.insert(path.span, link);
// In case the path ends with generics, we remove them from the span.
let span = path
.segments
.last()
.map(|last| {
// In `use` statements, the included item is not in the path segments.
// However, it doesn't matter because you can't have generics on `use`
// statements.
if path.span.contains(last.ident.span) {
path.span.with_hi(last.ident.span.hi())
} else {
path.span
}
})
.unwrap_or(path.span);
self.matches.insert(span, link);
}
Res::Local(_) => {
if let Some(span) = self.tcx.hir().res_span(path.res) {
Expand Down

0 comments on commit 786b747

Please sign in to comment.