about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-04-05 04:39:34 +0000
committerbors <bors@rust-lang.org>2022-04-05 04:39:34 +0000
commit949b98cab8a186b98bf87e64374b8d0848c55271 (patch)
tree53bf1e67c7f27b559b81410fa79086525a0426a0 /src/test
parenta22cf2af0510b3ec4cbb19c3de11d3d8291349d9 (diff)
parentf5ee822098580f4e99bc0c710427727fe9df802c (diff)
downloadrust-949b98cab8a186b98bf87e64374b8d0848c55271.tar.gz
rust-949b98cab8a186b98bf87e64374b8d0848c55271.zip
Auto merge of #95337 - petrochenkov:doclink3, r=camelid
rustdoc: Fix resolution of `crate`-relative paths in doc links

Resolve `crate::foo` paths transparently to rustdoc, so their resolution no longer affects diagnostics and modules used for determining traits in scope.

The proper solution is to account for the current `module_id`/`parent_scope` in `fn resolve_crate_root`, but it's a slightly larger compiler changes. This PR moves the code closer to it, but keeps it rustdoc-specific.

Fixes https://github.com/rust-lang/rust/issues/78696
Fixes https://github.com/rust-lang/rust/issues/94924
Diffstat (limited to 'src/test')
-rw-r--r--src/test/rustdoc-ui/intra-doc/crate-nonexistent.rs5
-rw-r--r--src/test/rustdoc-ui/intra-doc/crate-nonexistent.stderr14
-rw-r--r--src/test/rustdoc/intra-doc/crate-relative-assoc.rs17
3 files changed, 36 insertions, 0 deletions
diff --git a/src/test/rustdoc-ui/intra-doc/crate-nonexistent.rs b/src/test/rustdoc-ui/intra-doc/crate-nonexistent.rs
new file mode 100644
index 00000000000..ceecfa6816c
--- /dev/null
+++ b/src/test/rustdoc-ui/intra-doc/crate-nonexistent.rs
@@ -0,0 +1,5 @@
+#![deny(rustdoc::broken_intra_doc_links)]
+
+/// [crate::DoesNotExist]
+//~^ ERROR unresolved link to `crate::DoesNotExist`
+pub struct Item;
diff --git a/src/test/rustdoc-ui/intra-doc/crate-nonexistent.stderr b/src/test/rustdoc-ui/intra-doc/crate-nonexistent.stderr
new file mode 100644
index 00000000000..a69b1c52ac5
--- /dev/null
+++ b/src/test/rustdoc-ui/intra-doc/crate-nonexistent.stderr
@@ -0,0 +1,14 @@
+error: unresolved link to `crate::DoesNotExist`
+  --> $DIR/crate-nonexistent.rs:3:6
+   |
+LL | /// [crate::DoesNotExist]
+   |      ^^^^^^^^^^^^^^^^^^^ no item named `DoesNotExist` in module `crate_nonexistent`
+   |
+note: the lint level is defined here
+  --> $DIR/crate-nonexistent.rs:1:9
+   |
+LL | #![deny(rustdoc::broken_intra_doc_links)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/rustdoc/intra-doc/crate-relative-assoc.rs b/src/test/rustdoc/intra-doc/crate-relative-assoc.rs
new file mode 100644
index 00000000000..d4a0ecc35ae
--- /dev/null
+++ b/src/test/rustdoc/intra-doc/crate-relative-assoc.rs
@@ -0,0 +1,17 @@
+pub mod io {
+    pub trait Read {
+        fn read(&mut self);
+    }
+}
+
+pub mod bufreader {
+    // @has crate_relative_assoc/bufreader/index.html '//a/@href' 'struct.TcpStream.html#method.read'
+    //! [`crate::TcpStream::read`]
+    use crate::io::Read;
+}
+
+pub struct TcpStream;
+
+impl crate::io::Read for TcpStream {
+    fn read(&mut self) {}
+}