Skip to content

Commit 4f8f80d

Browse files
committed
Simplify macro
1 parent e742b89 commit 4f8f80d

File tree

1 file changed

+44
-48
lines changed

1 file changed

+44
-48
lines changed

src/cargo/core/features.rs

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -539,23 +539,27 @@ impl Features {
539539
}
540540
}
541541

542-
macro_rules! cli_options {
542+
macro_rules! unstable_cli_options {
543543
(
544-
$(#[$struct_meta:meta])*
545-
$name: ident,
546544
$(
547545
$(#[$meta:meta])?
548-
$visibility: vis $element: ident: $ty: ty = ($help: expr )
546+
$element: ident: $ty: ty = ($help: expr )
549547
),*
550548
) => {
551-
$(#[$struct_meta])*
552-
pub struct $name {
549+
/// A parsed representation of all unstable flags that Cargo accepts.
550+
///
551+
/// Cargo, like `rustc`, accepts a suite of `-Z` flags which are intended for
552+
/// gating unstable functionality to Cargo. These flags are only available on
553+
/// the nightly channel of Cargo.
554+
#[derive(Default, Debug, Deserialize)]
555+
#[serde(default, rename_all = "kebab-case")]
556+
pub struct CliUnstable {
553557
$(
554558
$(#[$meta])?
555-
$visibility $element: $ty
559+
pub $element: $ty
556560
),*
557561
}
558-
impl $name {
562+
impl CliUnstable {
559563
pub fn help() -> Vec<(&'static str, &'static str)> {
560564
let fields = vec![$((stringify!($element), $help)),*];
561565
fields
@@ -564,51 +568,43 @@ macro_rules! cli_options {
564568
}
565569
}
566570

567-
cli_options!(
568-
/// A parsed representation of all unstable flags that Cargo accepts.
569-
///
570-
/// Cargo, like `rustc`, accepts a suite of `-Z` flags which are intended for
571-
/// gating unstable functionality to Cargo. These flags are only available on
572-
/// the nightly channel of Cargo.
573-
#[derive(Default, Debug, Deserialize)]
574-
#[serde(default, rename_all = "kebab-case")]
575-
CliUnstable,
571+
unstable_cli_options!(
576572
// Permanently unstable features:
577-
pub allow_features: Option<BTreeSet<String>> = ("Allow *only* the listed unstable features"),
578-
pub print_im_a_teapot: bool= (HIDDEN),
573+
allow_features: Option<BTreeSet<String>> = ("Allow *only* the listed unstable features"),
574+
print_im_a_teapot: bool= (HIDDEN),
579575

580576
// All other unstable features.
581577
// Please keep this list lexiographically ordered.
582-
pub advanced_env: bool = (HIDDEN),
583-
pub avoid_dev_deps: bool = ("Avoid installing dev-dependencies if possible"),
584-
pub binary_dep_depinfo: bool = ("Track changes to dependency artifacts"),
578+
advanced_env: bool = (HIDDEN),
579+
avoid_dev_deps: bool = ("Avoid installing dev-dependencies if possible"),
580+
binary_dep_depinfo: bool = ("Track changes to dependency artifacts"),
585581
#[serde(deserialize_with = "deserialize_build_std")]
586-
pub build_std: Option<Vec<String>> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"),
587-
pub build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
588-
pub config_include: bool = ("Enable the `include` key in config files"),
589-
pub configurable_env: bool = ("Enable the [env] section in the .cargo/config.toml file"),
590-
pub credential_process: bool = ("Add a config setting to fetch registry authentication tokens by calling an external process"),
591-
pub doctest_in_workspace: bool = ("Compile doctests with paths relative to the workspace root"),
592-
pub doctest_xcompile: bool = ("Compile and run doctests for non-host target using runner config"),
593-
pub dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
594-
pub future_incompat_report: bool = ("Enable creation of a future-incompat report for all dependencies"),
595-
pub extra_link_arg: bool = ("Allow `cargo:rustc-link-arg` in build scripts"),
596-
pub features: Option<Vec<String>> = (HIDDEN),
597-
pub jobserver_per_rustc: bool = (HIDDEN),
598-
pub minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum"),
599-
pub mtime_on_use: bool = ("Configure Cargo to update the mtime of used files"),
600-
pub multitarget: bool = ("Allow passing multiple `--target` flags to the cargo subcommand selected"),
601-
pub named_profiles: bool = ("Allow defining custom profiles"),
602-
pub namespaced_features: bool = ("Allow features with `dep:` prefix"),
603-
pub no_index_update: bool = ("Do not update the registry index even if the cache is outdated"),
604-
pub panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
605-
pub patch_in_config: bool = ("Allow `[patch]` sections in .cargo/config.toml files"),
606-
pub rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
607-
pub separate_nightlies: bool = (HIDDEN),
608-
pub terminal_width: Option<Option<usize>> = ("Provide a terminal width to rustc for error truncation"),
609-
pub timings: Option<Vec<String>> = ("Display concurrency information"),
610-
pub unstable_options: bool = ("Allow the usage of unstable options"),
611-
pub weak_dep_features: bool = ("Allow `dep_name?/feature` feature syntax")
582+
build_std: Option<Vec<String>> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"),
583+
build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
584+
config_include: bool = ("Enable the `include` key in config files"),
585+
configurable_env: bool = ("Enable the [env] section in the .cargo/config.toml file"),
586+
credential_process: bool = ("Add a config setting to fetch registry authentication tokens by calling an external process"),
587+
doctest_in_workspace: bool = ("Compile doctests with paths relative to the workspace root"),
588+
doctest_xcompile: bool = ("Compile and run doctests for non-host target using runner config"),
589+
dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
590+
future_incompat_report: bool = ("Enable creation of a future-incompat report for all dependencies"),
591+
extra_link_arg: bool = ("Allow `cargo:rustc-link-arg` in build scripts"),
592+
features: Option<Vec<String>> = (HIDDEN),
593+
jobserver_per_rustc: bool = (HIDDEN),
594+
minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum"),
595+
mtime_on_use: bool = ("Configure Cargo to update the mtime of used files"),
596+
multitarget: bool = ("Allow passing multiple `--target` flags to the cargo subcommand selected"),
597+
named_profiles: bool = ("Allow defining custom profiles"),
598+
namespaced_features: bool = ("Allow features with `dep:` prefix"),
599+
no_index_update: bool = ("Do not update the registry index even if the cache is outdated"),
600+
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
601+
patch_in_config: bool = ("Allow `[patch]` sections in .cargo/config.toml files"),
602+
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
603+
separate_nightlies: bool = (HIDDEN),
604+
terminal_width: Option<Option<usize>> = ("Provide a terminal width to rustc for error truncation"),
605+
timings: Option<Vec<String>> = ("Display concurrency information"),
606+
unstable_options: bool = ("Allow the usage of unstable options"),
607+
weak_dep_features: bool = ("Allow `dep_name?/feature` feature syntax")
612608
);
613609

614610
const STABILIZED_COMPILE_PROGRESS: &str = "The progress bar is now always \

0 commit comments

Comments
 (0)