I have a trait Foo
inheriting from another trait Bar
. Bar
has an associated type Baz
. Foo
constrains Baz
such that Baz
must implement Hoge
.
trait Hoge {}
trait Bar {
type Baz;
}
trait Foo: Bar where Self::Baz: Hoge {}
However, when I define a generic function requiring the generic type T
to implement Foo
,
// [DESIRED CODE]
fn fizz<T: Foo>(buzz: T) {
// ...
}
rustc
complains with EO277
unless I constrain T
explicitly:
fn fizz<T: Foo>(buzz: T) where T::Baz: Hoge {
// ...
}
I do not understand why I need to do this. I would like to be able to write [DESIRED CODE]
. What is the recommended way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…