diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index 038ee351545..0fbe090f219 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -236,6 +236,7 @@ fn get_index_type_name(clean_type: &clean::Type) -> Option {
///
/// Important note: It goes through generics recursively. So if you have
/// `T: Option>`, it'll go into `Option` and then into `Result`.
+#[instrument(level = "trace", skip(tcx, res))]
fn add_generics_and_bounds_as_types<'tcx>(
generics: &Generics,
arg: &Type,
@@ -316,6 +317,7 @@ fn add_generics_and_bounds_as_types<'tcx>(
if recurse >= 10 {
// FIXME: remove this whole recurse thing when the recursion bug is fixed
+ // See #59502 for the original issue.
return;
}
diff --git a/src/test/rustdoc-ui/search-index-generics-recursion-bug-issue-59502.rs b/src/test/rustdoc-ui/search-index-generics-recursion-bug-issue-59502.rs
new file mode 100644
index 00000000000..ce51556dd41
--- /dev/null
+++ b/src/test/rustdoc-ui/search-index-generics-recursion-bug-issue-59502.rs
@@ -0,0 +1,11 @@
+// check-pass
+
+// Minimization of issue #59502
+
+trait MyTrait {
+ type Output;
+}
+
+pub fn pow>(arg: T) -> T {
+ arg
+}