Skip to content

Stack overflow with impl Trait and multiple lifetimes... and a closure. #92833

Description

@steffahn

Seems to stack overflow (I think it's one... on Linux it does give "segfault", technically, and on Windows it produces "thread 'rustc' has overflowed its stack").

(Current nightly behaves like current stable.)

trait Fn1<T>: Fn(T) -> <Self as Fn1<T>>::Output {
    type Output;
}
impl<F: ?Sized, T, O> Fn1<T> for F where F: Fn(T) -> O {type Output = O;}

trait Trait<'a1, 'a2> {}
impl<S: ?Sized> Trait<'_, '_> for S {}

fn foo<'a>(request: &'a str) -> impl for<'b> Fn1<&'b (), Output = impl Trait<'a, 'b>> {
    move |_: &()| ()
}

(playground)

Haven't tried much to minimize further yet, perhaps this can also be done, somehow, without using a closure? Nevermind, I removed the need for closures now

trait Fn1<T> {
    type Output;
}
impl<T, S: ?Sized> Fn1<T> for S {
    type Output = ();
}

trait Trait<'a> {}
impl<'a, S: ?Sized> Trait<'a> for S {}

fn foo() -> impl for<'b> Fn1<&'b (), Output = impl Trait<'b>> {
    ()
}

The same code used to give various ICEs in older Rust versions, stack overflow seems to be since 1.57. I don't have time to investigate further today.

@rustbot label I-crash, A-impl-trait, A-lifetimes, A-closures, T-compiler
@rustbot label -A-closures


Labeling question: is ICE -> crash a regression?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsC-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