为什么不能满足这种更高的kinded life相关类型特征限制?

use*_*ser 19 rust

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();
}

fn main() {}
Run Code Online (Sandbox Code Playgroud)

围栏链接

这出错了

<anon>:17:7: 17:20 error: the requirement `for<'self_> <X as A<'self_>>::I : 'static` is not satisfied [E0280]
<anon>:17     x.mutate_self();
                ^~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101
Run Code Online (Sandbox Code Playgroud)

我会认为第15行的界限会满足第7行的界限.我错过了什么?

小智 1

你有这样尝试过吗?

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();
}
Run Code Online (Sandbox Code Playgroud)