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

Encountered a Stack Overflow Crash on stable compiled rust #105158

Open
d3rpp opened this issue Dec 2, 2022 · 4 comments
Open

Encountered a Stack Overflow Crash on stable compiled rust #105158

d3rpp opened this issue Dec 2, 2022 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@d3rpp
Copy link

d3rpp commented Dec 2, 2022

I tried this code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3bc6e2fae27c0a45ec2fa59a087a291b

I expected to see this happen:
Print out a vector of dynamic trait objects

Instead, this happened:
a Stack Overflow error on the compiled output

Meta

On the Rust Playground, using Debug, Stable on the 2nd of December 2022.

Backtrace

There isn't one here

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
timeout: the monitored command dumped core
/playground/tools/entrypoint.sh: line 11:     7 Aborted                 timeout --signal=KILL ${timeout} "$@"

This is the error produced by the playground

@d3rpp d3rpp added the C-bug Category: This is a bug. label Dec 2, 2022
@d3rpp
Copy link
Author

d3rpp commented Dec 2, 2022

I now realise that I am causing infinite recursion in here:

impl Debug for dyn Shape {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{:#?}", self)
    }
}

So I know it's a problem that I specifically created that is causing the Stack Overflow error.

Though given the correctness of Rust, I'll leave it up to you as to whether this should be investigated or if I'm being an idiot.

I do recognise that what I have created is a recursion with no exit condition, though part of me feels as if the compiler should have a warning about that at the very least

@jruderman
Copy link
Contributor

A function unconditionally calling itself triggers the unconditional_recursion lint, with the warning "function cannot return without recursing":

fn a() { a() }

But a pair of functions co-recursing does not (#57965):

fn x() { y() }
fn y() { x() }

This case may be more complicated: it involves a trait, a macro, and a Result error case that might need to be ignored for the recursion to be considered "unconditional". So perhaps we should leave this open and revisit it after #57965 is fixed.

@rustbot label +A-diagnostics

@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Dec 2, 2022
@Noratrieb
Copy link
Member

The compiler really shouldn't stackoverflow on normal code like this, so that is a bug.

@jruderman
Copy link
Contributor

The crash is in the compiled output, not in the compiler

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants