Skip to content

Commit

Permalink
fix(derive): Don't fail on variant field attributes
Browse files Browse the repository at this point in the history
Well, thats annoying how easy it is to get this wrong but tests can only
help with regressions; it would be hard to prevent future failures.

Fixes #5007
  • Loading branch information
epage committed Jul 14, 2023
1 parent 9af3a94 commit 3025ff8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions clap_derive/src/derives/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn gen_augment(

Kind::Flatten(_) => match variant.fields {
Unnamed(FieldsUnnamed { ref unnamed, .. }) if unnamed.len() == 1 => {
let ty = &unnamed[0];
let ty = &unnamed[0].ty;
let deprecations = if !override_required {
item.deprecations()
} else {
Expand Down Expand Up @@ -223,7 +223,7 @@ fn gen_augment(
}
Unit => quote!( #subcommand_var ),
Unnamed(FieldsUnnamed { ref unnamed, .. }) if unnamed.len() == 1 => {
let ty = &unnamed[0];
let ty = &unnamed[0].ty;
if override_required {
quote_spanned! { ty.span()=>
{
Expand Down Expand Up @@ -293,7 +293,7 @@ fn gen_augment(
}
}
Unnamed(FieldsUnnamed { ref unnamed, .. }) if unnamed.len() == 1 => {
let ty = &unnamed[0];
let ty = &unnamed[0].ty;
let arg_block = if override_required {
quote_spanned! { ty.span()=>
{
Expand Down Expand Up @@ -390,7 +390,7 @@ fn gen_has_subcommand(variants: &[(&Variant, Item)]) -> Result<TokenStream, syn:
.iter()
.map(|(variant, _attrs)| match variant.fields {
Unnamed(ref fields) if fields.unnamed.len() == 1 => {
let ty = &fields.unnamed[0];
let ty = &fields.unnamed[0].ty;
Ok(quote! {
if <#ty as clap::Subcommand>::has_subcommand(__clap_name) {
return true;
Expand Down Expand Up @@ -496,7 +496,7 @@ fn gen_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStream, sy
},
Unit => quote!(),
Unnamed(ref fields) if fields.unnamed.len() == 1 => {
let ty = &fields.unnamed[0];
let ty = &fields.unnamed[0].ty;
quote!( ( <#ty as clap::FromArgMatches>::from_arg_matches_mut(__clap_arg_matches)? ) )
}
Unnamed(..) => abort_call_site!("{}: tuple enums are not supported", variant.ident),
Expand All @@ -512,7 +512,7 @@ fn gen_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStream, sy
let variant_name = &variant.ident;
match variant.fields {
Unnamed(ref fields) if fields.unnamed.len() == 1 => {
let ty = &fields.unnamed[0];
let ty = &fields.unnamed[0].ty;
Ok(quote! {
if __clap_arg_matches
.subcommand_name()
Expand Down Expand Up @@ -632,7 +632,7 @@ fn gen_update_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStr
let variant_name = &variant.ident;
match variant.fields {
Unnamed(ref fields) if fields.unnamed.len() == 1 => {
let ty = &fields.unnamed[0];
let ty = &fields.unnamed[0].ty;
Ok(quote! {
if <#ty as clap::Subcommand>::has_subcommand(__clap_name) {
if let Self :: #variant_name (child) = s {
Expand Down

0 comments on commit 3025ff8

Please sign in to comment.