diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index bcb3e57c84428..aff6a4ddabae8 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -367,6 +367,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,
}
// Panics if `syms` is empty.
@@ -509,7 +511,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),
}
}
diff --git a/tests/rustdoc/reexport/auxiliary/wrap-unnamable-type.rs b/tests/rustdoc/reexport/auxiliary/wrap-unnamable-type.rs
new file mode 100644
index 0000000000000..8ce0a0de54484
--- /dev/null
+++ b/tests/rustdoc/reexport/auxiliary/wrap-unnamable-type.rs
@@ -0,0 +1,12 @@
+pub trait Assoc {
+ type Ty;
+}
+
+pub struct Foo(::Ty);
+
+const _: () = {
+ impl crate::Assoc for Foo {
+ type Ty = Bar;
+ }
+ pub struct Bar;
+};
diff --git a/tests/rustdoc/reexport/wrapped-unnamble-type-143222.rs b/tests/rustdoc/reexport/wrapped-unnamble-type-143222.rs
new file mode 100644
index 0000000000000..005a5c0b98add
--- /dev/null
+++ b/tests/rustdoc/reexport/wrapped-unnamble-type-143222.rs
@@ -0,0 +1,12 @@
+//@ compile-flags: -Z normalize-docs --document-private-items -Zunstable-options --show-type-layout
+//@ aux-build:wrap-unnamable-type.rs
+//@ build-aux-docs
+
+#![crate_name = "foo"]
+
+extern crate wrap_unnamable_type as helper;
+//extern crate helper;
+//@ has 'foo/struct.Foo.html'
+//@ !hasraw - '_/struct.Bar.html'
+#[doc(inline)]
+pub use helper::Foo;