Skip to content

'rustc' has overflowed its stack error #39639

@J-F-Liu

Description

@J-F-Liu

I see this error also reported in other issues, but I think the cause is different. Here is my example code:

#![feature(conservative_impl_trait)]

trait Trait {
    fn method(&self, x: i32) -> i32;
}

impl<F> Trait for F
    where F: Fn(i32) -> i32
{
    fn method(&self, x: i32) -> i32 {
        if x > 0 { self(x - 1) } else { 0 }
    }
}

fn call<T: Trait, F: Fn() -> T>(f: F) -> impl Trait {
    move |x: i32| f().method(x)
}

fn expr() -> impl Trait {
    call(expr)
    // move |x: i32| expr().method(x)
}

fn main() {
    println!("{:?}", expr().method(2));
}
rustc 1.17.0-nightly (ea7a6486a 2017-02-04)

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow

If you uncomment move || expr().method() and comment call(expr) build can success.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions