Skip to content

Commit d054690

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

File tree

9 files changed

+123
-115
lines changed

9 files changed

+123
-115
lines changed

compiler/rustc_session/src/config.rs

+36-36
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,18 +1679,18 @@ 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,
@@ -1699,46 +1699,46 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
16991699
"",
17001700
"Link the generated crate(s) to the specified native\n\
17011701
library NAME. The optional KIND can be one of\n\
1702-
static, framework, or dylib (the default).\n\
1702+
<static|framework|dylib> (default: dylib).\n\
17031703
Optional comma separated MODIFIERS\n\
1704-
(bundle|verbatim|whole-archive|as-needed)\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]"),
1713-
opt(Stable, Multi, "", "print", &PRINT_HELP, "INFO[=FILE]"),
1712+
opt(Stable, Multi, "", "emit", &EMIT_HELP, "<TYPE>[=<FILE>]"),
1713+
opt(Stable, Multi, "", "print", &PRINT_HELP, "<INFO>[=<FILE>]"),
17141714
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
17151715
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"),
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>"),
17181718
opt(
17191719
Stable,
17201720
Opt,
17211721
"",
17221722
"explain",
17231723
"Provide a detailed explanation of an error message",
1724-
"OPT",
1724+
"<OPT>",
17251725
),
17261726
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"),
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>"),
17331733
opt(
17341734
Stable,
17351735
Multi,
17361736
"",
17371737
"cap-lints",
17381738
"Set the most restrictive lint level. More restrictive lints are capped at this level",
1739-
"LEVEL",
1739+
"<LEVEL>",
17401740
),
1741-
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
1741+
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "<OPT>[=<VALUE>]"),
17421742
opt(Stable, Flag, "V", "version", "Print version info and exit", ""),
17431743
opt(Stable, Flag, "v", "verbose", "Use verbose output", ""),
17441744
];
@@ -1752,47 +1752,47 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
17521752
"",
17531753
"extern",
17541754
"Specify where an external rust library is located",
1755-
"NAME[=PATH]",
1755+
"<NAME>[=<PATH>]",
17561756
),
1757-
opt(Stable, Opt, "", "sysroot", "Override the system root", "PATH"),
1758-
opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "FLAG"),
1757+
opt(Stable, Opt, "", "sysroot", "Override the system root", "<PATH>"),
1758+
opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "<FLAG>"),
17591759
opt(
17601760
Stable,
17611761
Opt,
17621762
"",
17631763
"error-format",
17641764
"How errors and other messages are produced",
1765-
"human|json|short",
1765+
"<human|json|short>",
17661766
),
1767-
opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "CONFIG"),
1767+
opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "<CONFIG>"),
17681768
opt(
17691769
Stable,
17701770
Opt,
17711771
"",
17721772
"color",
17731773
"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",
1774+
* auto = colorize, if output goes to a tty (default);
1775+
* always = always colorize output;
1776+
* never = never colorize output",
1777+
"<auto|always|never>",
17781778
),
17791779
opt(
17801780
Stable,
17811781
Opt,
17821782
"",
17831783
"diagnostic-width",
17841784
"Inform rustc of the width of the output so that diagnostics can be truncated to fit",
1785-
"WIDTH",
1785+
"<WIDTH>",
17861786
),
17871787
opt(
17881788
Stable,
17891789
Multi,
17901790
"",
17911791
"remap-path-prefix",
17921792
"Remap source names in all output (compiler messages and output files)",
1793-
"FROM=TO",
1793+
"<FROM>=<TO>",
17941794
),
1795-
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "VAR=VALUE"),
1795+
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "<VAR>=<VALUE>"),
17961796
];
17971797
options.extend(verbose_only.into_iter().map(|mut opt| {
17981798
opt.is_verbose_help_only = true;
@@ -2792,7 +2792,7 @@ pub fn make_crate_type_option() -> RustcOptGroup {
27922792
"crate-type",
27932793
"Comma separated list of types of crates
27942794
for the compiler to emit",
2795-
"[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]",
2795+
"<bin|lib|rlib|dylib|cdylib|staticlib|proc-macro>",
27962796
)
27972797
}
27982798

compiler/rustc_span/src/edition.rs

+1-1
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|future>";
4949

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

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
@@ -63,10 +63,27 @@
1+
@@ -65,10 +65,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

+39-36
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
1415
library NAME. The optional KIND can be one of
15-
static, framework, or dylib (the default).
16+
<static|framework|dylib> (default: dylib).
1617
Optional comma separated MODIFIERS
17-
(bundle|verbatim|whole-archive|as-needed)
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|future>
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,47 @@ Options:
3940
* mir - CRATE_NAME.mir
4041
* obj - CRATE_NAME.o
4142
* thin-link-bitcode - CRATE_NAME.indexing.o
42-
--print INFO[=FILE]
43+
--print <INFO>[=<FILE>]
4344
Compiler information to print on stdout (or to a file)
4445
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).
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>.
4647
-g Equivalent to -C debuginfo=2
4748
-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
49+
-o <FILENAME> Write output to FILENAME
50+
--out-dir <DIR> Write output to compiler-chosen filename in DIR
51+
--explain <OPT> Provide a detailed explanation of an error message
5152
--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
53+
--target <TARGET>
54+
Target triple for which the code is compiled
55+
-A, --allow <LINT> Set lint allowed
56+
-W, --warn <LINT> Set lint warnings
57+
--force-warn <LINT>
5658
Set lint force-warn
57-
-D, --deny LINT Set lint denied
58-
-F, --forbid LINT Set lint forbidden
59-
--cap-lints LEVEL
59+
-D, --deny <LINT> Set lint denied
60+
-F, --forbid <LINT> Set lint forbidden
61+
--cap-lints <LEVEL>
6062
Set the most restrictive lint level. More restrictive
6163
lints are capped at this level
62-
-C, --codegen OPT[=VALUE]
64+
-C, --codegen <OPT>[=<VALUE>]
6365
Set a codegen option
6466
-V, --version Print version info and exit
6567
-v, --verbose Use verbose output
66-
--extern NAME[=PATH]
68+
--extern <NAME>[=<PATH>]
6769
Specify where an external rust library is located
68-
--sysroot PATH Override the system root
69-
--error-format human|json|short
70+
--sysroot <PATH>
71+
Override the system root
72+
--error-format <human|json|short>
7073
How errors and other messages are produced
71-
--json CONFIG Configure the JSON output of the compiler
72-
--color auto|always|never
74+
--json <CONFIG> Configure the JSON output of the compiler
75+
--color <auto|always|never>
7376
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
77+
* auto = colorize, if output goes to a tty (default);
78+
* always = always colorize output;
79+
* never = never colorize output
80+
--diagnostic-width <WIDTH>
7881
Inform rustc of the width of the output so that
7982
diagnostics can be truncated to fit
80-
--remap-path-prefix FROM=TO
83+
--remap-path-prefix <FROM>=<TO>
8184
Remap source names in all output (compiler messages
8285
and output files)
8386
@path Read newline separated options from `path`

0 commit comments

Comments
 (0)