diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index ebb4cfb7d48bd..7e53cf231a14e 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1960,13 +1960,19 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { .filter(|i| i.inner_impl().trait_.is_some()) .find(|i| i.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_trait_did) { - sidebar_deref_methods(cx, out, impl_, v); + sidebar_deref_methods(cx, out, impl_, v, FxHashSet::default()); } } } } -fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &Vec) { +fn sidebar_deref_methods( + cx: &Context<'_>, + out: &mut Buffer, + impl_: &Impl, + v: &Vec, + mut already_seen: FxHashSet, +) { let c = cx.cache(); debug!("found Deref: {:?}", impl_); @@ -2032,7 +2038,15 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V .filter(|i| i.inner_impl().trait_.is_some()) .find(|i| i.inner_impl().trait_.def_id_full(c) == c.deref_trait_did) { - sidebar_deref_methods(cx, out, target_deref_impl, target_impls); + if already_seen.insert(target_did.clone()) { + sidebar_deref_methods( + cx, + out, + target_deref_impl, + target_impls, + already_seen, + ); + } } } } diff --git a/src/test/rustdoc/issue-85095.rs b/src/test/rustdoc/issue-85095.rs new file mode 100644 index 0000000000000..5c4a1da9e596d --- /dev/null +++ b/src/test/rustdoc/issue-85095.rs @@ -0,0 +1,22 @@ +use std::ops::Deref; + +pub struct A; +pub struct B; + +// @has issue_85095/struct.A.html '//code' 'impl Deref for A' +impl Deref for A { + type Target = B; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// @has issue_85095/struct.B.html '//code' 'impl Deref for B' +impl Deref for B { + type Target = A; + + fn deref(&self) -> &Self::Target { + panic!() + } +}