Skip to content

Commit

Permalink
fix rustdoc stack overflow on mutually recursive Deref
Browse files Browse the repository at this point in the history
fix #85095
  • Loading branch information
trinity-1686a committed Jun 15, 2021
1 parent 9089771 commit aee50f4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/librustdoc/html/render/mod.rs
Expand Up @@ -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<Impl>) {
fn sidebar_deref_methods(
cx: &Context<'_>,
out: &mut Buffer,
impl_: &Impl,
v: &Vec<Impl>,
mut already_seen: FxHashSet<DefId>,
) {
let c = cx.cache();

debug!("found Deref: {:?}", impl_);
Expand Down Expand Up @@ -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,
);
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions 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!()
}
}

0 comments on commit aee50f4

Please sign in to comment.