Open
Description
trait Test {
fn boo<'ctx>() where Self: 'ctx;
}
impl<A, B> Test for (A, B) {
fn boo<'ctx>() where A: 'ctx, B: 'ctx { } // ok
}
impl Test for () {
fn boo<'ctx>() { } // [E0195]: lifetime parameters or bounds on method `boo` do not match the trait declaration
}
I expected this to succeed. And in fact, the first impl (the generic one) succeeds! (i.e. the compiler is able to successfully determine that Self: 'ctx
given A: 'ctx
and B: 'ctx
)
However, an error is emitted on the impl for ()
:
error[E0195]: lifetime parameters or bounds on method `boo` do not match the trait declaration
--> src/lib.rs:10:11
|
2 | fn boo<'ctx>() where Self: 'ctx;
| ------ lifetimes in impl do not match this method in trait
...
10 | fn boo<'ctx>() { }
| ^^^^^^ lifetimes do not match method in trait
error: aborting due to previous error
In order to make this one compile, we need to add where (): 'ctx
to the impl, which is, well, a bit silly!
impl Test for () {
fn boo<'ctx>() where (): 'ctx { } // ok (workaround)
}
Addendum: In fact, any mention of the lifetime inside where
bounds causes compilation to succeed.
impl Test for () {
fn boo<'ctx>() where i32: 'ctx { } // ok
}
impl Test for () {
fn boo<'ctx>() where &'ctx i32: Clone { } // also ok
}