Skip to content

Commit 0f829fc

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

File tree

8 files changed

+134
-120
lines changed

8 files changed

+134
-120
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE
15651565
static PRINT_HELP: LazyLock<String> = LazyLock::new(|| {
15661566
format!(
15671567
"Compiler information to print on stdout (or to a file)\n\
1568-
INFO may be one of ({}).",
1568+
INFO may be one of <{}>.",
15691569
PRINT_KINDS.iter().map(|(name, _)| format!("{name}")).collect::<Vec<_>>().join("|")
15701570
)
15711571
});
@@ -1586,73 +1586,80 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
15861586
"",
15871587
"cfg",
15881588
"Configure the compilation environment.\n\
1589-
SPEC supports the syntax `NAME[=\"VALUE\"]`.",
1590-
"SPEC",
1589+
SPEC supports the syntax `<NAME>[=\"VALUE\"]`.",
1590+
"<SPEC>",
15911591
),
1592-
opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"),
1592+
opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", "<SPEC>"),
15931593
opt(
15941594
Stable,
15951595
Multi,
15961596
"L",
15971597
"",
15981598
"Add a directory to the library search path. \
1599-
The optional KIND can be one of dependency, crate, native, framework, or all (the default).",
1600-
"[KIND=]PATH",
1599+
The optional <KIND> can be one of <dependency|crate|native|framework|all> (default: all).",
1600+
"[<KIND>=]<PATH>",
16011601
),
16021602
opt(
16031603
Stable,
16041604
Multi,
16051605
"l",
16061606
"",
16071607
"Link the generated crate(s) to the specified native\n\
1608-
library NAME. The optional KIND can be one of\n\
1609-
static, framework, or dylib (the default).\n\
1610-
Optional comma separated MODIFIERS\n\
1611-
(bundle|verbatim|whole-archive|as-needed)\n\
1608+
library <NAME>. The optional <KIND> can be one of\n\
1609+
<static|framework|dylib> (default: dylib).\n\
1610+
Optional comma separated <MODIFIERS>\n\
1611+
<bundle|verbatim|whole-archive|as-needed>\n\
16121612
may be specified each with a prefix of either '+' to\n\
16131613
enable or '-' to disable.",
1614-
"[KIND[:MODIFIERS]=]NAME[:RENAME]",
1614+
"[<KIND>[:<MODIFIERS>]=]<NAME>[:<RENAME>]",
16151615
),
16161616
make_crate_type_option(),
1617-
opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "NAME"),
1617+
opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "<NAME>"),
16181618
opt(Stable, Opt, "", "edition", &EDITION_STRING, EDITION_NAME_LIST),
16191619
opt(
16201620
Stable,
16211621
Multi,
16221622
"",
16231623
"emit",
16241624
"Comma separated list of types of output for the compiler to emit",
1625-
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]",
1625+
"<asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir>",
16261626
),
1627-
opt(Stable, Multi, "", "print", &PRINT_HELP, "INFO[=FILE]"),
1627+
opt(Stable, Multi, "", "print", &PRINT_HELP, "<INFO>[=<FILE>]"),
16281628
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
16291629
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
1630-
opt(Stable, Opt, "o", "", "Write output to <filename>", "FILENAME"),
1631-
opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
1630+
opt(Stable, Opt, "o", "", "Write output to <FILENAME>", "<FILENAME>"),
1631+
opt(
1632+
Stable,
1633+
Opt,
1634+
"",
1635+
"out-dir",
1636+
"Write output to compiler-chosen filename in <DIR>",
1637+
"<DIR>",
1638+
),
16321639
opt(
16331640
Stable,
16341641
Opt,
16351642
"",
16361643
"explain",
16371644
"Provide a detailed explanation of an error message",
1638-
"OPT",
1645+
"<OPT>",
16391646
),
16401647
opt(Stable, Flag, "", "test", "Build a test harness", ""),
1641-
opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", "TARGET"),
1642-
opt(Stable, Multi, "A", "allow", "Set lint allowed", "LINT"),
1643-
opt(Stable, Multi, "W", "warn", "Set lint warnings", "LINT"),
1644-
opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "LINT"),
1645-
opt(Stable, Multi, "D", "deny", "Set lint denied", "LINT"),
1646-
opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "LINT"),
1648+
opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", "<TARGET>"),
1649+
opt(Stable, Multi, "A", "allow", "Set lint allowed", "<LINT>"),
1650+
opt(Stable, Multi, "W", "warn", "Set lint warnings", "<LINT>"),
1651+
opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "<LINT>"),
1652+
opt(Stable, Multi, "D", "deny", "Set lint denied", "<LINT>"),
1653+
opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "<LINT>"),
16471654
opt(
16481655
Stable,
16491656
Multi,
16501657
"",
16511658
"cap-lints",
16521659
"Set the most restrictive lint level. More restrictive lints are capped at this level",
1653-
"LEVEL",
1660+
"<LEVEL>",
16541661
),
1655-
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
1662+
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "<OPT>[=<VALUE>]"),
16561663
opt(Stable, Flag, "V", "version", "Print version info and exit", ""),
16571664
opt(Stable, Flag, "v", "verbose", "Use verbose output", ""),
16581665
];
@@ -1666,47 +1673,47 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
16661673
"",
16671674
"extern",
16681675
"Specify where an external rust library is located",
1669-
"NAME[=PATH]",
1676+
"<NAME>[=<PATH>]",
16701677
),
1671-
opt(Stable, Opt, "", "sysroot", "Override the system root", "PATH"),
1672-
opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "FLAG"),
1678+
opt(Stable, Opt, "", "sysroot", "Override the system root", "<PATH>"),
1679+
opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "<FLAG>"),
16731680
opt(
16741681
Stable,
16751682
Opt,
16761683
"",
16771684
"error-format",
16781685
"How errors and other messages are produced",
1679-
"human|json|short",
1686+
"<human|json|short>",
16801687
),
1681-
opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "CONFIG"),
1688+
opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "<CONFIG>"),
16821689
opt(
16831690
Stable,
16841691
Opt,
16851692
"",
16861693
"color",
16871694
"Configure coloring of output:
1688-
auto = colorize, if output goes to a tty (default);
1689-
always = always colorize output;
1690-
never = never colorize output",
1691-
"auto|always|never",
1695+
* auto = colorize, if output goes to a tty (default);
1696+
* always = always colorize output;
1697+
* never = never colorize output",
1698+
"<auto|always|never>",
16921699
),
16931700
opt(
16941701
Stable,
16951702
Opt,
16961703
"",
16971704
"diagnostic-width",
16981705
"Inform rustc of the width of the output so that diagnostics can be truncated to fit",
1699-
"WIDTH",
1706+
"<WIDTH>",
17001707
),
17011708
opt(
17021709
Stable,
17031710
Multi,
17041711
"",
17051712
"remap-path-prefix",
17061713
"Remap source names in all output (compiler messages and output files)",
1707-
"FROM=TO",
1714+
"<FROM>=<TO>",
17081715
),
1709-
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "VAR=VALUE"),
1716+
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "<VAR>=<VALUE>"),
17101717
];
17111718
options.extend(verbose_only.into_iter().map(|mut opt| {
17121719
opt.is_verbose_help_only = true;
@@ -2706,7 +2713,7 @@ pub fn make_crate_type_option() -> RustcOptGroup {
27062713
"crate-type",
27072714
"Comma separated list of types of crates
27082715
for the compiler to emit",
2709-
"[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]",
2716+
"<bin|lib|rlib|dylib|cdylib|staticlib|proc-macro>",
27102717
)
27112718
}
27122719

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-
@@ -53,10 +53,27 @@
1+
@@ -55,10 +55,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: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,75 @@ 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 [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
30+
--emit <asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir>
3031
Comma separated list of types of output for the
3132
compiler to emit
32-
--print INFO[=FILE]
33+
--print <INFO>[=<FILE>]
3334
Compiler information to print on stdout (or to a file)
3435
INFO may be one of
35-
(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).
36+
<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>.
3637
-g Equivalent to -C debuginfo=2
3738
-O Equivalent to -C opt-level=3
38-
-o FILENAME Write output to <filename>
39-
--out-dir DIR Write output to compiler-chosen filename in <dir>
40-
--explain OPT Provide a detailed explanation of an error message
39+
-o <FILENAME> Write output to <FILENAME>
40+
--out-dir <DIR> Write output to compiler-chosen filename in <DIR>
41+
--explain <OPT> Provide a detailed explanation of an error message
4142
--test Build a test harness
42-
--target TARGET Target triple for which the code is compiled
43-
-A, --allow LINT Set lint allowed
44-
-W, --warn LINT Set lint warnings
45-
--force-warn LINT
43+
--target <TARGET>
44+
Target triple for which the code is compiled
45+
-A, --allow <LINT> Set lint allowed
46+
-W, --warn <LINT> Set lint warnings
47+
--force-warn <LINT>
4648
Set lint force-warn
47-
-D, --deny LINT Set lint denied
48-
-F, --forbid LINT Set lint forbidden
49-
--cap-lints LEVEL
49+
-D, --deny <LINT> Set lint denied
50+
-F, --forbid <LINT> Set lint forbidden
51+
--cap-lints <LEVEL>
5052
Set the most restrictive lint level. More restrictive
5153
lints are capped at this level
52-
-C, --codegen OPT[=VALUE]
54+
-C, --codegen <OPT>[=<VALUE>]
5355
Set a codegen option
5456
-V, --version Print version info and exit
5557
-v, --verbose Use verbose output
56-
--extern NAME[=PATH]
58+
--extern <NAME>[=<PATH>]
5759
Specify where an external rust library is located
58-
--sysroot PATH Override the system root
59-
--error-format human|json|short
60+
--sysroot <PATH>
61+
Override the system root
62+
--error-format <human|json|short>
6063
How errors and other messages are produced
61-
--json CONFIG Configure the JSON output of the compiler
62-
--color auto|always|never
64+
--json <CONFIG> Configure the JSON output of the compiler
65+
--color <auto|always|never>
6366
Configure coloring of output:
64-
auto = colorize, if output goes to a tty (default);
65-
always = always colorize output;
66-
never = never colorize output
67-
--diagnostic-width WIDTH
67+
* auto = colorize, if output goes to a tty (default);
68+
* always = always colorize output;
69+
* never = never colorize output
70+
--diagnostic-width <WIDTH>
6871
Inform rustc of the width of the output so that
6972
diagnostics can be truncated to fit
70-
--remap-path-prefix FROM=TO
73+
--remap-path-prefix <FROM>=<TO>
7174
Remap source names in all output (compiler messages
7275
and output files)
7376
@path Read newline separated options from `path`

0 commit comments

Comments
 (0)