Trait Solver 1 @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.
trait Trait {}
impl Trait for for<'a> fn(&'a u32) {}
fn f()
where
for<'a> fn(&'a u32): Trait,
{
}
fn main() {
f();
}
Solution
error: implementation of `Trait` is not general enough
--> examples/trait_solver_1.rs:12:5
|
12 | f();
| ^^^ implementation of `Trait` is not general enough
|
= note: `for<'a> fn(&'a u32)` must implement `Trait`, for any lifetime `'0`...
= note: ...but `Trait` is actually implemented for the type `for<'a> fn(&'a u32)`
error: could not compile `code` (example "trait_solver_1") due to 1 previous error
The trait implementation is for a higher ranked function pointer (for<'a> fn
).
But the where clause is different, there the for<'a>
is parsed as part of the bound, so the bound is on a not higher-ranked function pointer.
impl:
type: for<'a> fn(&'a u32)
trait: Trait
bound:
type: fn(&'a u32)
trait: Trait
Only higher-ranked function pointers implement the trait, so it fails to compile.