【发布时间】: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();
}
这个错误了
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 行的界限。我错过了什么?
【问题讨论】:
-
我认为是这个问题:github.com/rust-lang/rust/issues/27113。你不能在 where 子句的 lhs 上有 HKL
-
@ker 我愿意相信这一点。我现在才发现用
Send替换rhs'static可以编译边界。很奇怪。 -
@ker 啊,它编译,但实际上试图
implthe trait for a type never works。 -
对于这种特殊情况,添加通用生命周期
AMut和foo,而不是 HKL,works。
标签: rust