【问题标题】:Why can't this higher kinded lifetime associated type trait bound be satisfied?为什么不能满足这种更高种类的生命周期相关类型特征绑定?
【发布时间】:2016-03-10 21:40:53
【问题描述】:
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();
}

Playground

这个错误了

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,
   |                                  ^^^^

我原以为第 15 行的界限会满足第 7 行的界限。我错过了什么?

【问题讨论】:

标签: rust


【解决方案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();
}

【讨论】:

    猜你喜欢
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    相关资源
    最近更新 更多