Skip to content

Commit 88acd49

Browse files
authored
Rollup merge of rust-lang#132754 - Zalathar:opts, r=GuillaumeGomez,jieyouxu
Simplify the internal API for declaring command-line options The internal APIs for declaring command-line options are old, and intimidatingly complex. This PR replaces them with a single function that takes explicit `stability` and `kind` arguments, making it easier to see how each option is handled, and whether it is treated as stable or unstable. We also don't appear to have any tests for the output of `rustc --help` and similar, so I've added a run-make test to verify that this PR doesn't change any output. (There is already a similar run-make test for rustdoc's help output.) --- The librustdoc changes are simply adjusting to updated compiler APIs; no functional change intended. --- A side-effect of these changes is that rustfmt can once again format the entirety of these option declaration lists, which it was not doing before.
2 parents 5f58dc9 + b8377e5 commit 88acd49

File tree

9 files changed

+807
-594
lines changed

9 files changed

+807
-594
lines changed

compiler/rustc_driver_impl/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ fn usage(verbose: bool, include_unstable_options: bool, nightly_build: bool) {
937937
let groups = if verbose { config::rustc_optgroups() } else { config::rustc_short_optgroups() };
938938
let mut options = getopts::Options::new();
939939
for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
940-
(option.apply)(&mut options);
940+
option.apply(&mut options);
941941
}
942942
let message = "Usage: rustc [OPTIONS] INPUT";
943943
let nightly_help = if nightly_build {
@@ -1219,7 +1219,7 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
12191219
let mut options = getopts::Options::new();
12201220
let optgroups = config::rustc_optgroups();
12211221
for option in &optgroups {
1222-
(option.apply)(&mut options);
1222+
option.apply(&mut options);
12231223
}
12241224
let matches = options.parse(args).unwrap_or_else(|e| {
12251225
let msg: Option<String> = match e {
@@ -1233,7 +1233,7 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
12331233
optgroups.iter().find(|option| option.name == opt).map(|option| {
12341234
// Print the help just for the option in question.
12351235
let mut options = getopts::Options::new();
1236-
(option.apply)(&mut options);
1236+
option.apply(&mut options);
12371237
// getopt requires us to pass a function for joining an iterator of
12381238
// strings, even though in this case we expect exactly one string.
12391239
options.usage_with_format(|it| {

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ where
102102
fn optgroups() -> getopts::Options {
103103
let mut opts = getopts::Options::new();
104104
for group in rustc_optgroups() {
105-
(group.apply)(&mut opts);
105+
group.apply(&mut opts);
106106
}
107107
return opts;
108108
}

0 commit comments

Comments
 (0)