Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion to reorder generic parameters ignores type defaults #80512

Closed
varkor opened this issue Dec 30, 2020 · 2 comments · Fixed by #80519
Closed

Suggestion to reorder generic parameters ignores type defaults #80512

varkor opened this issue Dec 30, 2020 · 2 comments · Fixed by #80519
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@varkor
Copy link
Member

varkor commented Dec 30, 2020

struct S<T = (), 'a>(&'a T);

results in:

error: lifetime parameters must be declared prior to type parameters
 --> src/lib.rs:1:18
  |
1 | struct S<T = (), 'a>(&'a T);
  |         ---------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T>`

when it should be:

help: reorder the parameters: lifetimes, then types, then consts: `<'a, T = ()>`

This should be easy to fix: just replace ident in the following line with an appropriate format string.

GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),

@varkor varkor added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Dec 30, 2020
@varkor varkor changed the title Reorder generic parameters suggestion ignores defaults Suggestion to reorder generic parameters ignores type defaults Dec 30, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Dec 30, 2020
@max-heller
Copy link
Contributor

@rustbot claim

@max-heller
Copy link
Contributor

This should be easy to fix: just replace ident in the following line with an appropriate format string.

GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),

For the record, it's not quite this simple, as doing so results in incorrect output when the parameter also has bounds. For example, it would render T: 'a = () as T = (): 'a because bounds are printed after the ident

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Dec 31, 2020
Take type defaults into account in suggestions to reorder generic parameters

Fixes rust-lang#80512
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 31, 2020
Take type defaults into account in suggestions to reorder generic parameters

Fixes rust-lang#80512
@bors bors closed this as completed in 1f431f9 Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants