Skip to content

Commit d5e01bf

Browse files
committed
Add coarse fix to rust-lang#9350 (WIP)
1 parent e870eac commit d5e01bf

File tree

2 files changed

+65
-55
lines changed

2 files changed

+65
-55
lines changed

src/bin/cargo/cli.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo::core::features;
1+
use cargo::core::{features, CliUnstable};
22
use cargo::{self, drop_print, drop_println, CliResult, Config};
33
use clap::{AppSettings, Arg, ArgMatches};
44

@@ -30,26 +30,20 @@ pub fn main(config: &mut Config) -> CliResult {
3030
};
3131

3232
if args.value_of("unstable-features") == Some("help") {
33+
let options = CliUnstable::help();
34+
let help_lines: Vec<String> = options.iter().map(|(option_name, option_help_message)| {
35+
format!("-Z {} -- {}", option_name, option_help_message)
36+
}).collect();
37+
let joined = help_lines.join("\n");
3338
drop_println!(
3439
config,
3540
"
3641
Available unstable (nightly-only) flags:
3742
38-
-Z allow-features -- Allow *only* the listed unstable features
39-
-Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
40-
-Z extra-link-arg -- Allow `cargo:rustc-link-arg` in build scripts
41-
-Z minimal-versions -- Install minimal dependency versions instead of maximum
42-
-Z no-index-update -- Do not update the registry, avoids a network request for benchmarking
43-
-Z unstable-options -- Allow the usage of unstable options
44-
-Z timings -- Display concurrency information
45-
-Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
46-
-Z terminal-width -- Provide a terminal width to rustc for error truncation
47-
-Z namespaced-features -- Allow features with `dep:` prefix
48-
-Z weak-dep-features -- Allow `dep_name?/feature` feature syntax
49-
-Z patch-in-config -- Allow `[patch]` sections in .cargo/config.toml files
43+
{}
5044
5145
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
52-
);
46+
, joined);
5347
if !config.nightly_features_allowed {
5448
drop_println!(
5549
config,

src/cargo/core/features.rs

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -538,51 +538,67 @@ impl Features {
538538
}
539539
}
540540

541-
/// A parsed representation of all unstable flags that Cargo accepts.
542-
///
543-
/// Cargo, like `rustc`, accepts a suite of `-Z` flags which are intended for
544-
/// gating unstable functionality to Cargo. These flags are only available on
545-
/// the nightly channel of Cargo.
546-
#[derive(Default, Debug, Deserialize)]
547-
#[serde(default, rename_all = "kebab-case")]
548-
pub struct CliUnstable {
541+
macro_rules! help_struct {
542+
($name: ident, $($visibility: vis $element: ident: $ty: ty = ($help: literal $(, #[$meta:meta])?)),*) => {
543+
/// A parsed representation of all unstable flags that Cargo accepts.
544+
///
545+
/// Cargo, like `rustc`, accepts a suite of `-Z` flags which are intended for
546+
/// gating unstable functionality to Cargo. These flags are only available on
547+
/// the nightly channel of Cargo.
548+
#[derive(Default, Debug, Deserialize)]
549+
#[serde(default, rename_all = "kebab-case")]
550+
pub struct $name {
551+
$(
552+
$(#[$meta])?
553+
$visibility $element: $ty
554+
),*
555+
}
556+
impl $name {
557+
pub fn help() -> Vec<(&'static str, &'static str)> {
558+
let fields = vec![$((stringify!($element), $help)),*];
559+
fields
560+
}
561+
}
562+
}
563+
}
564+
565+
help_struct!(CliUnstable,
549566
// Permanently unstable features:
550-
pub allow_features: Option<BTreeSet<String>>,
551-
pub print_im_a_teapot: bool,
567+
pub allow_features: Option<BTreeSet<String>> = ("Allow *only* the listed unstable features"),
568+
pub print_im_a_teapot: bool= (""),
552569

553570
// All other unstable features.
554571
// Please keep this list lexiographically ordered.
555-
pub advanced_env: bool,
556-
pub avoid_dev_deps: bool,
557-
pub binary_dep_depinfo: bool,
558-
#[serde(deserialize_with = "deserialize_build_std")]
559-
pub build_std: Option<Vec<String>>,
560-
pub build_std_features: Option<Vec<String>>,
561-
pub config_include: bool,
562-
pub configurable_env: bool,
563-
pub credential_process: bool,
564-
pub doctest_in_workspace: bool,
565-
pub doctest_xcompile: bool,
566-
pub dual_proc_macros: bool,
567-
pub enable_future_incompat_feature: bool,
568-
pub extra_link_arg: bool,
569-
pub features: Option<Vec<String>>,
570-
pub jobserver_per_rustc: bool,
571-
pub minimal_versions: bool,
572-
pub mtime_on_use: bool,
573-
pub multitarget: bool,
574-
pub named_profiles: bool,
575-
pub namespaced_features: bool,
576-
pub no_index_update: bool,
577-
pub panic_abort_tests: bool,
578-
pub patch_in_config: bool,
579-
pub rustdoc_map: bool,
580-
pub separate_nightlies: bool,
581-
pub terminal_width: Option<Option<usize>>,
582-
pub timings: Option<Vec<String>>,
583-
pub unstable_options: bool,
584-
pub weak_dep_features: bool,
585-
}
572+
pub advanced_env: bool= (""),
573+
pub avoid_dev_deps: bool= ("Avoid installing dev-dependencies if possible"),
574+
pub binary_dep_depinfo: bool= (""),
575+
pub build_std: Option<Vec<String>> = ("", #[serde(deserialize_with = "deserialize_build_std")]),
576+
pub build_std_features: Option<Vec<String>> = (""),
577+
pub config_include: bool= (""),
578+
pub configurable_env: bool= (""),
579+
pub credential_process: bool= (""),
580+
pub doctest_in_workspace: bool= (""),
581+
pub doctest_xcompile: bool= ("Compile and run doctests for non-host target using runner config"),
582+
pub dual_proc_macros: bool= (""),
583+
pub enable_future_incompat_feature: bool= (""),
584+
pub extra_link_arg: bool= ("Allow `cargo:rustc-link-arg` in build scripts"),
585+
pub features: Option<Vec<String>> = (""),
586+
pub jobserver_per_rustc: bool= (""),
587+
pub minimal_versions: bool= ("Install minimal dependency versions instead of maximum"),
588+
pub mtime_on_use: bool= (""),
589+
pub multitarget: bool= (""),
590+
pub named_profiles: bool= (""),
591+
pub namespaced_features: bool= ("Allow features with `dep:` prefix"),
592+
pub no_index_update: bool= ("Do not update the registry, avoids a network request for benchmarking"),
593+
pub panic_abort_tests: bool= (""),
594+
pub patch_in_config: bool= ("Allow `[patch]` sections in .cargo/config.toml files"),
595+
pub rustdoc_map: bool= (""),
596+
pub separate_nightlies: bool= (""),
597+
pub terminal_width: Option<Option<usize>> = ("Provide a terminal width to rustc for error truncation"),
598+
pub timings: Option<Vec<String>> = ("Display concurrency information"),
599+
pub unstable_options: bool= ("Allow the usage of unstable options"),
600+
pub weak_dep_features: bool= ("Allow `dep_name?/feature` feature syntax")
601+
);
586602

587603
const STABILIZED_COMPILE_PROGRESS: &str = "The progress bar is now always \
588604
enabled when used on an interactive console.\n\

0 commit comments

Comments
 (0)