Skip to content

Commit 4762694

Browse files
committed
rustdoc: never try to link to unnamable types
1 parent 293f95f commit 4762694

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/librustdoc/html/format.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ pub(crate) enum HrefError {
368368
Private,
369369
// Not in external cache, href link should be in same page
370370
NotInExternalCache,
371+
/// Refers to an unnamable item, such as one defined within a function or const block.
372+
UnnamableItem,
371373
}
372374

373375
/// 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(
498500
builder.extend(module_fqp.iter().copied());
499501
Ok(builder)
500502
}
501-
ExternalLocation::Local => Ok(href_relative_parts(module_fqp, relative_to)),
503+
ExternalLocation::Local => {
504+
if module_fqp.iter().any(|sym| sym.as_str() == "_") {
505+
Err(HrefError::UnnamableItem)
506+
} else {
507+
Ok(href_relative_parts(module_fqp, relative_to))
508+
}
509+
}
502510
ExternalLocation::Unknown => Err(HrefError::DocumentationNotBuilt),
503511
}
504512
}

0 commit comments

Comments
 (0)