Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc stack overflow on mutually recusive Deref implementation #85095

Closed
trinity-1686a opened this issue May 8, 2021 · 3 comments · Fixed by #86322
Closed

rustdoc stack overflow on mutually recusive Deref implementation #85095

trinity-1686a opened this issue May 8, 2021 · 3 comments · Fixed by #86322
Labels
C-bug Category: This is a bug.

Comments

@trinity-1686a
Copy link
Contributor

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
@trinity-1686a trinity-1686a added the C-bug Category: This is a bug. label May 8, 2021
@jyn514
Copy link
Member

jyn514 commented May 9, 2021

This should be "fixed" by #84867. cc #80653

@trinity-1686a
Copy link
Contributor Author

I tested by cloning the pr, running ./x.py build --stage 1 and executing ./build/x86_64-unknown-linux-gnu/stage1/bin/rustdoc lib.rs and the issue is still here. Either I'm missing something, or if fixes only a close, but different issue

@trinity-1686a
Copy link
Contributor Author

I've done more testing, and #84867 does solve part of the issue.
When using that branch, the infinite recursion happen in the exact same place, nothing changed. I've made a small patch (link bellow) that, when applied on master, solve this stack overflow, but another one happen on rustdoc::passes::collect_trait_impls::collect_trait_impls::add_deref_target. Trying the same patch on #84867 and the issue is really fixed, so #84867 fix one stack overflow, but there is an other that is triggered before.

0001-fix-infinite-recursion-on-sidebar_deref_methods.patch.gz (gziped as Github wouldn't accept it otherwise)

bors added a commit to rust-lang-ci/rust that referenced this issue Jun 18, 2021
…cursive-deref, r=jyn514

fix rustdoc stack overflow on mutually recursive Deref

fix rust-lang#85095
fix rust-lang#85037
@bors bors closed this as completed in aee50f4 Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants