Skip to content

Commit 966361f

Browse files
committed
Auto merge of #86322 - trinity-1686a:rustdoc-fix-overflow-recursive-deref, r=jyn514
fix rustdoc stack overflow on mutually recursive Deref fix #85095 fix #85037
2 parents ed33787 + 5f7d441 commit 966361f

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

src/librustdoc/html/render/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -1997,19 +1997,6 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
19971997
out.push_str("</div>");
19981998
}
19991999
}
2000-
2001-
// Recurse into any further impls that might exist for `target`
2002-
if let Some(target_did) = target.def_id_full(c) {
2003-
if let Some(target_impls) = c.impls.get(&target_did) {
2004-
if let Some(target_deref_impl) = target_impls
2005-
.iter()
2006-
.filter(|i| i.inner_impl().trait_.is_some())
2007-
.find(|i| i.inner_impl().trait_.def_id_full(c) == c.deref_trait_did)
2008-
{
2009-
sidebar_deref_methods(cx, out, target_deref_impl, target_impls);
2010-
}
2011-
}
2012-
}
20132000
}
20142001
}
20152002

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use std::ops::Deref;
2+
3+
pub struct A {}
4+
impl A { pub fn foo_a(&self) {} }
5+
6+
pub struct B {}
7+
impl B { pub fn foo_b(&self) {} }
8+
9+
pub struct C {}
10+
impl C { pub fn foo_c(&self) {} }
11+
12+
// @has recursive_deref_sidebar/struct.A.html '//div[@class="sidebar-links"]' 'foo_b'
13+
impl Deref for A {
14+
type Target = B;
15+
fn deref(&self) -> &B { todo!() }
16+
}
17+
18+
// @!has recursive_deref_sidebar/struct.A.html '//div[@class="sidebar-links"]' 'foo_c'
19+
impl Deref for B {
20+
type Target = C;
21+
fn deref(&self) -> &C { todo!() }
22+
}

src/test/rustdoc/recursive-deref.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use std::ops::Deref;
2+
3+
pub struct A;
4+
pub struct B;
5+
6+
// @has recursive_deref/struct.A.html '//code' 'impl Deref for A'
7+
impl Deref for A {
8+
type Target = B;
9+
10+
fn deref(&self) -> &Self::Target {
11+
panic!()
12+
}
13+
}
14+
15+
// @has recursive_deref/struct.B.html '//code' 'impl Deref for B'
16+
impl Deref for B {
17+
type Target = A;
18+
19+
fn deref(&self) -> &Self::Target {
20+
panic!()
21+
}
22+
}

0 commit comments

Comments
 (0)