Skip to content

rustdoc stack overflow on mutually recusive Deref implementation #85095

Closed
@trinity-1686a

Description

@trinity-1686a

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions