Skip to content

Make E0284 generic argument suggestions more explicit#154557

Open
Muhtasim-Rasheed wants to merge 1 commit intorust-lang:mainfrom
Muhtasim-Rasheed:issue-147313-improve-help
Open

Make E0284 generic argument suggestions more explicit#154557
Muhtasim-Rasheed wants to merge 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 "::"
  • 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.

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.

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