Skip to content

Make E0284 generic argument suggestions more explicit#154557

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Muhtasim-Rasheed:issue-147313-improve-help
Apr 21, 2026
Merged

Make E0284 generic argument suggestions more explicit#154557
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Muhtasim-Rasheed:issue-147313-improve-help

Conversation

@Muhtasim-Rasheed
Copy link
Copy Markdown
Contributor

@Muhtasim-Rasheed Muhtasim-Rasheed commented Mar 29, 2026

Closes #147313

Previously, when type annotations were missing for a function call, rust suggested: "consider specifying the generic argument". This PR improves the diagnostics:

  • If only one generic type is missing:
    "consider specifying a concrete type for the generic type <T>" with the turbofish being "::<SomeConcreteType>"
  • If only one const generic is missing:
    "consider specifying a const for the const generic <CONST>" with the turbofish being "::<SOME_CONST>"

Multiple missing generics still produce the original more general suggestion

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 29, 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. labels Mar 29, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 29, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
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 12 candidates

#[suggestion(
"consider specifying a concrete type for the generic type `{$arg}`",
style = "verbose",
code = "::<SomeConcreteType>",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention for placeholders nowadays is /* … */

Suggested change
code = "::<SomeConcreteType>",
code = "::</* Type */>",

#[suggestion(
"consider specifying a const for the const generic `{$arg}`",
style = "verbose",
code = "::<SOME_CONST>",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
code = "::<SOME_CONST>",
code = "::</* CONST */>",

ditto

args: String,
},
#[suggestion(
"consider specifying a concrete type for the generic type `{$arg}`",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"consider specifying a concrete type for the generic type `{$arg}`",
"consider specifying a concrete type for the type parameter `{$param}`",

arg: String,
},
#[suggestion(
"consider specifying a const for the const generic `{$arg}`",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"consider specifying a const for the const generic `{$arg}`",
"consider specifying a value for the const parameter `{$param}`",

args,
});
if generic_args.len() == 1
&& args.chars().all(|c| c.is_alphanumeric() || c == '_')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through the generated text to heuristically figure out if this is meant to be a type or const param is iffy. After all args represents the list of arguments, not the list of (formal) parameters.

If you are set on suggesting a placeholder if the argument list "isn't meaningful" (for some sense of meaningful) I would look a few lines further up to decide that. Note that I haven't really looked at this PR in detail so I don't know the criteria you're looking for.

@chenyukang
Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 19, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 19, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Muhtasim-Rasheed Muhtasim-Rasheed force-pushed the issue-147313-improve-help branch from f4f12fc to b178681 Compare April 20, 2026 10:48
@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Apr 20, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 20, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Muhtasim-Rasheed
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 20, 2026
@chenyukang
Copy link
Copy Markdown
Member

@bors r=chenyukang

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 21, 2026

📌 Commit b178681 has been approved by chenyukang

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 21, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 21, 2026
Rollup of 5 pull requests

Successful merges:

 - #153411 (Offload slice support)
 - #154557 (Make E0284 generic argument suggestions more explicit)
 - #154933 (Suggest removing `&` when awaiting a reference to a future)
 - #155524 (Fix LLVM offload install docs to use semicolon-separated CMake lists)
 - #155568 (Update books)
@rust-bors rust-bors Bot merged commit a8e1664 into rust-lang:main Apr 21, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 21, 2026
rust-timer added a commit that referenced this pull request Apr 21, 2026
Rollup merge of #154557 - Muhtasim-Rasheed:issue-147313-improve-help, r=chenyukang

Make E0284 generic argument suggestions more explicit

Closes #147313

Previously, when type annotations were missing for a function call, rust suggested: "consider specifying the generic argument". This PR improves the diagnostics:

- If only one generic type is missing:
  "consider specifying a concrete type for the generic type `<T>`" with the turbofish being "::\<SomeConcreteType>"
- If only one const generic is missing:
  "consider specifying a const for the const generic `<CONST>`" with the turbofish being "::<SOME_CONST>"

Multiple missing generics still produce the original more general suggestion
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 21, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#153411 (Offload slice support)
 - rust-lang/rust#154557 (Make E0284 generic argument suggestions more explicit)
 - rust-lang/rust#154933 (Suggest removing `&` when awaiting a reference to a future)
 - rust-lang/rust#155524 (Fix LLVM offload install docs to use semicolon-separated CMake lists)
 - rust-lang/rust#155568 (Update books)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

suggestion for "type annotations needed" should be explicit about how to specify the generic argument

4 participants