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

Overflowed stack #105656

Closed
JustForFun88 opened this issue Dec 13, 2022 · 7 comments
Closed

Overflowed stack #105656

JustForFun88 opened this issue Dec 13, 2022 · 7 comments
Labels
C-bug Category: This is a bug.

Comments

@JustForFun88
Copy link

JustForFun88 commented Dec 13, 2022

I tried this code:

struct CharBuffer {
    buf: [u8; 4],
    len: usize,
}

impl From<CharBuffer> for char {
    #[inline]
    fn from(char: CharBuffer) -> Self {
        char.into()
    }
}

fn main() {
    let foo = CharBuffer{ buf: [0; 4], len: 0 };
    let bar: char = char::from(foo);
}

I expected to see this happen:

error[E0277]: the trait bound `char: From<CharBuffer>` is not satisfied
 --> src/main.rs:9:9
  |
9 |         char.into()
  |         ^^^^ ---- required by a bound introduced by this call
  |         |
  |         the trait `From<CharBuffer>` is not implemented for `char`
  |
  = note: required for `CharBuffer` to implement `Into<char>`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

Instead, this happened:

thread 'main' has overflowed its stack
@JustForFun88 JustForFun88 added the C-bug Category: This is a bug. label Dec 13, 2022
@bjorn3
Copy link
Member

bjorn3 commented Dec 13, 2022

I can reproduce this on the playground when using nightly, but not locally.

@bjorn3 bjorn3 added the I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. label Dec 13, 2022
@albertlarsan68
Copy link
Member

albertlarsan68 commented Dec 13, 2022

It is the created binary that crashes, not the rustc process.

It can be explained by the fact that there is a recursive call in the impl From<CharBuffer> for char.

@bjorn3 bjorn3 removed the I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. label Dec 13, 2022
@bjorn3
Copy link
Member

bjorn3 commented Dec 13, 2022

That explains why I couldn't reproduce it locally 😅 I didn't run the executable. Only rustc.

@JustForFun88
Copy link
Author

I know that in general it is a problem of recursive call. I was just confused by the silent compilation.

The compiler didn't even warn that there was a recursive call of the same function.

@albertlarsan68
Copy link
Member

The bug may be this, that there is no diagnostic concerning this unconditional recursion.

@rustbot label +A-diagnostics +D-terse

@quat1024
Copy link

quat1024 commented Dec 13, 2022

This is a case of #57965, the unconditional_recursion lint not detecting mutual recursion.

See also: #98217

@jruderman
Copy link
Contributor

I think this can be closed as a duplicate of #98217

@oli-obk oli-obk closed this as completed Dec 17, 2022
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

No branches or pull requests

6 participants