Why can't this higher kinded lifetime associated type trait bound be satisfied?
RustRust Problem Overview
trait A<'self_>: 'self_ {
type I;
}
trait AMut
where
Self: for<'self_> A<'self_>,
for<'self_> <Self as A<'self_>>::I: 'static,
{
fn mutate_self(&mut self);
}
fn foo<X>(x: &mut X)
where
X: 'static + for<'a> A<'a> + AMut,
for<'a> <X as A<'a>>::I: 'static,
{
x.mutate_self();
}
This errors out with
error[E0280]: the requirement `for<'self_> <Self as A<'self_>>::I: 'static` is not satisfied
--> src/lib.rs:4:1
|
4 | trait AMut
| ^ ---- required by a bound in this
| _|
| |
5 | | where
6 | | Self: for<'self_> A<'self_>,
7 | | for<'self_> <Self as A<'self_>>::I: 'static,
| | ------- required by this bound in `AMut`
8 | | {
9 | | fn mutate_self(&mut self);
10 | | }
| |_^
error[E0280]: the requirement `for<'self_> <X as A<'self_>>::I: 'static` is not satisfied
--> src/lib.rs:14:34
|
4 | trait AMut
| ---- required by a bound in this
...
7 | for<'self_> <Self as A<'self_>>::I: 'static,
| ------- required by this bound in `AMut`
...
14 | X: 'static + for<'a> A<'a> + AMut,
| ^^^^
I would've thought that the bound on line 15 would satisfy the bound on line 7. What am I missing?
Rust Solutions
Solution 1 - Rust
Have you tried like this?
trait A<'self_>: 'self_ {
type I;
}
trait AMut<'a>
where
Self: A<'a>,
<Self as A<'a>>::I: 'static,
{
fn mutate_self(&mut self);
}
fn foo<X>(x: &mut X)
where
X: 'static + for<'a> A<'a> + for<'a> AMut<'a>,
for<'a> <X as A<'a>>::I: 'static,
{
x.mutate_self();
}