Rust &引用;冲突的实施”;复杂泛型代码中的错误,如何修复?

Rust &引用;冲突的实施”;复杂泛型代码中的错误,如何修复?,rust,Rust,我有Basetrait,为所有实现Bar的类型实现Foo,现在我想为所有Foobar结构实现Foo,其中B:Base: trait Base {} trait Foo<B: Base> {} trait Bar<B: Base> {} struct Foobar<B: Base> { _b: B } // delete either, compile success impl<B: Base, T: Bar<B>> Fo

我有
Base
trait,为所有实现
Bar
的类型实现
Foo
,现在我想为所有
Foobar
结构实现
Foo
,其中
B:Base

trait Base {}


trait Foo<B: Base> {}


trait Bar<B: Base> {}


struct Foobar<B: Base> { _b: B }


// delete either, compile success
impl<B: Base, T: Bar<B>> Foo<B> for T {}
impl<B: Base> Foo<B> for Foobar<B> {}


fn main()
{
}
trait Base{}
性状Foo{}
特征条{}
结构Foobar{u b:b}
//删除或编译成功
T{}的impl Foo
Foobar{}的impl Foo
fn main()
{
}
编译错误是:

<anon>:14:1: 14:41 error: conflicting implementations for trait `Foo` [E0119]
<anon>:14 impl<B: Base, T: Bar<B>> Foo<B> for T {}
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:14:1: 14:41 help: see the detailed explanation for E0119
<anon>:15:1: 15:38 note: note conflicting implementation here
<anon>:15 impl<B: Base> Foo<B> for Foobar<B> {}
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

您的impl重叠,对此没有一般性的解决办法(除了“如果您以后想专门化它,请避免使用一揽子impl”)


有可能有一个更专业的版本的impl目前正在进行中。正在尝试实施。

您不能。但有一个RFC允许: