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

ICE in existential type with lifetime in trait implementation #54169

Open
petertodd opened this issue Sep 13, 2018 · 1 comment

Comments

Projects
None yet
4 participants
@petertodd
Copy link
Contributor

commented Sep 13, 2018

Example:

#![feature(existential_type)]
use std::fmt::Debug;

pub trait Foo {
    type Assoc : Debug;
    fn func() -> Self::Assoc;
}

pub struct Bar;

impl Foo for Bar {
    existential type Assoc<'b> : Debug;

    fn func() -> Self::Assoc {
    }   
}

fn main() {
}

Backtrace:

$ rustc  existential-panic.rs 
error: internal compiler error: librustc/ty/subst.rs:445: Region parameter out of range when substituting in region 'b (root type=Some(Assoc::<'b>)) (index=0)

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


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.30.0-nightly (2f1547c0a 2018-09-11) running on x86_64-unknown-linux-gnu
@Matthias247

This comment has been minimized.

Copy link
Contributor

commented May 14, 2019

I just run into the same problem when trying to define an async interface (with Future) and implement it with existential type:

#![feature(existential_type, async_await)]

use std::future::Future;

pub trait MyTrait<'a> {
    type ResultFut: Future<Output = ()> + 'a;

    fn do_sth(&'a mut self, a: &'a str) -> Self::ResultFut;
}

struct MyImpl {
}

impl<'a> MyTrait<'a> for MyImpl {
    existential type ResultFut<'a>: Future<Output = ()> + 'a;

    fn do_sth(&'a mut self, a: &'a str) -> Self::ResultFut {
        async {
            Ok(())
        }
    }
}
Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc/ty/subst.rs:489: Region parameter out of range when substituting in region 'a (root type=Some(ResultFut::<'a, 'a>)) (index=1)

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:572:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error

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.36.0-nightly (a9ec99f42 2019-05-13) running on x86_64-unknown-linux-gnu

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

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `playground`.

To learn more, run the command again with --verbose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.