Trait Solver 2 @BoxyUwU @WaffleLapkin
Warning: this quiz is still "work-in-progress", some questions might not have good explanations (or any at all), formatting/structure/titles/etc are not final, and so on. You might want to return here on a later date.
struct A;
struct B;
struct C;
trait Trait<'a, T> {
type Assoc;
}
trait Bound {}
impl Bound for B {}
impl Bound for C {}
impl<'a> Trait<'a, B> for A {
type Assoc = B;
}
impl<'a> Trait<'a, C> for A {
type Assoc = C;
}
fn f<T>(_: T)
where
for<'a> A: Trait<'a, T>,
for<'a> <A as Trait<'a, T>>::Assoc: Bound,
{
}
fn main() {
f(B);
}
Solution
error[E0277]: the trait bound `for<'a> <A as Trait<'a, _>>::Assoc: Bound` is not satisfied
--> examples/trait_solver_2.rs:30:7
|
30 | f(B);
| - ^ the trait `for<'a> Bound` is not implemented for `<A as Trait<'a, _>>::Assoc`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `Bound`:
B
C
note: this is a known limitation of the trait solver that will be lifted in the future
--> examples/trait_solver_2.rs:30:7
|
30 | f(B);
| --^-
| | |
| | the trait solver is unable to infer the generic types that should be inferred from this argument
| add turbofish arguments to this call to specify the types manually, even if it's redundant
note: required by a bound in `f`
--> examples/trait_solver_2.rs:25:41
|
22 | fn f<T>(_: T)
| - required by a bound in this function
...
25 | for<'a> <A as Trait<'a, T>>::Assoc: Bound,
| ^^^^^ required by this bound in `f`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `code` (example "trait_solver_2") due to 1 previous error