summaryrefslogtreecommitdiffstats
path: root/vendor/clap_derive/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/clap_derive/src
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/clap_derive/src')
-rw-r--r--vendor/clap_derive/src/derives/args.rs45
-rw-r--r--vendor/clap_derive/src/derives/into_app.rs18
-rw-r--r--vendor/clap_derive/src/derives/parser.rs15
-rw-r--r--vendor/clap_derive/src/derives/subcommand.rs47
-rw-r--r--vendor/clap_derive/src/derives/value_enum.rs9
-rw-r--r--vendor/clap_derive/src/dummies.rs6
-rw-r--r--vendor/clap_derive/src/item.rs12
7 files changed, 96 insertions, 56 deletions
diff --git a/vendor/clap_derive/src/derives/args.rs b/vendor/clap_derive/src/derives/args.rs
index e8611b6bd..20164ff2e 100644
--- a/vendor/clap_derive/src/derives/args.rs
+++ b/vendor/clap_derive/src/derives/args.rs
@@ -16,7 +16,7 @@ use proc_macro2::{Ident, Span, TokenStream};
use quote::{format_ident, quote, quote_spanned};
use syn::{
punctuated::Punctuated, spanned::Spanned, token::Comma, Data, DataStruct, DeriveInput, Field,
- Fields, Generics,
+ Fields, FieldsNamed, Generics,
};
use crate::item::{Item, Kind, Name};
@@ -32,14 +32,7 @@ pub fn derive_args(input: &DeriveInput) -> Result<TokenStream, syn::Error> {
}) => {
let name = Name::Derived(ident.clone());
let item = Item::from_args_struct(input, name)?;
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(&item, fields)?;
gen_for_struct(&item, ident, &input.generics, &fields)
}
Data::Struct(DataStruct {
@@ -93,7 +86,13 @@ pub fn gen_for_struct(
};
Ok(quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -106,6 +105,7 @@ pub fn gen_for_struct(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
@@ -128,7 +128,13 @@ pub fn gen_for_struct(
}
}
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -141,6 +147,7 @@ pub fn gen_for_struct(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::Args for #item_name #ty_generics #where_clause {
fn group_id() -> Option<clap::Id> {
#group_id
@@ -710,7 +717,7 @@ fn gen_parsers(
Ty::Other => {
quote_spanned! { ty.span()=>
#arg_matches.#get_one(#id)
- .ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, format!("The following required argument was not provided: {}", #id)))?
+ .ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, concat!("The following required argument was not provided: ", #id)))?
}
}
};
@@ -740,3 +747,17 @@ pub fn raw_deprecated() -> TokenStream {
}
}
+
+pub fn collect_args_fields<'a>(
+ item: &'a Item,
+ fields: &'a FieldsNamed,
+) -> Result<Vec<(&'a Field, Item)>, syn::Error> {
+ fields
+ .named
+ .iter()
+ .map(|field| {
+ let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
+ Ok((field, item))
+ })
+ .collect()
+}
diff --git a/vendor/clap_derive/src/derives/into_app.rs b/vendor/clap_derive/src/derives/into_app.rs
index 72f081fd8..0bd636245 100644
--- a/vendor/clap_derive/src/derives/into_app.rs
+++ b/vendor/clap_derive/src/derives/into_app.rs
@@ -29,7 +29,13 @@ pub fn gen_for_struct(
let app_var = Ident::new("__clap_app", Span::call_site());
let tokens = quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -42,6 +48,7 @@ pub fn gen_for_struct(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
fn command<'b>() -> clap::Command {
let #app_var = clap::Command::new(#name);
@@ -69,7 +76,13 @@ pub fn gen_for_enum(
let app_var = Ident::new("__clap_app", Span::call_site());
Ok(quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -82,6 +95,7 @@ pub fn gen_for_enum(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
fn command<'b>() -> clap::Command {
let #app_var = clap::Command::new(#name)
diff --git a/vendor/clap_derive/src/derives/parser.rs b/vendor/clap_derive/src/derives/parser.rs
index 39b0b8a77..272948b63 100644
--- a/vendor/clap_derive/src/derives/parser.rs
+++ b/vendor/clap_derive/src/derives/parser.rs
@@ -21,6 +21,7 @@ use syn::{
Generics,
};
+use crate::derives::args::collect_args_fields;
use crate::derives::{args, into_app, subcommand};
use crate::item::Item;
use crate::item::Name;
@@ -36,14 +37,7 @@ pub fn derive_parser(input: &DeriveInput) -> Result<TokenStream, syn::Error> {
}) => {
let name = Name::Assigned(quote!(#pkg_name));
let item = Item::from_args_struct(input, name)?;
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(&item, fields)?;
gen_for_struct(&item, ident, &input.generics, &fields)
}
Data::Struct(DataStruct {
@@ -92,6 +86,10 @@ fn gen_for_struct(
let args = args::gen_for_struct(item, item_name, generics, fields)?;
Ok(quote! {
+ #[automatically_derived]
+ #[allow(
+ unused_qualifications,
+ )]
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}
#into_app
@@ -111,6 +109,7 @@ fn gen_for_enum(
let subcommand = subcommand::gen_for_enum(item, item_name, generics, variants)?;
Ok(quote! {
+ #[automatically_derived]
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}
#into_app
diff --git a/vendor/clap_derive/src/derives/subcommand.rs b/vendor/clap_derive/src/derives/subcommand.rs
index 403fe4557..3ae74d01a 100644
--- a/vendor/clap_derive/src/derives/subcommand.rs
+++ b/vendor/clap_derive/src/derives/subcommand.rs
@@ -17,6 +17,7 @@ use quote::{format_ident, quote, quote_spanned};
use syn::{spanned::Spanned, Data, DeriveInput, FieldsUnnamed, Generics, Variant};
use crate::derives::args;
+use crate::derives::args::collect_args_fields;
use crate::item::{Item, Kind, Name};
use crate::utils::{is_simple_ty, subty_if_name};
@@ -65,7 +66,13 @@ pub fn gen_for_enum(
let has_subcommand = gen_has_subcommand(variants)?;
Ok(quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -78,6 +85,7 @@ pub fn gen_for_enum(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
@@ -91,7 +99,13 @@ pub fn gen_for_enum(
#update_from_arg_matches
}
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -104,6 +118,7 @@ pub fn gen_for_enum(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::Subcommand for #item_name #ty_generics #where_clause {
fn augment_subcommands <'b>(__clap_app: clap::Command) -> clap::Command {
#augmentation
@@ -264,15 +279,7 @@ fn gen_augment(
let sub_augment = match variant.fields {
Named(ref fields) => {
// Defer to `gen_augment` for adding cmd methods
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item =
- Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(item, fields)?;
args::gen_augment(&fields, &subcommand_var, item, override_required)?
}
Unit => {
@@ -484,14 +491,7 @@ fn gen_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStream, sy
let variant_name = &variant.ident;
let constructor_block = match variant.fields {
Named(ref fields) => {
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(item, fields)?;
args::gen_constructor(&fields)?
},
Unit => quote!(),
@@ -599,14 +599,7 @@ fn gen_update_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStr
let field_names = fields.named.iter().map(|field| {
field.ident.as_ref().unwrap()
}).collect::<Vec<_>>();
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(item, fields)?;
let update = args::gen_updater(&fields, false)?;
(quote!( { #( #field_names, )* }), quote!( { #update } ))
}
diff --git a/vendor/clap_derive/src/derives/value_enum.rs b/vendor/clap_derive/src/derives/value_enum.rs
index 6f107c01c..397eb3323 100644
--- a/vendor/clap_derive/src/derives/value_enum.rs
+++ b/vendor/clap_derive/src/derives/value_enum.rs
@@ -51,7 +51,13 @@ pub fn gen_for_enum(
let to_possible_value = gen_to_possible_value(item, &lits);
Ok(quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -64,6 +70,7 @@ pub fn gen_for_enum(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl clap::ValueEnum for #item_name {
#value_variants
#to_possible_value
diff --git a/vendor/clap_derive/src/dummies.rs b/vendor/clap_derive/src/dummies.rs
index b10bedc64..3a1581b23 100644
--- a/vendor/clap_derive/src/dummies.rs
+++ b/vendor/clap_derive/src/dummies.rs
@@ -7,6 +7,7 @@ use quote::quote;
pub fn parser(name: &Ident) -> proc_macro2::TokenStream {
let into_app = into_app(name);
quote!(
+ #[automatically_derived]
impl clap::Parser for #name {}
#into_app
)
@@ -15,6 +16,7 @@ pub fn parser(name: &Ident) -> proc_macro2::TokenStream {
#[must_use]
pub fn into_app(name: &Ident) -> proc_macro2::TokenStream {
quote! {
+ #[automatically_derived]
impl clap::CommandFactory for #name {
fn command<'b>() -> clap::Command {
unimplemented!()
@@ -29,6 +31,7 @@ pub fn into_app(name: &Ident) -> proc_macro2::TokenStream {
#[must_use]
pub fn from_arg_matches(name: &Ident) -> proc_macro2::TokenStream {
quote! {
+ #[automatically_derived]
impl clap::FromArgMatches for #name {
fn from_arg_matches(_m: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
unimplemented!()
@@ -44,6 +47,7 @@ pub fn from_arg_matches(name: &Ident) -> proc_macro2::TokenStream {
pub fn subcommand(name: &Ident) -> proc_macro2::TokenStream {
let from_arg_matches = from_arg_matches(name);
quote! {
+ #[automatically_derived]
impl clap::Subcommand for #name {
fn augment_subcommands(_cmd: clap::Command) -> clap::Command {
unimplemented!()
@@ -63,6 +67,7 @@ pub fn subcommand(name: &Ident) -> proc_macro2::TokenStream {
pub fn args(name: &Ident) -> proc_macro2::TokenStream {
let from_arg_matches = from_arg_matches(name);
quote! {
+ #[automatically_derived]
impl clap::Args for #name {
fn augment_args(_cmd: clap::Command) -> clap::Command {
unimplemented!()
@@ -78,6 +83,7 @@ pub fn args(name: &Ident) -> proc_macro2::TokenStream {
#[must_use]
pub fn value_enum(name: &Ident) -> proc_macro2::TokenStream {
quote! {
+ #[automatically_derived]
impl clap::ValueEnum for #name {
fn value_variants<'a>() -> &'a [Self]{
unimplemented!()
diff --git a/vendor/clap_derive/src/item.rs b/vendor/clap_derive/src/item.rs
index 9b29ff9e8..f3631fa7f 100644
--- a/vendor/clap_derive/src/item.rs
+++ b/vendor/clap_derive/src/item.rs
@@ -908,7 +908,7 @@ impl Item {
if !lines.is_empty() {
let (short_help, long_help) =
format_doc_comment(&lines, !self.verbatim_doc_comment, self.force_long_help);
- let short_name = format_ident!("{}", short_name);
+ let short_name = format_ident!("{short_name}");
let short = Method::new(
short_name,
short_help
@@ -917,7 +917,7 @@ impl Item {
);
self.doc_comment.push(short);
if let Some(long_name) = long_name {
- let long_name = format_ident!("{}", long_name);
+ let long_name = format_ident!("{long_name}");
let long = Method::new(
long_name,
long_help
@@ -946,7 +946,7 @@ impl Item {
(_, _) => {
let old = self.kind.name();
let new = kind.name();
- abort!(kind.span(), "`{}` cannot be used with `{}`", new, old);
+ abort!(kind.span(), "`{new}` cannot be used with `{old}`");
}
}
Ok(())
@@ -1247,8 +1247,8 @@ impl Method {
ident,
"cannot derive `{}` from Cargo.toml\n\n= note: {note}\n\n= help: {help}\n\n",
ident,
- note = format_args!("`{}` environment variable is not set", env_var),
- help = format_args!("use `{} = \"...\"` to set {} manually", ident, ident)
+ note = format_args!("`{env_var}` environment variable is not set"),
+ help = format_args!("use `{ident} = \"...\"` to set {ident} manually")
);
}
};
@@ -1405,7 +1405,7 @@ impl CasingStyle {
"lower" | "lowercase" => cs(Lower),
"upper" | "uppercase" => cs(Upper),
"verbatim" | "verbatimcase" => cs(Verbatim),
- s => abort!(name, "unsupported casing: `{}`", s),
+ s => abort!(name, "unsupported casing: `{s}`"),
};
Ok(s)
}