Skip to content

Commit 2d8ab22

Browse files
committed
Auto merge of #132902 - matthiaskrgr:rollup-43qgg3t, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #129627 (Ensure that tail expr receive lifetime extension) - #130999 (Implement file_lock feature) - #132873 (handle separate prefixes in clippy rules) - #132891 (Remove `rustc_session::config::rustc_short_optgroups`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d4822c2 + bcd85e5 commit 2d8ab22

File tree

17 files changed

+674
-57
lines changed

17 files changed

+674
-57
lines changed

compiler/rustc_driver_impl/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,12 @@ pub fn version_at_macro_invocation(
934934
}
935935

936936
fn usage(verbose: bool, include_unstable_options: bool, nightly_build: bool) {
937-
let groups = if verbose { config::rustc_optgroups() } else { config::rustc_short_optgroups() };
938937
let mut options = getopts::Options::new();
939-
for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
938+
for option in config::rustc_optgroups()
939+
.iter()
940+
.filter(|x| verbose || !x.is_verbose_help_only)
941+
.filter(|x| include_unstable_options || x.is_stable())
942+
{
940943
option.apply(&mut options);
941944
}
942945
let message = "Usage: rustc [OPTIONS] INPUT";

compiler/rustc_session/src/config.rs

+55-48
Original file line numberDiff line numberDiff line change
@@ -1398,9 +1398,25 @@ pub enum OptionKind {
13981398
}
13991399

14001400
pub struct RustcOptGroup {
1401-
apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>,
1401+
/// The "primary" name for this option. Normally equal to `long_name`,
1402+
/// except for options that don't have a long name, in which case
1403+
/// `short_name` is used.
1404+
///
1405+
/// This is needed when interacting with `getopts` in some situations,
1406+
/// because if an option has both forms, that library treats the long name
1407+
/// as primary and the short name as an alias.
14021408
pub name: &'static str,
14031409
stability: OptionStability,
1410+
kind: OptionKind,
1411+
1412+
short_name: &'static str,
1413+
long_name: &'static str,
1414+
desc: &'static str,
1415+
value_hint: &'static str,
1416+
1417+
/// If true, this option should not be printed by `rustc --help`, but
1418+
/// should still be printed by `rustc --help -v`.
1419+
pub is_verbose_help_only: bool,
14041420
}
14051421

14061422
impl RustcOptGroup {
@@ -1409,7 +1425,13 @@ impl RustcOptGroup {
14091425
}
14101426

14111427
pub fn apply(&self, options: &mut getopts::Options) {
1412-
(self.apply)(options);
1428+
let &Self { short_name, long_name, desc, value_hint, .. } = self;
1429+
match self.kind {
1430+
OptionKind::Opt => options.optopt(short_name, long_name, desc, value_hint),
1431+
OptionKind::Multi => options.optmulti(short_name, long_name, desc, value_hint),
1432+
OptionKind::Flag => options.optflag(short_name, long_name, desc),
1433+
OptionKind::FlagMulti => options.optflagmulti(short_name, long_name, desc),
1434+
};
14131435
}
14141436
}
14151437

@@ -1419,31 +1441,22 @@ pub fn make_opt(
14191441
short_name: &'static str,
14201442
long_name: &'static str,
14211443
desc: &'static str,
1422-
hint: &'static str,
1444+
value_hint: &'static str,
14231445
) -> RustcOptGroup {
1446+
// "Flag" options don't have a value, and therefore don't have a value hint.
1447+
match kind {
1448+
OptionKind::Opt | OptionKind::Multi => {}
1449+
OptionKind::Flag | OptionKind::FlagMulti => assert_eq!(value_hint, ""),
1450+
}
14241451
RustcOptGroup {
14251452
name: cmp::max_by_key(short_name, long_name, |s| s.len()),
14261453
stability,
1427-
apply: match kind {
1428-
OptionKind::Opt => Box::new(move |opts: &mut getopts::Options| {
1429-
opts.optopt(short_name, long_name, desc, hint)
1430-
}),
1431-
OptionKind::Multi => Box::new(move |opts: &mut getopts::Options| {
1432-
opts.optmulti(short_name, long_name, desc, hint)
1433-
}),
1434-
OptionKind::Flag => {
1435-
assert_eq!(hint, "");
1436-
Box::new(move |opts: &mut getopts::Options| {
1437-
opts.optflag(short_name, long_name, desc)
1438-
})
1439-
}
1440-
OptionKind::FlagMulti => {
1441-
assert_eq!(hint, "");
1442-
Box::new(move |opts: &mut getopts::Options| {
1443-
opts.optflagmulti(short_name, long_name, desc)
1444-
})
1445-
}
1446-
},
1454+
kind,
1455+
short_name,
1456+
long_name,
1457+
desc,
1458+
value_hint,
1459+
is_verbose_help_only: false,
14471460
}
14481461
}
14491462

@@ -1454,16 +1467,15 @@ The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE
14541467
)
14551468
});
14561469

1457-
/// Returns the "short" subset of the rustc command line options,
1458-
/// including metadata for each option, such as whether the option is
1459-
/// part of the stable long-term interface for rustc.
1460-
pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
1470+
/// Returns all rustc command line options, including metadata for
1471+
/// each option, such as whether the option is stable.
1472+
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
14611473
use OptionKind::{Flag, FlagMulti, Multi, Opt};
1462-
use OptionStability::Stable;
1474+
use OptionStability::{Stable, Unstable};
14631475

14641476
use self::make_opt as opt;
14651477

1466-
vec![
1478+
let mut options = vec![
14671479
opt(Stable, Flag, "h", "help", "Display this message", ""),
14681480
opt(
14691481
Stable,
@@ -1550,21 +1562,11 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
15501562
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
15511563
opt(Stable, Flag, "V", "version", "Print version info and exit", ""),
15521564
opt(Stable, Flag, "v", "verbose", "Use verbose output", ""),
1553-
]
1554-
}
1555-
1556-
/// Returns all rustc command line options, including metadata for
1557-
/// each option, such as whether the option is part of the stable
1558-
/// long-term interface for rustc.
1559-
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
1560-
use OptionKind::{Multi, Opt};
1561-
use OptionStability::{Stable, Unstable};
1562-
1563-
use self::make_opt as opt;
1565+
];
15641566

1565-
let mut opts = rustc_short_optgroups();
1566-
// FIXME: none of these descriptions are actually used
1567-
opts.extend(vec![
1567+
// Options in this list are hidden from `rustc --help` by default, but are
1568+
// shown by `rustc --help -v`.
1569+
let verbose_only = [
15681570
opt(
15691571
Stable,
15701572
Multi,
@@ -1590,9 +1592,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
15901592
"",
15911593
"color",
15921594
"Configure coloring of output:
1593-
auto = colorize, if output goes to a tty (default);
1594-
always = always colorize output;
1595-
never = never colorize output",
1595+
auto = colorize, if output goes to a tty (default);
1596+
always = always colorize output;
1597+
never = never colorize output",
15961598
"auto|always|never",
15971599
),
15981600
opt(
@@ -1612,8 +1614,13 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
16121614
"FROM=TO",
16131615
),
16141616
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "VAR=VALUE"),
1615-
]);
1616-
opts
1617+
];
1618+
options.extend(verbose_only.into_iter().map(|mut opt| {
1619+
opt.is_verbose_help_only = true;
1620+
opt
1621+
}));
1622+
1623+
options
16171624
}
16181625

16191626
pub fn get_cmd_lint_options(

0 commit comments

Comments
 (0)