Make E0284 generic argument suggestions more explicit#154557
Make E0284 generic argument suggestions more explicit#154557rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
|
Some changes occurred in need_type_info.rs cc @lcnr |
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| #[suggestion( | ||
| "consider specifying a concrete type for the generic type `{$arg}`", | ||
| style = "verbose", | ||
| code = "::<SomeConcreteType>", |
There was a problem hiding this comment.
The convention for placeholders nowadays is /* … */
| code = "::<SomeConcreteType>", | |
| code = "::</* Type */>", |
| #[suggestion( | ||
| "consider specifying a const for the const generic `{$arg}`", | ||
| style = "verbose", | ||
| code = "::<SOME_CONST>", |
There was a problem hiding this comment.
| code = "::<SOME_CONST>", | |
| code = "::</* CONST */>", |
ditto
| args: String, | ||
| }, | ||
| #[suggestion( | ||
| "consider specifying a concrete type for the generic type `{$arg}`", |
There was a problem hiding this comment.
| "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}`", |
There was a problem hiding this comment.
| "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 == '_') |
There was a problem hiding this comment.
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.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
f4f12fc to
b178681
Compare
|
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. |
|
@rustbot ready |
|
@bors r=chenyukang |
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)
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
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)
Closes #147313
Previously, when type annotations were missing for a function call, rust suggested: "consider specifying the generic argument". This PR improves the diagnostics:
"consider specifying a concrete type for the generic type
<T>" with the turbofish being "::<SomeConcreteType>""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