]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #96636 - GuillaumeGomez:fix-jump-to-def-regression, r=notriddle
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 7 May 2022 13:23:45 +0000 (15:23 +0200)
committerGitHub <noreply@github.com>
Sat, 7 May 2022 13:23:45 +0000 (15:23 +0200)
Fix jump to def regression

https://github.com/rust-lang/rust/pull/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``

src/doc/rustdoc/src/unstable-features.md
src/librustdoc/html/render/span_map.rs
src/test/rustdoc/check-source-code-urls-to-def.rs

index 537ab48bbfc12a457dc3e49afb879e203cdb6754..30b3d6defb4b86e0636957e41159eacb38d9acef 100644 (file)
@@ -567,3 +567,10 @@ $ rustdoc src/lib.rs -Z unstable-options \
 
 The example above check every well known names (`target_os`, `doc`, `test`, ... via `names()`)
 and check the values of `feature`: `foo` and `bar`.
+
+### `--generate-link-to-definition`: Generate links on types in source code
+
+ * Tracking issue: [#89095](https://github.com/rust-lang/rust/issues/89095)
+
+This flag enables the generation of links in the source code pages which allow the reader
+to jump to a type definition.
index b5502309560eeb8712b6bc926b3183ec04234485..1ae888d059dc6402e6e00103c15413adccdd2635 100644 (file)
@@ -5,7 +5,7 @@
 use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::DefId;
 use rustc_hir::intravisit::{self, Visitor};
-use rustc_hir::{ExprKind, GenericParam, HirId, Mod, Node};
+use rustc_hir::{ExprKind, HirId, Mod, Node};
 use rustc_middle::hir::nested_filter;
 use rustc_middle::ty::TyCtxt;
 use rustc_span::Span;
@@ -100,8 +100,6 @@ fn nested_visit_map(&mut self) -> Self::Map {
         self.tcx.hir()
     }
 
-    fn visit_generic_param(&mut self, _: &'tcx GenericParam<'tcx>) {}
-
     fn visit_path(&mut self, path: &'tcx rustc_hir::Path<'tcx>, _id: HirId) {
         self.handle_path(path, None);
         intravisit::walk_path(self, path);
index ca4179d403d691362100d0342f1380c6180ecadb..12c5df2871cf5cc0f49f8dd2a5499328f713f082 100644 (file)
@@ -46,6 +46,24 @@ pub fn foo(a: u32, b: &str, c: String, d: Foo, e: bar::Bar, f: source_code::Sour
 // @has - '//a[@href="../../src/foo/auxiliary/source-code-bar.rs.html#14-16"]' 'Trait'
 pub fn foo2<T: bar::sub::Trait, V: Trait>(t: &T, v: &V, b: bool) {}
 
+pub trait AnotherTrait {}
+pub trait WhyNot {}
+
+// @has - '//a[@href="../../src/foo/check-source-code-urls-to-def.rs.html#49"]' 'AnotherTrait'
+// @has - '//a[@href="../../src/foo/check-source-code-urls-to-def.rs.html#50"]' 'WhyNot'
+pub fn foo3<T, V>(t: &T, v: &V)
+where
+    T: AnotherTrait,
+    V: WhyNot
+{}
+
+pub trait AnotherTrait2 {}
+
+// @has - '//a[@href="../../src/foo/check-source-code-urls-to-def.rs.html#60"]' 'AnotherTrait2'
+pub fn foo4() {
+    let x: Vec<AnotherTrait2> = Vec::new();
+}
+
 // @has - '//a[@href="../../foo/primitive.bool.html"]' 'bool'
 #[doc(primitive = "bool")]
 mod whatever {}