Skip to content

Commit 1ddb2ef

Browse files
authored
Unrolled build for rust-lang#128961
Rollup merge of rust-lang#128961 - GKFX:issue-128930-explain-missing-option, r=jieyouxu Fix rust-lang#128930: Print documentation of CLI options missing their arg Fix rust-lang#128930. Failing to give an argument to CLI options which require it now prints something like: ``` $ rustc --print error: Argument to option 'print' missing Usage: --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] Compiler information to print on stdout ```
2 parents e9e13a6 + ae75a9b commit 1ddb2ef

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

compiler/rustc_driver_impl/src/lib.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1218,17 +1218,30 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
12181218
// Parse with *all* options defined in the compiler, we don't worry about
12191219
// option stability here we just want to parse as much as possible.
12201220
let mut options = getopts::Options::new();
1221-
for option in config::rustc_optgroups() {
1221+
let optgroups = config::rustc_optgroups();
1222+
for option in &optgroups {
12221223
(option.apply)(&mut options);
12231224
}
12241225
let matches = options.parse(args).unwrap_or_else(|e| {
1225-
let msg = match e {
1226+
let msg: Option<String> = match e {
12261227
getopts::Fail::UnrecognizedOption(ref opt) => CG_OPTIONS
12271228
.iter()
12281229
.map(|&(name, ..)| ('C', name))
12291230
.chain(Z_OPTIONS.iter().map(|&(name, ..)| ('Z', name)))
12301231
.find(|&(_, name)| *opt == name.replace('_', "-"))
12311232
.map(|(flag, _)| format!("{e}. Did you mean `-{flag} {opt}`?")),
1233+
getopts::Fail::ArgumentMissing(ref opt) => {
1234+
optgroups.iter().find(|option| option.name == opt).map(|option| {
1235+
// Print the help just for the option in question.
1236+
let mut options = getopts::Options::new();
1237+
(option.apply)(&mut options);
1238+
// getopt requires us to pass a function for joining an iterator of
1239+
// strings, even though in this case we expect exactly one string.
1240+
options.usage_with_format(|it| {
1241+
it.fold(format!("{e}\nUsage:"), |a, b| a + "\n" + &b)
1242+
})
1243+
})
1244+
}
12321245
_ => None,
12331246
};
12341247
early_dcx.early_fatal(msg.unwrap_or_else(|| e.to_string()));

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ enum OptionStability {
13761376

13771377
pub struct RustcOptGroup {
13781378
pub apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>,
1379-
name: &'static str,
1379+
pub name: &'static str,
13801380
stability: OptionStability,
13811381
}
13821382

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
error: Argument to option 'cap-lints' missing
2+
Usage:
3+
--cap-lints LEVEL Set the most restrictive lint level. More restrictive
4+
lints are capped at this level
25

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//@ compile-flags: --print
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: Argument to option 'print' missing
2+
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]
4+
Compiler information to print on stdout
5+

0 commit comments

Comments
 (0)