@@ -1398,9 +1398,25 @@ pub enum OptionKind {
1398
1398
}
1399
1399
1400
1400
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.
1402
1408
pub name: &'static str,
1403
1409
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,
1404
1420
}
1405
1421
1406
1422
impl RustcOptGroup {
@@ -1409,7 +1425,13 @@ impl RustcOptGroup {
1409
1425
}
1410
1426
1411
1427
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
+ };
1413
1435
}
1414
1436
}
1415
1437
@@ -1419,31 +1441,22 @@ pub fn make_opt(
1419
1441
short_name: &'static str,
1420
1442
long_name: &'static str,
1421
1443
desc: &'static str,
1422
- hint : &'static str,
1444
+ value_hint : &'static str,
1423
1445
) -> 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
+ }
1424
1451
RustcOptGroup {
1425
1452
name: cmp::max_by_key(short_name, long_name, |s| s.len()),
1426
1453
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,
1447
1460
}
1448
1461
}
1449
1462
@@ -1454,16 +1467,15 @@ The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE
1454
1467
)
1455
1468
});
1456
1469
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> {
1461
1473
use OptionKind::{Flag, FlagMulti, Multi, Opt};
1462
- use OptionStability::Stable;
1474
+ use OptionStability::{ Stable, Unstable} ;
1463
1475
1464
1476
use self::make_opt as opt;
1465
1477
1466
- vec![
1478
+ let mut options = vec![
1467
1479
opt(Stable, Flag, "h", "help", "Display this message", ""),
1468
1480
opt(
1469
1481
Stable,
@@ -1550,21 +1562,11 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
1550
1562
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
1551
1563
opt(Stable, Flag, "V", "version", "Print version info and exit", ""),
1552
1564
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
+ ];
1564
1566
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 = [
1568
1570
opt(
1569
1571
Stable,
1570
1572
Multi,
@@ -1590,9 +1592,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
1590
1592
"",
1591
1593
"color",
1592
1594
"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",
1596
1598
"auto|always|never",
1597
1599
),
1598
1600
opt(
@@ -1612,8 +1614,13 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
1612
1614
"FROM=TO",
1613
1615
),
1614
1616
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
1617
1624
}
1618
1625
1619
1626
pub fn get_cmd_lint_options(
0 commit comments