Indicate origin of where type parameter for uninferred types
Based on #65951 (which is not merge yet), fixes #67277.
This PR improves a little the diagnostic for code like:
```
async fn foo() {
bar().await;
}
async fn bar<T>() -> () {}
```
by showing:
```
error[E0698]: type inside `async fn` body must be known in this context
--> unresolved_type_param.rs:9:5
|
9 | bar().await;
| ^^^ cannot infer type for type parameter `T` declared on the function `bar`
|
...
```
(The
```
declared on the function `bar`
```
part is new)
A small side note: `Vec` and `slice` seem to resist this change, because querying `item_name()` panics, and `get_opt_name()` returns `None`.
r? @estebank
self.var_map.entry(ty).or_insert_with(||
infcx.next_ty_var(
TypeVariableOrigin {
- kind: TypeVariableOriginKind::TypeParameterDefinition(name),
+ kind: TypeVariableOriginKind::TypeParameterDefinition(name, None),
span: DUMMY_SP,
}
)
let message = if let Some(name) = last_generator
.and_then(|generator_did| self.tcx.parent(generator_did))
.and_then(|parent_did| self.tcx.hir().as_local_hir_id(parent_did))
- .map(|parent_hir_id| self.tcx.hir().name(parent_hir_id))
+ .and_then(|parent_hir_id| self.tcx.hir().opt_name(parent_hir_id))
{
format!("future returned by `{}` is not {}", name, trait_name)
} else {