Rollup merge of #103839 - Nilstrieb:print-list, r=compiler-errors
Print valid `--print` requests if request is invalid When someone makes a typo, it can be useful to see the valid options. This is also useful if someone wants to find out about all the options.
This commit is contained in:
commit
c2affd5049
@ -1789,34 +1789,49 @@ fn collect_print_requests(
|
|||||||
cg.target_feature = String::new();
|
cg.target_feature = String::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
prints.extend(matches.opt_strs("print").into_iter().map(|s| match &*s {
|
const PRINT_REQUESTS: &[(&str, PrintRequest)] = &[
|
||||||
"crate-name" => PrintRequest::CrateName,
|
("crate-name", PrintRequest::CrateName),
|
||||||
"file-names" => PrintRequest::FileNames,
|
("file-names", PrintRequest::FileNames),
|
||||||
"sysroot" => PrintRequest::Sysroot,
|
("sysroot", PrintRequest::Sysroot),
|
||||||
"target-libdir" => PrintRequest::TargetLibdir,
|
("target-libdir", PrintRequest::TargetLibdir),
|
||||||
"cfg" => PrintRequest::Cfg,
|
("cfg", PrintRequest::Cfg),
|
||||||
"calling-conventions" => PrintRequest::CallingConventions,
|
("calling-conventions", PrintRequest::CallingConventions),
|
||||||
"target-list" => PrintRequest::TargetList,
|
("target-list", PrintRequest::TargetList),
|
||||||
"target-cpus" => PrintRequest::TargetCPUs,
|
("target-cpus", PrintRequest::TargetCPUs),
|
||||||
"target-features" => PrintRequest::TargetFeatures,
|
("target-features", PrintRequest::TargetFeatures),
|
||||||
"relocation-models" => PrintRequest::RelocationModels,
|
("relocation-models", PrintRequest::RelocationModels),
|
||||||
"code-models" => PrintRequest::CodeModels,
|
("code-models", PrintRequest::CodeModels),
|
||||||
"tls-models" => PrintRequest::TlsModels,
|
("tls-models", PrintRequest::TlsModels),
|
||||||
"native-static-libs" => PrintRequest::NativeStaticLibs,
|
("native-static-libs", PrintRequest::NativeStaticLibs),
|
||||||
"stack-protector-strategies" => PrintRequest::StackProtectorStrategies,
|
("stack-protector-strategies", PrintRequest::StackProtectorStrategies),
|
||||||
"target-spec-json" => {
|
("target-spec-json", PrintRequest::TargetSpec),
|
||||||
if unstable_opts.unstable_options {
|
("link-args", PrintRequest::LinkArgs),
|
||||||
PrintRequest::TargetSpec
|
];
|
||||||
} else {
|
|
||||||
|
prints.extend(matches.opt_strs("print").into_iter().map(|req| {
|
||||||
|
match PRINT_REQUESTS.iter().find(|&&(name, _)| name == req) {
|
||||||
|
Some((_, PrintRequest::TargetSpec)) => {
|
||||||
|
if unstable_opts.unstable_options {
|
||||||
|
PrintRequest::TargetSpec
|
||||||
|
} else {
|
||||||
|
early_error(
|
||||||
|
error_format,
|
||||||
|
"the `-Z unstable-options` flag must also be passed to \
|
||||||
|
enable the target-spec-json print option",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(&(_, print_request)) => print_request,
|
||||||
|
None => {
|
||||||
|
let prints =
|
||||||
|
PRINT_REQUESTS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
|
||||||
|
let prints = prints.join(", ");
|
||||||
early_error(
|
early_error(
|
||||||
error_format,
|
error_format,
|
||||||
"the `-Z unstable-options` flag must also be passed to \
|
&format!("unknown print request `{req}`. Valid print requests are: {prints}"),
|
||||||
enable the target-spec-json print option",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"link-args" => PrintRequest::LinkArgs,
|
|
||||||
req => early_error(error_format, &format!("unknown print request `{req}`")),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
prints
|
prints
|
||||||
|
4
src/test/run-make/valid-print-requests/Makefile
Normal file
4
src/test/run-make/valid-print-requests/Makefile
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
include ../../run-make-fulldeps/tools.mk
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(RUSTC) --print uwu 2>&1 | diff - valid-print-requests.stderr
|
@ -0,0 +1,2 @@
|
|||||||
|
error: unknown print request `uwu`. Valid print requests are: `crate-name`, `file-names`, `sysroot`, `target-libdir`, `cfg`, `calling-conventions`, `target-list`, `target-cpus`, `target-features`, `relocation-models`, `code-models`, `tls-models`, `native-static-libs`, `stack-protector-strategies`, `target-spec-json`, `link-args`
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user