about summary refs log tree commit diff
path: root/tests/rustdoc-ui
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-05-27 15:17:22 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-06-23 16:02:33 +0200
commita0d64177f023d0f141044dd57eace3ca386a36f1 (patch)
treec69ad15bc0620ec7e6db39cdebad5954f81d7268 /tests/rustdoc-ui
parent7e683cc4d1f8dff6c777b2eecec4c1173dbff1db (diff)
downloadrust-a0d64177f023d0f141044dd57eace3ca386a36f1.tar.gz
rust-a0d64177f023d0f141044dd57eace3ca386a36f1.zip
Add ui test for `redundant_explicit_links` rustdoc lint for items coming from expansion
Diffstat (limited to 'tests/rustdoc-ui')
-rw-r--r--tests/rustdoc-ui/lints/redundant_explicit_links-expansion.rs28
-rw-r--r--tests/rustdoc-ui/lints/redundant_explicit_links-expansion.stderr23
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/rustdoc-ui/lints/redundant_explicit_links-expansion.rs b/tests/rustdoc-ui/lints/redundant_explicit_links-expansion.rs
new file mode 100644
index 00000000000..8cb75ba4e18
--- /dev/null
+++ b/tests/rustdoc-ui/lints/redundant_explicit_links-expansion.rs
@@ -0,0 +1,28 @@
+// This is a regression test for <https://github.com/rust-lang/rust/issues/141553>.
+// If the link is generated from expansion, we should not emit the lint.
+
+#![deny(rustdoc::redundant_explicit_links)]
+
+macro_rules! mac1 {
+    () => {
+        "provided by a [`BufferProvider`](crate::BufferProvider)."
+    };
+}
+
+macro_rules! mac2 {
+    () => {
+        #[doc = mac1!()]
+        pub struct BufferProvider;
+    }
+}
+
+// Should not lint.
+#[doc = mac1!()]
+pub struct Foo;
+
+// Should not lint.
+mac2!{}
+
+#[doc = "provided by a [`BufferProvider`](crate::BufferProvider)."]
+//~^ ERROR: redundant_explicit_links
+pub struct Bla;
diff --git a/tests/rustdoc-ui/lints/redundant_explicit_links-expansion.stderr b/tests/rustdoc-ui/lints/redundant_explicit_links-expansion.stderr
new file mode 100644
index 00000000000..0a38ec2aa6a
--- /dev/null
+++ b/tests/rustdoc-ui/lints/redundant_explicit_links-expansion.stderr
@@ -0,0 +1,23 @@
+error: redundant explicit link target
+  --> $DIR/redundant_explicit_links-expansion.rs:26:43
+   |
+LL | #[doc = "provided by a [`BufferProvider`](crate::BufferProvider)."]
+   |                         ----------------  ^^^^^^^^^^^^^^^^^^^^^ explicit target is redundant
+   |                         |
+   |                         because label contains path that resolves to same destination
+   |
+   = note: when a link's destination is not specified,
+           the label is used to resolve intra-doc links
+note: the lint level is defined here
+  --> $DIR/redundant_explicit_links-expansion.rs:4:9
+   |
+LL | #![deny(rustdoc::redundant_explicit_links)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: remove explicit link target
+   |
+LL - #[doc = "provided by a [`BufferProvider`](crate::BufferProvider)."]
+LL + #[doc = "provided by a [`BufferProvider`]."]
+   |
+
+error: aborting due to 1 previous error
+