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