Rollup merge of #124320 - Urgau:print-check-cfg, r=petrochenkov
Add `--print=check-cfg` to get the expected configs This PR adds a new `--print` variant `check-cfg` to get the expected configs. Details and rational can be found on the MCP: https://github.com/rust-lang/compiler-team/issues/743 ``@rustbot`` label +F-check-cfg +S-waiting-on-MCP r? ``@petrochenkov``
This commit is contained in:
commit
7e441a11a1
8 changed files with 184 additions and 2 deletions
|
@ -804,6 +804,39 @@ fn print_crate_info(
|
|||
println_info!("{cfg}");
|
||||
}
|
||||
}
|
||||
CheckCfg => {
|
||||
let mut check_cfgs: Vec<String> = Vec::with_capacity(410);
|
||||
|
||||
// INSTABILITY: We are sorting the output below.
|
||||
#[allow(rustc::potential_query_instability)]
|
||||
for (name, expected_values) in &sess.psess.check_config.expecteds {
|
||||
use crate::config::ExpectedValues;
|
||||
match expected_values {
|
||||
ExpectedValues::Any => check_cfgs.push(format!("{name}=any()")),
|
||||
ExpectedValues::Some(values) => {
|
||||
check_cfgs.extend(values.iter().map(|value| {
|
||||
if let Some(value) = value {
|
||||
format!("{name}=\"{value}\"")
|
||||
} else {
|
||||
name.to_string()
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
check_cfgs.sort_unstable();
|
||||
if !sess.psess.check_config.exhaustive_names {
|
||||
if !sess.psess.check_config.exhaustive_values {
|
||||
println_info!("any()=any()");
|
||||
} else {
|
||||
println_info!("any()");
|
||||
}
|
||||
}
|
||||
for check_cfg in check_cfgs {
|
||||
println_info!("{check_cfg}");
|
||||
}
|
||||
}
|
||||
CallingConventions => {
|
||||
let mut calling_conventions = rustc_target::spec::abi::all_names();
|
||||
calling_conventions.sort_unstable();
|
||||
|
|
|
@ -773,6 +773,7 @@ pub enum PrintKind {
|
|||
TargetLibdir,
|
||||
CrateName,
|
||||
Cfg,
|
||||
CheckCfg,
|
||||
CallingConventions,
|
||||
TargetList,
|
||||
TargetCPUs,
|
||||
|
@ -1443,7 +1444,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
|
|||
"",
|
||||
"print",
|
||||
"Compiler information to print on stdout",
|
||||
"[crate-name|file-names|sysroot|target-libdir|cfg|calling-conventions|\
|
||||
"[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]",
|
||||
|
@ -1859,6 +1860,7 @@ fn collect_print_requests(
|
|||
("all-target-specs-json", PrintKind::AllTargetSpecs),
|
||||
("calling-conventions", PrintKind::CallingConventions),
|
||||
("cfg", PrintKind::Cfg),
|
||||
("check-cfg", PrintKind::CheckCfg),
|
||||
("code-models", PrintKind::CodeModels),
|
||||
("crate-name", PrintKind::CrateName),
|
||||
("deployment-target", PrintKind::DeploymentTarget),
|
||||
|
@ -1908,6 +1910,16 @@ fn collect_print_requests(
|
|||
);
|
||||
}
|
||||
}
|
||||
Some((_, PrintKind::CheckCfg)) => {
|
||||
if unstable_opts.unstable_options {
|
||||
PrintKind::CheckCfg
|
||||
} else {
|
||||
early_dcx.early_fatal(
|
||||
"the `-Z unstable-options` flag must also be passed to \
|
||||
enable the check-cfg print option",
|
||||
);
|
||||
}
|
||||
}
|
||||
Some(&(_, print_kind)) => print_kind,
|
||||
None => {
|
||||
let prints =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue