about summary refs log tree commit diff
path: root/src/test/rustdoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-11-30 09:00:52 +0000
committerbors <bors@rust-lang.org>2020-11-30 09:00:52 +0000
commitb7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18 (patch)
tree942c74c777f9ea954f387d1e7a9380390393d502 /src/test/rustdoc
parent28b86e0860f0593b85cda6c2c7b03ae8a582962f (diff)
parent2b17f025610077b2b45bdb6401756e404e6c34b2 (diff)
downloadrust-b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18.tar.gz
rust-b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18.zip
Auto merge of #76467 - jyn514:intra-link-self, r=Manishearth
Fix intra-doc links for `Self` on cross-crate items and primitives

- Remove the difference between `parent_item` and `current_item`; these
  should never have been different.
- Remove `current_item` from `resolve` and `variant_field` so that
  `Self` is only substituted in one place at the very start.
- Resolve the current item as a `DefId`, not a `HirId`. This is what
  actually fixed the bug.

Hacks:
- `clean` uses `TypedefItem` when it _really_ should be
  `AssociatedTypeItem`. I tried fixing this without success and hacked
  around it instead (see comments)
- This second-guesses the `to_string()` impl since it wants
  fully-qualified paths. Possibly there's a better way to do this.
Diffstat (limited to 'src/test/rustdoc')
-rw-r--r--src/test/rustdoc/intra-doc-crate/auxiliary/self.rs7
-rw-r--r--src/test/rustdoc/intra-doc-crate/self.rs6
-rw-r--r--src/test/rustdoc/intra-link-prim-self.rs36
3 files changed, 49 insertions, 0 deletions
diff --git a/src/test/rustdoc/intra-doc-crate/auxiliary/self.rs b/src/test/rustdoc/intra-doc-crate/auxiliary/self.rs
new file mode 100644
index 00000000000..cdfe842f3cc
--- /dev/null
+++ b/src/test/rustdoc/intra-doc-crate/auxiliary/self.rs
@@ -0,0 +1,7 @@
+#![crate_name = "cross_crate_self"]
+pub struct S;
+
+impl S {
+    /// Link to [Self::f]
+    pub fn f() {}
+}
diff --git a/src/test/rustdoc/intra-doc-crate/self.rs b/src/test/rustdoc/intra-doc-crate/self.rs
new file mode 100644
index 00000000000..62aef8e85af
--- /dev/null
+++ b/src/test/rustdoc/intra-doc-crate/self.rs
@@ -0,0 +1,6 @@
+// aux-build:self.rs
+
+extern crate cross_crate_self;
+
+// @has self/struct.S.html '//a[@href="../self/struct.S.html#method.f"]' "Self::f"
+pub use cross_crate_self::S;
diff --git a/src/test/rustdoc/intra-link-prim-self.rs b/src/test/rustdoc/intra-link-prim-self.rs
new file mode 100644
index 00000000000..1189d266c53
--- /dev/null
+++ b/src/test/rustdoc/intra-link-prim-self.rs
@@ -0,0 +1,36 @@
+// ignore-tidy-linelength
+#![deny(broken_intra_doc_links)]
+#![feature(lang_items)]
+#![feature(no_core)]
+#![no_core]
+
+#[lang = "usize"]
+/// [Self::f]
+/// [Self::MAX]
+// @has intra_link_prim_self/primitive.usize.html
+// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.usize.html#method.f"]' 'Self::f'
+// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.usize.html#associatedconstant.MAX"]' 'Self::MAX'
+impl usize {
+    /// Some docs
+    pub fn f() {}
+
+    /// 10 and 2^32 are basically the same.
+    pub const MAX: usize = 10;
+
+    // FIXME(#8995) uncomment this when associated types in inherent impls are supported
+    // @ has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.usize.html#associatedtype.ME"]' 'Self::ME'
+    // / [Self::ME]
+    //pub type ME = usize;
+}
+
+#[doc(primitive = "usize")]
+/// This has some docs.
+mod usize {}
+
+/// [S::f]
+/// [Self::f]
+pub struct S;
+
+impl S {
+    pub fn f() {}
+}