Skip to content

ICE with higher ranked lifetimes #49919

Closed
@mcarton

Description

@mcarton

While trying to find the right syntax for this SO question, I came upon this:

fn foo<'a, T: 'a>(t: T) -> Box<Fn() -> &'a T + 'a> {
    let foo: Box<for <'c> Fn() -> &'c T> = Box::new(move || &t);
    unimplemented!()
}

fn main() {}

which ICEs on Stable, Beta and Nightly:

   Compiling playground v0.0.1 (file:///playground)
error[E0582]: binding for associated type `Output` references lifetime `'c`, which does not appear in the trait input types
 --> src/main.rs:2:35
  |
2 |     let foo: Box<for <'c> Fn() -> &'c T> = Box::new(move || &t);
  |                                   ^^^^^

error: internal compiler error: librustc/infer/higher_ranked/mod.rs:160: no representative region for `ReSkolemized(1, BrAnon(1))` in `{ReSkolemized(1, BrAnon(1))}`

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:543:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0582`.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.26.0-beta.3 (8a75d2b50 2018-04-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

https://play.rust-lang.org/?gist=99fafbbcbd0fc919138de28d5e1a6326&version=nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions