Skip to content

indicate origin of where type parameter for uninferred types #67277

Closed
@nikomatsakis

Description

@nikomatsakis

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.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions