Test rust regression

This commit is contained in:
Pavan Kumar Sunkara 2020-11-28 10:17:53 +00:00
parent 0242afee81
commit 56aeb155e1
2 changed files with 31 additions and 30 deletions

View file

@ -43,11 +43,11 @@ pub fn gen_for_struct(
)] )]
#[deny(clippy::correctness)] #[deny(clippy::correctness)]
impl ::clap::FromArgMatches for #struct_name { impl ::clap::FromArgMatches for #struct_name {
fn from_arg_matches(matches: &::clap::ArgMatches) -> Self { fn from_arg_matches(arg_matches: &::clap::ArgMatches) -> Self {
#struct_name #constructor #struct_name #constructor
} }
fn update_from_arg_matches(&mut self, matches: &::clap::ArgMatches) { fn update_from_arg_matches(&mut self, arg_matches: &::clap::ArgMatches) {
#updater #updater
} }
} }
@ -69,11 +69,11 @@ pub fn gen_for_enum(name: &Ident) -> TokenStream {
)] )]
#[deny(clippy::correctness)] #[deny(clippy::correctness)]
impl ::clap::FromArgMatches for #name { impl ::clap::FromArgMatches for #name {
fn from_arg_matches(matches: &::clap::ArgMatches) -> Self { fn from_arg_matches(arg_matches: &::clap::ArgMatches) -> Self {
<#name as ::clap::Subcommand>::from_subcommand(matches.subcommand()).unwrap() <#name as ::clap::Subcommand>::from_subcommand(arg_matches.subcommand()).unwrap()
} }
fn update_from_arg_matches(&mut self, matches: &::clap::ArgMatches) { fn update_from_arg_matches(&mut self, arg_matches: &::clap::ArgMatches) {
<#name as ::clap::Subcommand>::update_from_subcommand(self, matches.subcommand()); <#name as ::clap::Subcommand>::update_from_subcommand(self, arg_matches.subcommand());
} }
} }
} }
@ -136,11 +136,11 @@ fn gen_parsers(
Ty::Bool => { Ty::Bool => {
if update.is_some() { if update.is_some() {
quote_spanned! { ty.span()=> quote_spanned! { ty.span()=>
*#field_name || matches.is_present(#name) *#field_name || arg_matches.is_present(#name)
} }
} else { } else {
quote_spanned! { ty.span()=> quote_spanned! { ty.span()=>
matches.is_present(#name) arg_matches.is_present(#name)
} }
} }
} }
@ -153,22 +153,22 @@ fn gen_parsers(
} }
quote_spanned! { ty.span()=> quote_spanned! { ty.span()=>
matches.#value_of(#name) arg_matches.#value_of(#name)
.map(#parse) .map(#parse)
} }
} }
Ty::OptionOption => quote_spanned! { ty.span()=> Ty::OptionOption => quote_spanned! { ty.span()=>
if matches.is_present(#name) { if arg_matches.is_present(#name) {
Some(matches.#value_of(#name).map(#parse)) Some(arg_matches.#value_of(#name).map(#parse))
} else { } else {
None None
} }
}, },
Ty::OptionVec => quote_spanned! { ty.span()=> Ty::OptionVec => quote_spanned! { ty.span()=>
if matches.is_present(#name) { if arg_matches.is_present(#name) {
Some(matches.#values_of(#name) Some(arg_matches.#values_of(#name)
.map(|v| v.map(#parse).collect()) .map(|v| v.map(#parse).collect())
.unwrap_or_else(Vec::new)) .unwrap_or_else(Vec::new))
} else { } else {
@ -184,18 +184,18 @@ fn gen_parsers(
} }
quote_spanned! { ty.span()=> quote_spanned! { ty.span()=>
matches.#values_of(#name) arg_matches.#values_of(#name)
.map(|v| v.map(#parse).collect()) .map(|v| v.map(#parse).collect())
.unwrap_or_else(Vec::new) .unwrap_or_else(Vec::new)
} }
} }
Ty::Other if occurrences => quote_spanned! { ty.span()=> Ty::Other if occurrences => quote_spanned! { ty.span()=>
#parse(matches.#value_of(#name)) #parse(arg_matches.#value_of(#name))
}, },
Ty::Other if flag => quote_spanned! { ty.span()=> Ty::Other if flag => quote_spanned! { ty.span()=>
#parse(matches.is_present(#name)) #parse(arg_matches.is_present(#name))
}, },
Ty::Other => { Ty::Other => {
@ -204,7 +204,7 @@ fn gen_parsers(
} }
quote_spanned! { ty.span()=> quote_spanned! { ty.span()=>
matches.#value_of(#name) arg_matches.#value_of(#name)
.map(#parse) .map(#parse)
.unwrap() .unwrap()
} }
@ -213,7 +213,7 @@ fn gen_parsers(
if let Some(access) = update { if let Some(access) = update {
quote_spanned! { field.span()=> quote_spanned! { field.span()=>
if matches.is_present(#name) { if arg_matches.is_present(#name) {
#access #access
*#field_name = #field_value *#field_name = #field_value
} }
@ -249,14 +249,14 @@ pub fn gen_constructor(fields: &Punctuated<Field, Comma>, parent_attribute: &Att
}; };
quote_spanned! { kind.span()=> quote_spanned! { kind.span()=>
#field_name: { #field_name: {
<#subcmd_type as ::clap::Subcommand>::from_subcommand(matches.subcommand()) <#subcmd_type as ::clap::Subcommand>::from_subcommand(arg_matches.subcommand())
#unwrapper #unwrapper
} }
} }
} }
Kind::Flatten => quote_spanned! { kind.span()=> Kind::Flatten => quote_spanned! { kind.span()=>
#field_name: ::clap::FromArgMatches::from_arg_matches(matches) #field_name: ::clap::FromArgMatches::from_arg_matches(arg_matches)
}, },
Kind::Skip(val) => match val { Kind::Skip(val) => match val {
@ -329,7 +329,7 @@ pub fn gen_updater(
quote_spanned! { kind.span()=> quote_spanned! { kind.span()=>
{ {
let subcmd = matches.subcommand(); let subcmd = arg_matches.subcommand();
#access #access
#updater #updater
} }
@ -338,7 +338,7 @@ pub fn gen_updater(
Kind::Flatten => quote_spanned! { kind.span()=> { Kind::Flatten => quote_spanned! { kind.span()=> {
#access #access
::clap::FromArgMatches::update_from_arg_matches(#field_name, matches); ::clap::FromArgMatches::update_from_arg_matches(#field_name, arg_matches);
} }
}, },

View file

@ -240,13 +240,13 @@ fn gen_from_subcommand(
Unit => quote!(), Unit => quote!(),
Unnamed(ref fields) if fields.unnamed.len() == 1 => { Unnamed(ref fields) if fields.unnamed.len() == 1 => {
let ty = &fields.unnamed[0]; let ty = &fields.unnamed[0];
quote!( ( <#ty as ::clap::FromArgMatches>::from_arg_matches(matches) ) ) quote!( ( <#ty as ::clap::FromArgMatches>::from_arg_matches(arg_matches) ) )
} }
Unnamed(..) => abort_call_site!("{}: tuple enums are not supported", variant.ident), Unnamed(..) => abort_call_site!("{}: tuple enums are not supported", variant.ident),
}; };
quote! { quote! {
Some((#sub_name, matches)) => { Some((#sub_name, arg_matches)) => {
Some(#name :: #variant_name #constructor_block) Some(#name :: #variant_name #constructor_block)
} }
} }
@ -273,11 +273,11 @@ fn gen_from_subcommand(
Some((span, var_name, str_ty, values_of)) => quote_spanned! { span=> Some((span, var_name, str_ty, values_of)) => quote_spanned! { span=>
None => ::std::option::Option::None, None => ::std::option::Option::None,
Some((external, matches)) => { Some((external, arg_matches)) => {
::std::option::Option::Some(#name::#var_name( ::std::option::Option::Some(#name::#var_name(
::std::iter::once(#str_ty::from(external)) ::std::iter::once(#str_ty::from(external))
.chain( .chain(
matches.#values_of("").into_iter().flatten().map(#str_ty::from) arg_matches.#values_of("").into_iter().flatten().map(#str_ty::from)
) )
.collect::<::std::vec::Vec<_>>() .collect::<::std::vec::Vec<_>>()
)) ))
@ -361,7 +361,8 @@ fn gen_update_from_subcommand(
( (
quote!((ref mut arg)), quote!((ref mut arg)),
quote!(::clap::FromArgMatches::update_from_arg_matches( quote!(::clap::FromArgMatches::update_from_arg_matches(
arg, matches arg,
arg_matches
)), )),
) )
} else { } else {
@ -384,7 +385,7 @@ fn gen_update_from_subcommand(
( (
quote!((ref mut arg)), quote!((ref mut arg)),
quote! { quote! {
<#ty as ::clap::Subcommand>::update_from_subcommand(arg, Some((name, matches))); <#ty as ::clap::Subcommand>::update_from_subcommand(arg, Some((name, arg_matches)));
}, },
) )
} }
@ -403,11 +404,11 @@ fn gen_update_from_subcommand(
&mut self, &mut self,
subcommand: Option<(&str, &::clap::ArgMatches)> subcommand: Option<(&str, &::clap::ArgMatches)>
) { ) {
if let Some((name, matches)) = subcommand { if let Some((name, arg_matches)) = subcommand {
match (name, self) { match (name, self) {
#( #subcommands ),* #( #subcommands ),*
#( #child_subcommands ),* #( #child_subcommands ),*
(_, s) => if let Some(sub) = <Self as ::clap::Subcommand>::from_subcommand(Some((name, matches))) { (_, s) => if let Some(sub) = <Self as ::clap::Subcommand>::from_subcommand(Some((name, arg_matches))) {
*s = sub; *s = sub;
} }
} }