about summary refs log tree commit diff
path: root/src/librustdoc
diff options
context:
space:
mode:
authorbinarycat <binarycat@envs.net>2025-04-18 20:23:05 -0500
committerbinarycat <binarycat@envs.net>2025-07-24 11:17:14 -0500
commit6a7d4882a207890c75ca09ce19810d90ac9cfde6 (patch)
tree2725cb9f61a6d2c44d589f965e55caefb307c7fd /src/librustdoc
parent041348110e2e526a80efd5adfc2909c716cbb37f (diff)
rustdoc::broken_intra_doc_links: only be lenient with shortcut links
collapsed links and reference links have a pretty particular syntax,
it seems unlikely they would show up on accident.

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
Diffstat (limited to 'src/librustdoc')
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 08f0d4015fc..c9fa3a4837f 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -944,9 +944,10 @@ fn preprocess_link(
     // certain link kinds cannot have their path be urls,
     // so they should not be ignored, no matter how much they look like urls.
     // e.g. [https://example.com/] is not a link to example.com.
-    let can_be_url = ori_link.kind != LinkType::ShortcutUnknown
-        && ori_link.kind != LinkType::CollapsedUnknown
-        && ori_link.kind != LinkType::ReferenceUnknown;
+    let can_be_url = !matches!(
+        ori_link.kind,
+        LinkType::ShortcutUnknown | LinkType::CollapsedUnknown | LinkType::ReferenceUnknown
+    );
 
     // [] is mostly likely not supposed to be a link
     if ori_link.link.is_empty() {
@@ -996,9 +997,25 @@ fn preprocess_link(
         }
     };
 
-    // If there's no backticks, be lenient revert to old behavior.
+    // If there's no backticks, be lenient and revert to the old behavior.
     // This is to prevent churn by linting on stuff that isn't meant to be a link.
-    if (can_be_url || !ori_link.link.contains('`')) && should_ignore_link(path_str) {
+    // only shortcut links have simple enough syntax that they
+    // are likely to be written accidentally, collapsed and reference links
+    // need 4 metachars, and reference links will not usually use
+    // backticks in the reference name.
+    // therefore, only shortcut syntax gets the lenient behavior.
+    //
+    // here's a truth table for how link kinds that cannot be urls are handled:
+    //
+    // |-------------------------------------------------------|
+    // |              |  is shortcut link  | not shortcut link |
+    // |--------------|--------------------|-------------------|
+    // | has backtick |    never ignore    |    never ignore   |
+    // | no backtick  | ignore if url-like |    never ignore   |
+    // |-------------------------------------------------------|
+    let ignore_urllike =
+        can_be_url || (ori_link.kind == LinkType::ShortcutUnknown && !ori_link.link.contains('`'));
+    if ignore_urllike && should_ignore_link(path_str) {
         return None;
     }