This is a similar issue as #84937, #89436, and #90875. Those were fixed by #90887, but it seems like the issue still exists (on stable and nightly). It is pretty flakey: In this case, it can be fixed by adding a type annotation and even by changing the order of the exec function's arguments.
fn main() {
// error: mismatched types
// expected fn pointer `for<'a> fn(<u32 as Input>::Projected<'a>) -> _`
// found fn item `fn(u32) -> u32 {double}`
//
// Two ways to fix the problem here:
// - Add `::<u32, _>` below
// - Switch the order of the parameters on `exec`
exec(double, 10);
}
fn double(x: u32) -> u32 {
2 * x
}
fn exec<In, Out>(f: for<'a> fn(<In as Input<'a>>::Projected) -> Out, input: In) -> Out
where
In: for<'a> Input<'a>,
{
todo!()
}
trait Input<'a> {
type Projected;
}
impl<'a> Input<'a> for u32 {
type Projected = u32;
}
Full Diagnostic
```
error[E0308]: mismatched types
--> src/lib.rs:26:11
|
26 | query(double, 10);
| ----- ^^^^^^ expected associated type, found `u32`
| |
| arguments to this function are incorrect
|
= note: expected fn pointer `for<'a> fn(>::Projected) -> _`
found fn item `fn(u32) -> u32 {double}`
= help: consider constraining the associated type `<_ as Input<'a>>::Projected` to `u32` or calling a method that returns `<_ as Input<'a>>::Projected`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: function defined here
--> src/lib.rs:33:4
|
33 | fn query(f: for<'a> fn(>::Projected) -> Out, input: In) -> Out
| ^^^^^ --------------------------------------------------
For more information about this error, try `rustc --explain E0308`.
```
This is a similar issue as #84937, #89436, and #90875. Those were fixed by #90887, but it seems like the issue still exists (on stable and nightly). It is pretty flakey: In this case, it can be fixed by adding a type annotation and even by changing the order of the
exec
function's arguments.Full Diagnostic
Meta
rustc --version --verbose
:cc @jackh726