Over in #65951, @estebank and I were discussing that we could improve the error message in cases like:
|
async fn foo() { |
|
bar().await; |
|
//~^ ERROR type inside `async fn` body must be known in this context |
|
//~| NOTE cannot infer type for `T` |
|
//~| NOTE the type is part of the `async fn` body because of this `await` |
|
//~| NOTE in this expansion of desugaring of `await` |
|
} |
Presently, we say:
https://github.com/rust-lang/rust/blob/master/src/test/ui/async-await/unresolved_type_param.stderr#L1-L5
but this T we reference comes from the definition of bar:
|
async fn bar<T>() -> () {} |
it'd be nice if we said "cannot infer value for type parameter T declared on the fn bar".
I believe that name comes from the TypeParameterDefinition information that we track as part of a type variable's origin:
|
if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind { |
|
return (name.to_string(), Some(var_origin.span)); |
|
} |
So we could do this by modifying that variant to track the DefId of the type parameter and then looking at the parent to derive the context.
This issue has been assigned to @ohadravid via this comment.
Over in #65951, @estebank and I were discussing that we could improve the error message in cases like:
rust/src/test/ui/async-await/unresolved_type_param.rs
Lines 8 to 14 in 3964a55
Presently, we say:
https://github.com/rust-lang/rust/blob/master/src/test/ui/async-await/unresolved_type_param.stderr#L1-L5
but this
Twe reference comes from the definition ofbar:rust/src/test/ui/async-await/unresolved_type_param.rs
Line 6 in 3964a55
it'd be nice if we said "cannot infer value for type parameter
Tdeclared on the fnbar".I believe that name comes from the
TypeParameterDefinitioninformation that we track as part of a type variable's origin:rust/src/librustc/infer/error_reporting/need_type_info.rs
Lines 159 to 161 in 3964a55
So we could do this by modifying that variant to track the
DefIdof the type parameter and then looking at the parent to derive the context.This issue has been assigned to @ohadravid via this comment.