Why theorize when we can just ask the compiler?
I tried modifying this single line in hir/lowering.rs.
When it compiles librustc, it produces a single error:
error[E0282]: type annotations needed
--> librustc/util/ppaux.rs:263:29
|
263 | let fn_trait_kind = ty::tls::with(|tcx| {
| _____________________________^
264 | | // Unfortunately, some kinds of items (e.g., closures) don't have
265 | | // generics. So walk back up the find the closest parent that DOES
266 | | // have them.
... |
338 | | Ok(tcx.lang_items().fn_trait_kind(path_def_id))
339 | | })?;
| |___________^ cannot infer type for `_`
Permalink to relevant code.
Imagine using ? in a closure and then ? on the result of the closure.
This is indeed what happens in that function. I am genuinely surprised, though, as I thought this was categorically impossible to do without type annotations… (unless you have a regular return result somewhere in the closure, where result's error type is known);