Skip to content

Commit a85a758

Browse files
committed
Unify the format of rustc cli flags
Signed-off-by: xizheyin <[email protected]>
1 parent 9bfa31f commit a85a758

File tree

9 files changed

+165
-118
lines changed

9 files changed

+165
-118
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE
16461646
static PRINT_HELP: LazyLock<String> = LazyLock::new(|| {
16471647
format!(
16481648
"Compiler information to print on stdout (or to a file)\n\
1649-
INFO may be one of ({}).",
1649+
INFO may be one of <{}>.",
16501650
PRINT_KINDS.iter().map(|(name, _)| format!("{name}")).collect::<Vec<_>>().join("|")
16511651
)
16521652
});
@@ -1679,66 +1679,85 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
16791679
"",
16801680
"cfg",
16811681
"Configure the compilation environment.\n\
1682-
SPEC supports the syntax `NAME[=\"VALUE\"]`.",
1683-
"SPEC",
1682+
SPEC supports the syntax `<NAME>[=\"VALUE\"]`.",
1683+
"<SPEC>",
16841684
),
1685-
opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"),
1685+
opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", "<SPEC>"),
16861686
opt(
16871687
Stable,
16881688
Multi,
16891689
"L",
16901690
"",
16911691
"Add a directory to the library search path. \
1692-
The optional KIND can be one of dependency, crate, native, framework, or all (the default).",
1693-
"[KIND=]PATH",
1692+
The optional <KIND> can be one of <dependency|crate|native|framework|all> (default: all).",
1693+
"[<KIND>=]<PATH>",
16941694
),
16951695
opt(
16961696
Stable,
16971697
Multi,
16981698
"l",
16991699
"",
17001700
"Link the generated crate(s) to the specified native\n\
1701-
library NAME. The optional KIND can be one of\n\
1702-
static, framework, or dylib (the default).\n\
1703-
Optional comma separated MODIFIERS\n\
1704-
(bundle|verbatim|whole-archive|as-needed)\n\
1701+
library <NAME>. The optional <KIND> can be one of\n\
1702+
<static|framework|dylib> (default: dylib).\n\
1703+
Optional comma separated <MODIFIERS>\n\
1704+
<bundle|verbatim|whole-archive|as-needed>\n\
17051705
may be specified each with a prefix of either '+' to\n\
17061706
enable or '-' to disable.",
1707-
"[KIND[:MODIFIERS]=]NAME[:RENAME]",
1707+
"[<KIND>[:<MODIFIERS>]=]<NAME>[:<RENAME>]",
17081708
),
17091709
make_crate_type_option(),
1710-
opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "NAME"),
1710+
opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "<NAME>"),
17111711
opt(Stable, Opt, "", "edition", &EDITION_STRING, EDITION_NAME_LIST),
1712-
opt(Stable, Multi, "", "emit", &EMIT_HELP, "TYPE[=FILE]"),
1712+
opt(Stable, Multi, "", "emit", &EMIT_HELP, "<TYPE>[=<FILE>]"),
1713+
opt(Stable, Multi, "", "print", &PRINT_HELP, "<INFO>[=<FILE>]"),
1714+
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
1715+
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
1716+
opt(Stable, Opt, "o", "", "Write output to <FILENAME>", "<FILENAME>"),
1717+
opt(
1718+
Stable,
1719+
Opt,
1720+
"",
1721+
"emit",
1722+
"Comma separated list of types of output for the compiler to emit",
1723+
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]",
1724+
),
17131725
opt(Stable, Multi, "", "print", &PRINT_HELP, "INFO[=FILE]"),
17141726
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
17151727
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
1716-
opt(Stable, Opt, "o", "", "Write output to <filename>", "FILENAME"),
1717-
opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
1728+
opt(Stable, Opt, "o", "", "Write output to <FILENAME>", "<FILENAME>"),
1729+
opt(
1730+
Stable,
1731+
Opt,
1732+
"",
1733+
"out-dir",
1734+
"Write output to compiler-chosen filename in <DIR>",
1735+
"<DIR>",
1736+
),
17181737
opt(
17191738
Stable,
17201739
Opt,
17211740
"",
17221741
"explain",
17231742
"Provide a detailed explanation of an error message",
1724-
"OPT",
1743+
"<OPT>",
17251744
),
17261745
opt(Stable, Flag, "", "test", "Build a test harness", ""),
1727-
opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", "TARGET"),
1728-
opt(Stable, Multi, "A", "allow", "Set lint allowed", "LINT"),
1729-
opt(Stable, Multi, "W", "warn", "Set lint warnings", "LINT"),
1730-
opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "LINT"),
1731-
opt(Stable, Multi, "D", "deny", "Set lint denied", "LINT"),
1732-
opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "LINT"),
1746+
opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", "<TARGET>"),
1747+
opt(Stable, Multi, "A", "allow", "Set lint allowed", "<LINT>"),
1748+
opt(Stable, Multi, "W", "warn", "Set lint warnings", "<LINT>"),
1749+
opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "<LINT>"),
1750+
opt(Stable, Multi, "D", "deny", "Set lint denied", "<LINT>"),
1751+
opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "<LINT>"),
17331752
opt(
17341753
Stable,
17351754
Multi,
17361755
"",
17371756
"cap-lints",
17381757
"Set the most restrictive lint level. More restrictive lints are capped at this level",
1739-
"LEVEL",
1758+
"<LEVEL>",
17401759
),
1741-
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
1760+
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "<OPT>[=<VALUE>]"),
17421761
opt(Stable, Flag, "V", "version", "Print version info and exit", ""),
17431762
opt(Stable, Flag, "v", "verbose", "Use verbose output", ""),
17441763
];
@@ -1752,47 +1771,47 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
17521771
"",
17531772
"extern",
17541773
"Specify where an external rust library is located",
1755-
"NAME[=PATH]",
1774+
"<NAME>[=<PATH>]",
17561775
),
1757-
opt(Stable, Opt, "", "sysroot", "Override the system root", "PATH"),
1758-
opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "FLAG"),
1776+
opt(Stable, Opt, "", "sysroot", "Override the system root", "<PATH>"),
1777+
opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "<FLAG>"),
17591778
opt(
17601779
Stable,
17611780
Opt,
17621781
"",
17631782
"error-format",
17641783
"How errors and other messages are produced",
1765-
"human|json|short",
1784+
"<human|json|short>",
17661785
),
1767-
opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "CONFIG"),
1786+
opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "<CONFIG>"),
17681787
opt(
17691788
Stable,
17701789
Opt,
17711790
"",
17721791
"color",
17731792
"Configure coloring of output:
1774-
auto = colorize, if output goes to a tty (default);
1775-
always = always colorize output;
1776-
never = never colorize output",
1777-
"auto|always|never",
1793+
* auto = colorize, if output goes to a tty (default);
1794+
* always = always colorize output;
1795+
* never = never colorize output",
1796+
"<auto|always|never>",
17781797
),
17791798
opt(
17801799
Stable,
17811800
Opt,
17821801
"",
17831802
"diagnostic-width",
17841803
"Inform rustc of the width of the output so that diagnostics can be truncated to fit",
1785-
"WIDTH",
1804+
"<WIDTH>",
17861805
),
17871806
opt(
17881807
Stable,
17891808
Multi,
17901809
"",
17911810
"remap-path-prefix",
17921811
"Remap source names in all output (compiler messages and output files)",
1793-
"FROM=TO",
1812+
"<FROM>=<TO>",
17941813
),
1795-
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "VAR=VALUE"),
1814+
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "<VAR>=<VALUE>"),
17961815
];
17971816
options.extend(verbose_only.into_iter().map(|mut opt| {
17981817
opt.is_verbose_help_only = true;
@@ -2792,7 +2811,7 @@ pub fn make_crate_type_option() -> RustcOptGroup {
27922811
"crate-type",
27932812
"Comma separated list of types of crates
27942813
for the compiler to emit",
2795-
"[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]",
2814+
"<bin|lib|rlib|dylib|cdylib|staticlib|proc-macro>",
27962815
)
27972816
}
27982817

compiler/rustc_span/src/edition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub const ALL_EDITIONS: &[Edition] = &[
4545
Edition::EditionFuture,
4646
];
4747

48-
pub const EDITION_NAME_LIST: &str = "2015|2018|2021|2024";
48+
pub const EDITION_NAME_LIST: &str = "<2015|2018|2021|2024>";
4949

5050
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
5151

tests/run-make/rustc-help/help-v.diff

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
@@ -63,10 +63,27 @@
1+
@@ -75,10 +75,28 @@
22
Set a codegen option
33
-V, --version Print version info and exit
44
-v, --verbose Use verbose output
5-
+ --extern NAME[=PATH]
5+
+ --extern <NAME>[=<PATH>]
66
+ Specify where an external rust library is located
7-
+ --sysroot PATH Override the system root
8-
+ --error-format human|json|short
7+
+ --sysroot <PATH>
8+
+ Override the system root
9+
+ --error-format <human|json|short>
910
+ How errors and other messages are produced
10-
+ --json CONFIG Configure the JSON output of the compiler
11-
+ --color auto|always|never
11+
+ --json <CONFIG> Configure the JSON output of the compiler
12+
+ --color <auto|always|never>
1213
+ Configure coloring of output:
13-
+ auto = colorize, if output goes to a tty (default);
14-
+ always = always colorize output;
15-
+ never = never colorize output
16-
+ --diagnostic-width WIDTH
14+
+ * auto = colorize, if output goes to a tty (default);
15+
+ * always = always colorize output;
16+
+ * never = never colorize output
17+
+ --diagnostic-width <WIDTH>
1718
+ Inform rustc of the width of the output so that
1819
+ diagnostics can be truncated to fit
19-
+ --remap-path-prefix FROM=TO
20+
+ --remap-path-prefix <FROM>=<TO>
2021
+ Remap source names in all output (compiler messages
2122
+ and output files)
2223
+ @path Read newline separated options from `path`

tests/run-make/rustc-help/help-v.stdout

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,32 @@ Usage: rustc [OPTIONS] INPUT
22

33
Options:
44
-h, --help Display this message
5-
--cfg SPEC Configure the compilation environment.
6-
SPEC supports the syntax `NAME[="VALUE"]`.
7-
--check-cfg SPEC
5+
--cfg <SPEC> Configure the compilation environment.
6+
SPEC supports the syntax `<NAME>[="VALUE"]`.
7+
--check-cfg <SPEC>
88
Provide list of expected cfgs for checking
9-
-L [KIND=]PATH Add a directory to the library search path. The
10-
optional KIND can be one of dependency, crate, native,
11-
framework, or all (the default).
12-
-l [KIND[:MODIFIERS]=]NAME[:RENAME]
9+
-L [<KIND>=]<PATH> Add a directory to the library search path. The
10+
optional <KIND> can be one of
11+
<dependency|crate|native|framework|all> (default:
12+
all).
13+
-l [<KIND>[:<MODIFIERS>]=]<NAME>[:<RENAME>]
1314
Link the generated crate(s) to the specified native
14-
library NAME. The optional KIND can be one of
15-
static, framework, or dylib (the default).
16-
Optional comma separated MODIFIERS
17-
(bundle|verbatim|whole-archive|as-needed)
15+
library <NAME>. The optional <KIND> can be one of
16+
<static|framework|dylib> (default: dylib).
17+
Optional comma separated <MODIFIERS>
18+
<bundle|verbatim|whole-archive|as-needed>
1819
may be specified each with a prefix of either '+' to
1920
enable or '-' to disable.
20-
--crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
21+
--crate-type <bin|lib|rlib|dylib|cdylib|staticlib|proc-macro>
2122
Comma separated list of types of crates
2223
for the compiler to emit
23-
--crate-name NAME
24+
--crate-name <NAME>
2425
Specify the name of the crate being built
25-
--edition 2015|2018|2021|2024
26+
--edition <2015|2018|2021|2024>
2627
Specify which edition of the compiler to use when
2728
compiling code. The default is 2015 and the latest
2829
stable edition is 2024.
29-
--emit TYPE[=FILE]
30+
--emit <TYPE>[=<FILE>]
3031
Comma separated list of types of output for the
3132
compiler to emit.
3233
Each TYPE has the default FILE name:
@@ -39,45 +40,57 @@ Options:
3940
* mir - CRATE_NAME.mir
4041
* obj - CRATE_NAME.o
4142
* thin-link-bitcode - CRATE_NAME.indexing.o
43+
--print <INFO>[=<FILE>]
44+
Compiler information to print on stdout (or to a file)
45+
INFO may be one of
46+
<all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models>.
47+
-g Equivalent to -C debuginfo=2
48+
-O Equivalent to -C opt-level=3
49+
-o <FILENAME> Write output to <FILENAME>
50+
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
51+
Comma separated list of types of output for the
52+
compiler to emit
4253
--print INFO[=FILE]
4354
Compiler information to print on stdout (or to a file)
4455
INFO may be one of
45-
(all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models).
56+
<all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models>.
4657
-g Equivalent to -C debuginfo=2
4758
-O Equivalent to -C opt-level=3
48-
-o FILENAME Write output to <filename>
49-
--out-dir DIR Write output to compiler-chosen filename in <dir>
50-
--explain OPT Provide a detailed explanation of an error message
59+
-o <FILENAME> Write output to <FILENAME>
60+
--out-dir <DIR> Write output to compiler-chosen filename in <DIR>
61+
--explain <OPT> Provide a detailed explanation of an error message
5162
--test Build a test harness
52-
--target TARGET Target triple for which the code is compiled
53-
-A, --allow LINT Set lint allowed
54-
-W, --warn LINT Set lint warnings
55-
--force-warn LINT
63+
--target <TARGET>
64+
Target triple for which the code is compiled
65+
-A, --allow <LINT> Set lint allowed
66+
-W, --warn <LINT> Set lint warnings
67+
--force-warn <LINT>
5668
Set lint force-warn
57-
-D, --deny LINT Set lint denied
58-
-F, --forbid LINT Set lint forbidden
59-
--cap-lints LEVEL
69+
-D, --deny <LINT> Set lint denied
70+
-F, --forbid <LINT> Set lint forbidden
71+
--cap-lints <LEVEL>
6072
Set the most restrictive lint level. More restrictive
6173
lints are capped at this level
62-
-C, --codegen OPT[=VALUE]
74+
-C, --codegen <OPT>[=<VALUE>]
6375
Set a codegen option
6476
-V, --version Print version info and exit
6577
-v, --verbose Use verbose output
66-
--extern NAME[=PATH]
78+
--extern <NAME>[=<PATH>]
6779
Specify where an external rust library is located
68-
--sysroot PATH Override the system root
69-
--error-format human|json|short
80+
--sysroot <PATH>
81+
Override the system root
82+
--error-format <human|json|short>
7083
How errors and other messages are produced
71-
--json CONFIG Configure the JSON output of the compiler
72-
--color auto|always|never
84+
--json <CONFIG> Configure the JSON output of the compiler
85+
--color <auto|always|never>
7386
Configure coloring of output:
74-
auto = colorize, if output goes to a tty (default);
75-
always = always colorize output;
76-
never = never colorize output
77-
--diagnostic-width WIDTH
87+
* auto = colorize, if output goes to a tty (default);
88+
* always = always colorize output;
89+
* never = never colorize output
90+
--diagnostic-width <WIDTH>
7891
Inform rustc of the width of the output so that
7992
diagnostics can be truncated to fit
80-
--remap-path-prefix FROM=TO
93+
--remap-path-prefix <FROM>=<TO>
8194
Remap source names in all output (compiler messages
8295
and output files)
8396
@path Read newline separated options from `path`

0 commit comments

Comments
 (0)