diff --git a/Cargo.toml b/Cargo.toml index f55486ce..79d42ea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,8 @@ color = ["atty", "termcolor"] suggestions = ["strsim"] # Optional -deprecated = [] # Guided experience to prepare for next breaking release (at different stages of development, this may become default) +# note: this will always enable clap_derive, change this to `clap_derive?/unstable-v4` when MSRV is bigger than 1.60 +deprecated = ["clap_derive/deprecated"] # Guided experience to prepare for next breaking release (at different stages of development, this may become default) derive = ["clap_derive", "once_cell"] cargo = ["once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros wrap_help = ["terminal_size", "textwrap/terminal_size"] diff --git a/clap_derive/Cargo.toml b/clap_derive/Cargo.toml index df26e253..4982d85c 100644 --- a/clap_derive/Cargo.toml +++ b/clap_derive/Cargo.toml @@ -51,4 +51,6 @@ proc-macro-error = "1" [features] default = [] debug = [] -unstable-v4 = [] +unstable-v4 = ["deprecated"] +deprecated = [] +raw-deprecated = ["deprecated"] diff --git a/clap_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs index 2707fd68..23a2260e 100644 --- a/clap_derive/src/derives/args.rs +++ b/clap_derive/src/derives/args.rs @@ -113,6 +113,7 @@ pub fn gen_from_arg_matches_for_struct( let constructor = gen_constructor(fields, &attrs); let updater = gen_updater(fields, &attrs, true); + let raw_deprecated = raw_deprecated(); let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); @@ -136,7 +137,7 @@ pub fn gen_from_arg_matches_for_struct( } fn from_arg_matches_mut(__clap_arg_matches: &mut clap::ArgMatches) -> ::std::result::Result { - #[allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Args` + #raw_deprecated let v = #struct_name #constructor; ::std::result::Result::Ok(v) } @@ -146,7 +147,7 @@ pub fn gen_from_arg_matches_for_struct( } fn update_from_arg_matches_mut(&mut self, __clap_arg_matches: &mut clap::ArgMatches) -> ::std::result::Result<(), clap::Error> { - #[allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Args` + #raw_deprecated #updater ::std::result::Result::Ok(()) } @@ -737,3 +738,16 @@ fn gen_parsers( quote_spanned!(field.span()=> #field_name: #field_value ) } } + +#[cfg(feature = "raw-deprecated")] +pub fn raw_deprecated() -> TokenStream { + quote! {} +} + +#[cfg(not(feature = "raw-deprecated"))] +pub fn raw_deprecated() -> TokenStream { + quote! { + #![allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Args` + + } +} diff --git a/clap_derive/src/derives/subcommand.rs b/clap_derive/src/derives/subcommand.rs index c10aeafd..07bdce5e 100644 --- a/clap_derive/src/derives/subcommand.rs +++ b/clap_derive/src/derives/subcommand.rs @@ -540,9 +540,10 @@ fn gen_from_arg_matches( }, }; + let raw_deprecated = args::raw_deprecated(); quote! { fn from_arg_matches_mut(__clap_arg_matches: &mut clap::ArgMatches) -> ::std::result::Result { - #[allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Subcommand` + #raw_deprecated #( #child_subcommands )else* @@ -654,12 +655,13 @@ fn gen_update_from_arg_matches( } }); + let raw_deprecated = args::raw_deprecated(); quote! { fn update_from_arg_matches_mut<'b>( &mut self, __clap_arg_matches: &mut clap::ArgMatches, ) -> ::std::result::Result<(), clap::Error> { - #[allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Subcommand` + #raw_deprecated if let Some(__clap_name) = __clap_arg_matches.subcommand_name() { match self {