Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1998cf7

Browse files
authoredMar 3, 2025
Rollup merge of #137862 - mtoner23:print-help, r=nnethercote
ensure we always print all --print options in help Closes #137853 Refactors the PRINT_KINDS map into a public const so we always print every option for print. the list is quite long now, and idk if long term we want to keep printing all these options from --help.
2 parents 0b66424 + 6f505ba commit 1998cf7

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed
 

‎compiler/rustc_session/src/config.rs

+34-30
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ mod cfg;
4242
mod native_libs;
4343
pub mod sigpipe;
4444

45+
pub const PRINT_KINDS: &[(&str, PrintKind)] = &[
46+
// tidy-alphabetical-start
47+
("all-target-specs-json", PrintKind::AllTargetSpecs),
48+
("calling-conventions", PrintKind::CallingConventions),
49+
("cfg", PrintKind::Cfg),
50+
("check-cfg", PrintKind::CheckCfg),
51+
("code-models", PrintKind::CodeModels),
52+
("crate-name", PrintKind::CrateName),
53+
("deployment-target", PrintKind::DeploymentTarget),
54+
("file-names", PrintKind::FileNames),
55+
("host-tuple", PrintKind::HostTuple),
56+
("link-args", PrintKind::LinkArgs),
57+
("native-static-libs", PrintKind::NativeStaticLibs),
58+
("relocation-models", PrintKind::RelocationModels),
59+
("split-debuginfo", PrintKind::SplitDebuginfo),
60+
("stack-protector-strategies", PrintKind::StackProtectorStrategies),
61+
("sysroot", PrintKind::Sysroot),
62+
("target-cpus", PrintKind::TargetCPUs),
63+
("target-features", PrintKind::TargetFeatures),
64+
("target-libdir", PrintKind::TargetLibdir),
65+
("target-list", PrintKind::TargetList),
66+
("target-spec-json", PrintKind::TargetSpec),
67+
("tls-models", PrintKind::TlsModels),
68+
// tidy-alphabetical-end
69+
];
70+
4571
/// The different settings that the `-C strip` flag can have.
4672
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
4773
pub enum Strip {
@@ -1508,6 +1534,13 @@ The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE
15081534
)
15091535
});
15101536

1537+
static PRINT_KINDS_STRING: LazyLock<String> = LazyLock::new(|| {
1538+
format!(
1539+
"[{}]",
1540+
PRINT_KINDS.iter().map(|(name, _)| format!("{name}")).collect::<Vec<_>>().join("|")
1541+
)
1542+
});
1543+
15111544
/// Returns all rustc command line options, including metadata for
15121545
/// each option, such as whether the option is stable.
15131546
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
@@ -1568,10 +1601,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
15681601
"",
15691602
"print",
15701603
"Compiler information to print on stdout",
1571-
"[crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|\
1572-
target-list|target-cpus|target-features|relocation-models|code-models|\
1573-
tls-models|target-spec-json|all-target-specs-json|native-static-libs|\
1574-
stack-protector-strategies|link-args|deployment-target]",
1604+
&PRINT_KINDS_STRING,
15751605
),
15761606
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
15771607
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
@@ -1999,32 +2029,6 @@ fn collect_print_requests(
19992029
cg.target_feature = String::new();
20002030
}
20012031

2002-
const PRINT_KINDS: &[(&str, PrintKind)] = &[
2003-
// tidy-alphabetical-start
2004-
("all-target-specs-json", PrintKind::AllTargetSpecs),
2005-
("calling-conventions", PrintKind::CallingConventions),
2006-
("cfg", PrintKind::Cfg),
2007-
("check-cfg", PrintKind::CheckCfg),
2008-
("code-models", PrintKind::CodeModels),
2009-
("crate-name", PrintKind::CrateName),
2010-
("deployment-target", PrintKind::DeploymentTarget),
2011-
("file-names", PrintKind::FileNames),
2012-
("host-tuple", PrintKind::HostTuple),
2013-
("link-args", PrintKind::LinkArgs),
2014-
("native-static-libs", PrintKind::NativeStaticLibs),
2015-
("relocation-models", PrintKind::RelocationModels),
2016-
("split-debuginfo", PrintKind::SplitDebuginfo),
2017-
("stack-protector-strategies", PrintKind::StackProtectorStrategies),
2018-
("sysroot", PrintKind::Sysroot),
2019-
("target-cpus", PrintKind::TargetCPUs),
2020-
("target-features", PrintKind::TargetFeatures),
2021-
("target-libdir", PrintKind::TargetLibdir),
2022-
("target-list", PrintKind::TargetList),
2023-
("target-spec-json", PrintKind::TargetSpec),
2024-
("tls-models", PrintKind::TlsModels),
2025-
// tidy-alphabetical-end
2026-
];
2027-
20282032
// We disallow reusing the same path in multiple prints, such as `--print
20292033
// cfg=output.txt --print link-args=output.txt`, because outputs are printed
20302034
// by disparate pieces of the compiler, and keeping track of which files

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Options:
2929
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
3030
Comma separated list of types of output for the
3131
compiler to emit
32-
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
32+
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
3333
Compiler information to print on stdout
3434
-g Equivalent to -C debuginfo=2
3535
-O Equivalent to -C opt-level=3

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Options:
2929
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
3030
Comma separated list of types of output for the
3131
compiler to emit
32-
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
32+
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
3333
Compiler information to print on stdout
3434
-g Equivalent to -C debuginfo=2
3535
-O Equivalent to -C opt-level=3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: Argument to option 'print' missing
22
Usage:
3-
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
3+
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
44
Compiler information to print on stdout
55

0 commit comments

Comments
 (0)
Failed to load comments.