Skip to content

rustc overflowed its stack: extern crate inside const inside external trait impl #71157

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

Closed
CAD97 opened this issue Apr 14, 2020 · 3 comments
Closed
Labels
C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Apr 14, 2020

...but only when the crate is introduced solely through edition2018 extern prelude and not when an extern crate statement exists at root level.

Minimized reproduction (on playground)

use serde::de::{Deserialize, Deserializer};

pub struct S;

impl<'de> Deserialize<'de> for S {
    fn deserialize<D>(_: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        const _: () = {
            extern crate serde;
        };
        todo!()
    }
}

(Reason for this code shape: deriving serde's traits puts the impl within a const and uses extern crate to get serde at a known name.)

Edits that make this not overflow the stack:

  • Add extern crate serde; at root level.
  • Inline the Deserialize trait definition.
  • Removing the const around the extern crate statement.
  • Moving the const declaration to root scope.

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (94d346360 2020-04-09)
binary: rustc
commit-hash: 94d346360da50f159e0dc777dc9bc3c5b6b51a00
commit-date: 2020-04-09
host: x86_64-pc-windows-msvc
release: 1.44.0-nightly
LLVM version: 9.0

This overflows the stack back to 1.31.0, the first stable release with edition 2018 support.

cargo check is enough to get the stack overflow.

Error output

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
@CAD97 CAD97 added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 14, 2020
@jonas-schievink jonas-schievink added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 14, 2020
@Centril Centril added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Apr 14, 2020
@CAD97
Copy link
Contributor Author

CAD97 commented Apr 14, 2020

Here's a mcve that works without serde, using a single manifest:

Cargo.toml
[package]
name = "playground"
version = "0.0.0"
edition = "2018"
lib.rs
pub trait Trait {
    fn method();
}
main.rs
use playground::Trait;

struct Struct;

impl Trait for Struct {
    fn method() {
        const _: () = {
            extern crate playground;
        };
    }
}

fn main() {}

Removing the main function from main.rs will cause an error without causing a stack overflow, so whatever causes the stack overflow runs after that check.

@Centril Centril added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. P-medium Medium priority and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Apr 15, 2020
@petrochenkov
Copy link
Contributor

Looks like a duplicate of #55779.

@spastorino spastorino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 15, 2020
@CAD97
Copy link
Contributor Author

CAD97 commented Apr 29, 2020

Closing as duplicate.

@CAD97 CAD97 closed this as completed Apr 29, 2020
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. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-medium Medium priority 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

5 participants