Closed
Description
I tried this code:
use std::ops::Deref;
pub struct A;
pub struct B;
impl Deref for A {
type Target = B;
fn deref(&self) -> &Self::Target {
panic!()
}
}
impl Deref for B {
type Target = A;
fn deref(&self) -> &Self::Target {
panic!()
}
}
Trying to run rustdoc with rustdoc lib.rs
I expected to see this happen: I'm not sure actually, probably an ICE, but I'd prefer it either detect and accept recursion, or detect and reject with a proper error message.
Instead, this happened: I get a stack overflow
thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
GDB tells me rustdoc::html::render::sidebar_deref_methods
is on the stack around 17 thousand times
(when running in GDB, it actually segfaulted at <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
instead of stack-overflowing)
impl Deref<Target=A> for A
does not seems to pose problems
Meta
rustc --version --verbose
:
rustc 1.52.0 (88f19c6da 2021-05-03)
binary: rustc
commit-hash: 88f19c6dab716c6281af7602e30f413e809c5974
commit-date: 2021-05-03
host: x86_64-unknown-linux-gnu
release: 1.52.0
LLVM version: 12.0.0