-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Leverage derive macro AllVariants & generated assoc const ALL_VARIANTS for CLI error+help messages #155677
Copy link
Copy link
Open
Labels
A-CLIArea: Command-line interface (CLI) to the compilerArea: Command-line interface (CLI) to the compilerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-tediousCall for participation: An issue involves lots of work and is better handled as many small tasks.Call for participation: An issue involves lots of work and is better handled as many small tasks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-CLIArea: Command-line interface (CLI) to the compilerArea: Command-line interface (CLI) to the compilerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-tediousCall for participation: An issue involves lots of work and is better handled as many small tasks.Call for participation: An issue involves lots of work and is better handled as many small tasks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
PR #148990 by @Zalathar introduced derive (decl) macro
AllVariantswhich generates associated constALL_VARIANTS: &[Self]containing all variants of a payload-less enum in declaration order. At the time of opening this issue, the macro is only used for print requests (--print) which is a pity since it's great for keeping the list of possible values in error diagnostics in sync with … all possible values.Presently, it's easy to forget updating the corresponding diagnostic when adding a new argument to an existing CLI option since the compiler won't detect the mismatch. This is not a theoretical concern, desyncs have happened in practice! We might even still have outdated diagnostics.
Note that
PrintRequesteven usesALL_VARIANTSto parse print requests by iterating over it. I'm currently not super convinced we should do the same for all other CLI enums, I have a sense that a manualmatchoptimizes better but that could be wrong (also, CLI parsing isn't hot so this probably wouldn't matter anyway).Steps
rust/compiler/rustc_session/src/config/print_request.rs
Lines 53 to 57 in 5095b44
AllVariantspublic, so tools likerustdoccan use it, too. Maybe move it fromrustc_sessiontorustc_macros, not sure what others think.T: AllVariants--help,-Chelp,-Zhelp), too, if possible