error[E0282]: type annotations needed
--> src/main.rs:12:16
|
12 | foo(|x, f| f(x + 32), |x| x * x)
| ^^^^^^^^^ cannot infer type
|
= note: type must be known at this point
This doesn't look like a bug. The type signature for foo requires that the first arg satisfies two constraints, but the closure itself does not prove the second constraint. (which is why your suggestion works; it proves the second constraint).
Rust only does local type inference; it will not infer types based on the closure body. The types must be known in the signature.
Here's another alternative. While it may not be as pretty, it shows that type inference works locally: