Closed
Description
We cannot declare a generic function where one of the tyvars is constrained by a type that contains a region. Here's an example:
trait Trait<'self> {
fn foo(&self) -> &'self str;
}
fn foo<'a, T: Trait<'a>>(_x: T) {}
fn main() {}
This errors with:
a.rs:5:22: 5:24 error: Illegal lifetime 'a: only 'self is allowed as part of a type declaration
a.rs:5 fn foo<'a, T: Trait<'a>>(_x: T) {}
There is a workaround though. Instead we can use a vtable, which compiles fine.
trait Trait<'self> {
fn foo(&self) -> &'self str;
}
fn foo<'a>(_x: &Trait<'a>) {}
fn main() {}