Skip to content

Commit 8d67df1

Browse files
Rollup merge of rust-lang#96636 - GuillaumeGomez:fix-jump-to-def-regression, r=notriddle
Fix jump to def regression rust-lang#93803 introduced a regression in the "jump to def" feature. This fixes it. Nice side-effect: it adds a new regression test. :) I also used this opportunity to add documentation about this unstable feature in the rustdoc book. cc `@cjgillot` r? `@notriddle`
2 parents 3cdf7e9 + 3bfa2eb commit 8d67df1

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/doc/rustdoc/src/unstable-features.md

+7
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,10 @@ $ rustdoc src/lib.rs -Z unstable-options \
567567

568568
The example above check every well known names (`target_os`, `doc`, `test`, ... via `names()`)
569569
and check the values of `feature`: `foo` and `bar`.
570+
571+
### `--generate-link-to-definition`: Generate links on types in source code
572+
573+
* Tracking issue: [#89095](https://github.com/rust-lang/rust/issues/89095)
574+
575+
This flag enables the generation of links in the source code pages which allow the reader
576+
to jump to a type definition.

src/librustdoc/html/render/span_map.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
55
use rustc_hir::def::{DefKind, Res};
66
use rustc_hir::def_id::DefId;
77
use rustc_hir::intravisit::{self, Visitor};
8-
use rustc_hir::{ExprKind, GenericParam, HirId, Mod, Node};
8+
use rustc_hir::{ExprKind, HirId, Mod, Node};
99
use rustc_middle::hir::nested_filter;
1010
use rustc_middle::ty::TyCtxt;
1111
use rustc_span::Span;
@@ -100,8 +100,6 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
100100
self.tcx.hir()
101101
}
102102

103-
fn visit_generic_param(&mut self, _: &'tcx GenericParam<'tcx>) {}
104-
105103
fn visit_path(&mut self, path: &'tcx rustc_hir::Path<'tcx>, _id: HirId) {
106104
self.handle_path(path, None);
107105
intravisit::walk_path(self, path);

src/test/rustdoc/check-source-code-urls-to-def.rs

+18
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ pub fn foo(a: u32, b: &str, c: String, d: Foo, e: bar::Bar, f: source_code::Sour
4646
// @has - '//a[@href="../../src/foo/auxiliary/source-code-bar.rs.html#14-16"]' 'Trait'
4747
pub fn foo2<T: bar::sub::Trait, V: Trait>(t: &T, v: &V, b: bool) {}
4848

49+
pub trait AnotherTrait {}
50+
pub trait WhyNot {}
51+
52+
// @has - '//a[@href="../../src/foo/check-source-code-urls-to-def.rs.html#49"]' 'AnotherTrait'
53+
// @has - '//a[@href="../../src/foo/check-source-code-urls-to-def.rs.html#50"]' 'WhyNot'
54+
pub fn foo3<T, V>(t: &T, v: &V)
55+
where
56+
T: AnotherTrait,
57+
V: WhyNot
58+
{}
59+
60+
pub trait AnotherTrait2 {}
61+
62+
// @has - '//a[@href="../../src/foo/check-source-code-urls-to-def.rs.html#60"]' 'AnotherTrait2'
63+
pub fn foo4() {
64+
let x: Vec<AnotherTrait2> = Vec::new();
65+
}
66+
4967
// @has - '//a[@href="../../foo/primitive.bool.html"]' 'bool'
5068
#[doc(primitive = "bool")]
5169
mod whatever {}

0 commit comments

Comments
 (0)