Region parameter out of range when substituting in region 'a


#1

Playground link

#![feature(generic_associated_types)]

trait Foo {
    type Bar;
    fn foo<'a>(&'a mut self) -> Self::Bar where Self::Bar: 'a;
}

struct FooA{}
struct Bar<'a> {
    foo: &'a mut FooA
}
impl Foo for FooA
{
    type Bar<'a> = Bar<'a>;
    fn foo<'a>(&'a mut self) -> Bar<'a> {
        Bar{foo: self}
    }
}


fn main() {
    FooA{}.foo();
}

Error:

   Compiling playground v0.0.1 (file:///playground)
error: internal compiler error: librustc/ty/subst.rs:425: Region parameter out of range when substituting in region 'a (root type=Some(Bar<'a>)) (index=0)

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:499: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.28.0-nightly (967c1f3be 2018-06-15) running on x86_64-unknown-linux-gnu

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

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.

#2

This superficially looks like https://github.com/rust-lang/rust/issues/50115 though some details of the MCE differ. Best to just create an issue if you’re unsure; ICEs are high-profile and nobody will be bothered by a duplicate issue.


#3

For other ICEs, yes, they should be counted as long as they exists. But for this, no. I have learned from the relevent issues that this feature is currently not in a useable status, so maybe just wait and see if this fixed in another day. There are already a couple issues have been raised regarding this.