Skip to content

Point at definition of item with type parameters that couldn't be inferred#153890

Open
estebank wants to merge 1 commit intorust-lang:mainfrom
estebank:issue-94969
Open

Point at definition of item with type parameters that couldn't be inferred#153890
estebank wants to merge 1 commit intorust-lang:mainfrom
estebank:issue-94969

Conversation

@estebank
Copy link
Contributor

When calling a function with type parameters that are unconstrained by the call expression, we mention the type parameter that couldn't be inferred, but the user previously didn't see where the name was coming from. By pointing at the function itself, including the type parameter, we give better context on what they should have done, specially when the inference machinery fails to provide any other context.

error[E0282]: type annotations needed
  --> $DIR/unresolved_type_param.rs:9:5
   |
LL |     bar().await;
   |     ^^^ cannot infer type of the type parameter `T` declared on the function `bar`
   |
note: type must be known for this
  --> $DIR/unresolved_type_param.rs:6:1
   |
LL | async fn bar<T>() -> () {}
   | ^^^^^^^^^^^^^^^^^^^^^^^
help: consider specifying the generic argument
   |
LL |     bar::<T>().await;
   |        +++++

We should further refine when we present this info to make sure we don't provide redundant notes in some cases. Also, there are cases (like those in issue 94969) that don't provide any new information with this change.

…erred

When calling a function with type parameters that are unconstrained by the call expression, we mention the type parameter that couldn't be inferred, but the user previously didn't see where the name was coming from. By pointing at the function itself, including the type parameter, we give better context on what they should have done, specially when the inference machinery fails to provide any other context.

```
error[E0282]: type annotations needed
  --> $DIR/unresolved_type_param.rs:9:5
   |
LL |     bar().await;
   |     ^^^ cannot infer type of the type parameter `T` declared on the function `bar`
   |
note: type must be known for this
  --> $DIR/unresolved_type_param.rs:6:1
   |
LL | async fn bar<T>() -> () {}
   | ^^^^^^^^^^^^^^^^^^^^^^^
help: consider specifying the generic argument
   |
LL |     bar::<T>().await;
   |        +++++
```

We should further refine when we present this info to make sure we don't provide redundant notes in some cases. Also, there are cases (like those in issue 94969) that don't provide any new information with this change.
@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2026

Some changes occurred in need_type_info.rs

cc @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Mar 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 15 candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants