about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustdoc/html/format.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index be8a2d511e9..f4cf819fc59 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -368,6 +368,8 @@ pub(crate) enum HrefError {
     Private,
     // Not in external cache, href link should be in same page
     NotInExternalCache,
+    /// Refers to an unnamable item, such as one defined within a function or const block.
+    UnnamableItem,
 }
 
 /// This function is to get the external macro path because they are not in the cache used in
@@ -498,7 +500,13 @@ fn url_parts(
             builder.extend(module_fqp.iter().copied());
             Ok(builder)
         }
-        ExternalLocation::Local => Ok(href_relative_parts(module_fqp, relative_to)),
+        ExternalLocation::Local => {
+            if module_fqp.iter().any(|sym| sym.as_str() == "_") {
+                Err(HrefError::UnnamableItem)
+            } else {
+                Ok(href_relative_parts(module_fqp, relative_to))
+            }
+        }
         ExternalLocation::Unknown => Err(HrefError::DocumentationNotBuilt),
     }
 }