diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index 6ebd9a5ab9da5..0991778f87d79 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -1771,13 +1771,15 @@ pub(crate) fn build_index(
assert!(ty.generics.is_some());
return;
};
- ty.id = convert_render_type_id(
- id,
- cache,
- serialized_index,
- used_in_function_signature,
- tcx,
- );
+ ty.id = if let RenderTypeId::DefId(def_id) = id
+ && matches!(tcx.def_kind(def_id), rustc_hir::def::DefKind::OpaqueTy)
+ {
+ // We exclude opaque types as they cannot have attributes, so no need to call
+ // `convert_render_type_id`.
+ None
+ } else {
+ convert_render_type_id(id, cache, serialized_index, used_in_function_signature, tcx)
+ };
use crate::clean::PrimitiveType;
// These cases are added to the inverted index, but not actually included
// in the signature. There's a matching set of cases in the
diff --git a/tests/rustdoc-js/auxiliary/opaque.rs b/tests/rustdoc-js/auxiliary/opaque.rs
new file mode 100644
index 0000000000000..b1f8e825e716a
--- /dev/null
+++ b/tests/rustdoc-js/auxiliary/opaque.rs
@@ -0,0 +1,9 @@
+pub struct Item(pub B);
+
+pub struct Container(pub B);
+
+impl Container {
+ pub fn get_item(&self) -> Result- , ()> {
+ Ok(Item(0))
+ }
+}
diff --git a/tests/rustdoc-js/opaque.js b/tests/rustdoc-js/opaque.js
new file mode 100644
index 0000000000000..b732c0eb10520
--- /dev/null
+++ b/tests/rustdoc-js/opaque.js
@@ -0,0 +1,10 @@
+// exact-check
+
+const EXPECTED = [
+ {
+ 'query': 'Container -> Result
- >',
+ 'others': [
+ { 'path': 'foo::Container', 'name': 'get_item' },
+ ],
+ },
+];
diff --git a/tests/rustdoc-js/opaque.rs b/tests/rustdoc-js/opaque.rs
new file mode 100644
index 0000000000000..741f6e9b1860e
--- /dev/null
+++ b/tests/rustdoc-js/opaque.rs
@@ -0,0 +1,10 @@
+// This test ensures that rustdoc doesn't crash when building the search index
+// when an opaque type is being reexported from a dependency.
+// Regression test for .
+
+//@ aux-build: opaque.rs
+
+#![crate_name = "foo"]
+
+extern crate opaque;
+pub use opaque::*;