Description
Compiling this code:
#![feature(generic_associated_types)]
trait MyTrait {
type Assoc<'a, 'b> where 'b: 'a;
fn do_sth(arg: Self::Assoc<'_, '_>);
}
struct Foo;
impl MyTrait for Foo {
type Assoc<'a, 'b> where 'b: 'a = u32;
fn do_sth(_: u32) {}
// fn do_sth(_: Self::Assoc<'static, 'static>) {}
// fn do_sth(_: Self::Assoc<'_, '_>) {}
}
I'd expect all of these three versions to compile. The associated type has two lifetimes as well as a lifetime bound 'b: 'a
, but u32
doesn't use the lifetime. However, I'm getting a compiler error:
error[E0478]: lifetime bound not satisfied
--> src/lib.rs:13:5
|
13 | fn do_sth(_: u32) {}
| ^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the anonymous lifetime #2 defined on the method body at 13:5
--> src/lib.rs:13:5
|
13 | fn do_sth(_: u32) {}
| ^^^^^^^^^^^^^^^^^
note: but lifetime parameter must outlive the anonymous lifetime #1 defined on the method body at 13:5
--> src/lib.rs:13:5
|
13 | fn do_sth(_: u32) {}
| ^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0478`.
error: could not compile `playground` due to previous error
Without the where 'b: 'a
, all three compile fine.