about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-10-16 20:15:53 +0200
committerGitHub <noreply@github.com>2024-10-16 20:15:53 +0200
commit87c31feab80f91198b21d1bcaa84546b2f0f2800 (patch)
tree57978a16b19ed1b64bc28dff0e15e8fdb73df6b9 /tests
parent950fb620323aabdb0af5a4cd71b15707788cb385 (diff)
parent10f2395c9ee5849e3a769ce21d3e704191ec8085 (diff)
downloadrust-87c31feab80f91198b21d1bcaa84546b2f0f2800.tar.gz
rust-87c31feab80f91198b21d1bcaa84546b2f0f2800.zip
Rollup merge of #131691 - GuillaumeGomez:intra-doc-link-filter-out-2, r=notriddle
Delay ambiguous intra-doc link resolution after `Cache` has been populated

Fixes https://github.com/rust-lang/rust/issues/130233.

I was getting nowhere with #130278. I took a wrong turn at some point and ended making way too many changes so instead I started again back from 0 and this time it worked out as expected.

r? ```@notriddle```
Diffstat (limited to 'tests')
-rw-r--r--tests/rustdoc-ui/intra-doc/filter-out-private-2.rs15
-rw-r--r--tests/rustdoc-ui/intra-doc/filter-out-private-2.stderr14
-rw-r--r--tests/rustdoc-ui/intra-doc/filter-out-private.rs13
-rw-r--r--tests/rustdoc-ui/intra-doc/filter-out-private.stderr22
-rw-r--r--tests/rustdoc/intra-doc/filter-out-private.rs26
5 files changed, 90 insertions, 0 deletions
diff --git a/tests/rustdoc-ui/intra-doc/filter-out-private-2.rs b/tests/rustdoc-ui/intra-doc/filter-out-private-2.rs
new file mode 100644
index 00000000000..9d8edbf6b5d
--- /dev/null
+++ b/tests/rustdoc-ui/intra-doc/filter-out-private-2.rs
@@ -0,0 +1,15 @@
+// This test ensures that ambiguities (not) resolved at a later stage still emit an error.
+
+#![deny(rustdoc::broken_intra_doc_links)]
+#![crate_name = "foo"]
+
+#[doc(hidden)]
+pub struct Thing {}
+
+#[allow(non_snake_case)]
+#[doc(hidden)]
+pub fn Thing() {}
+
+/// Do stuff with [`Thing`].
+//~^ ERROR all items matching `Thing` are private or doc(hidden)
+pub fn repro(_: Thing) {}
diff --git a/tests/rustdoc-ui/intra-doc/filter-out-private-2.stderr b/tests/rustdoc-ui/intra-doc/filter-out-private-2.stderr
new file mode 100644
index 00000000000..1a49c90a172
--- /dev/null
+++ b/tests/rustdoc-ui/intra-doc/filter-out-private-2.stderr
@@ -0,0 +1,14 @@
+error: all items matching `Thing` are private or doc(hidden)
+  --> $DIR/filter-out-private-2.rs:13:21
+   |
+LL | /// Do stuff with [`Thing`].
+   |                     ^^^^^ unresolved link
+   |
+note: the lint level is defined here
+  --> $DIR/filter-out-private-2.rs:3:9
+   |
+LL | #![deny(rustdoc::broken_intra_doc_links)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/rustdoc-ui/intra-doc/filter-out-private.rs b/tests/rustdoc-ui/intra-doc/filter-out-private.rs
new file mode 100644
index 00000000000..f481b51dad0
--- /dev/null
+++ b/tests/rustdoc-ui/intra-doc/filter-out-private.rs
@@ -0,0 +1,13 @@
+// This test ensures that ambiguities resolved at a later stage still emit an error.
+
+#![deny(rustdoc::broken_intra_doc_links)]
+#![crate_name = "foo"]
+
+pub struct Thing {}
+
+#[allow(non_snake_case)]
+pub fn Thing() {}
+
+/// Do stuff with [`Thing`].
+//~^ ERROR `Thing` is both a function and a struct
+pub fn repro(_: Thing) {}
diff --git a/tests/rustdoc-ui/intra-doc/filter-out-private.stderr b/tests/rustdoc-ui/intra-doc/filter-out-private.stderr
new file mode 100644
index 00000000000..1d1830b1f1c
--- /dev/null
+++ b/tests/rustdoc-ui/intra-doc/filter-out-private.stderr
@@ -0,0 +1,22 @@
+error: `Thing` is both a function and a struct
+  --> $DIR/filter-out-private.rs:11:21
+   |
+LL | /// Do stuff with [`Thing`].
+   |                     ^^^^^ ambiguous link
+   |
+note: the lint level is defined here
+  --> $DIR/filter-out-private.rs:3:9
+   |
+LL | #![deny(rustdoc::broken_intra_doc_links)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: to link to the function, add parentheses
+   |
+LL | /// Do stuff with [`Thing()`].
+   |                          ++
+help: to link to the struct, prefix with `struct@`
+   |
+LL | /// Do stuff with [`struct@Thing`].
+   |                     +++++++
+
+error: aborting due to 1 previous error
+
diff --git a/tests/rustdoc/intra-doc/filter-out-private.rs b/tests/rustdoc/intra-doc/filter-out-private.rs
new file mode 100644
index 00000000000..70591b120d8
--- /dev/null
+++ b/tests/rustdoc/intra-doc/filter-out-private.rs
@@ -0,0 +1,26 @@
+// This test ensures that private/hidden items don't create ambiguity.
+// This is a regression test for <https://github.com/rust-lang/rust/issues/130233>.
+
+#![deny(rustdoc::broken_intra_doc_links)]
+#![crate_name = "foo"]
+
+pub struct Thing {}
+
+#[doc(hidden)]
+#[allow(non_snake_case)]
+pub fn Thing() {}
+
+pub struct Bar {}
+
+#[allow(non_snake_case)]
+fn Bar() {}
+
+//@ has 'foo/fn.repro.html'
+//@ has - '//*[@class="toggle top-doc"]/*[@class="docblock"]//a/@href' 'struct.Thing.html'
+/// Do stuff with [`Thing`].
+pub fn repro(_: Thing) {}
+
+//@ has 'foo/fn.repro2.html'
+//@ has - '//*[@class="toggle top-doc"]/*[@class="docblock"]//a/@href' 'struct.Bar.html'
+/// Do stuff with [`Bar`].
+pub fn repro2(_: Bar) {}