Repository: clap-rs/clap (language: rust)

Issue:
derive(Subcommand) does not respect attributes on fields of enum variants
### Please complete the following tasks

- [X] I have searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [X] I have searched the [open](https://github.com/clap-rs/clap/issues) and [rejected](https://github.com/clap-rs/clap/issues?q=is%3Aissue+label%3AS-wont-fix+is%3Aclosed) issues

### Rust Version

rustc 1.70.0 (90c541806 2023-05-31)

### Clap Version

4.3.11

### Minimal reproducible code

```rust
#[derive(Args)]
pub struct ListCommand {
    dir: PathBuf,
    limit: u64
}

#[derive(ExternalDerive, Subcommand)]
pub enum Commands {
    #[id(b"LS")]
    List(
        #[id(b"")]
        ListArgs
    )
}

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}


fn main() {
    Cli::parse();
}
```

Where `ExternalDerive` is some derive macro that takes `id` as an attribute. In a private project currently, so I can not point to a crate with this derive macro.

### Steps to reproduce the bug with the above code

`cargo run list ~ 100`

### Actual Behaviour

Compilation fails due to the `Subcommand` derive macro.
```
error: expected type, found `#`
  --> audio_lib/src/actions/mod.rs:46:9
   |
46 |         #[id(b"")]
   |         ^ expected type

error: proc-macro derive produced unparsable tokens
  --> audio_lib/src/actions/mod.rs:42:33
   |
42 | #[derive(Debug, Compose, Parse, Subcommand)]
   |                                 ^^^^^^^^^^

error: could not compile `audio_lib` (lib) due to 2 previous errors
````

### Expected Behaviour

I expect the code to compile, and to run, and then exit without doing anything.

### Additional Context

_No response_

### Debug Output

_No response_


Discussion / hints:
Could you include a full reproduction case?  Without access to `ExternalDerive`, I can't reproduce this to determine root cause.
Of course, I have made a minimal reproduction repository [here](https://github.com/SlayerOfTheBad/ClapDeriveBug).

It's reproduced simply by running `cargo run --bin bin`
Examples of bad generated code:
```rust
                       {
                           return :: std :: result :: Result ::
                           Ok(Self ::
                           List(< #[id(b"")] ListArgs as clap :: FromArgMatches > ::
                           from_arg_matches_mut(__clap_arg_matches) ?))
                       }
// ...
               fn augment_subcommands < 'b > (__clap_app : clap :: Command) -> clap ::
               Command
               {
                   ; let __clap_app = __clap_app ; let __clap_app =
                   __clap_app.subcommand({
                       let __clap_subcommand = clap :: Command :: new("list") ; let
                       __clap_subcommand = __clap_subcommand ; let __clap_subcommand =
                       {
                           < #[id(b"")] ListArgs as clap :: Args > ::
                           augment_args(__clap_subcommand)
                       } ; __clap_subcommand
                   }) ; ; __clap_app
               } fn augment_subcommands_for_update < 'b > (__clap_app : clap :: Command)
               -> clap :: Command
               {
                   ; let __clap_app = __clap_app ; let __clap_app =
                   __clap_app.subcommand({
                       let __clap_subcommand = clap :: Command :: new("list") ; let
                       __clap_subcommand = __clap_subcommand ; let __clap_subcommand =
                       {
                           < #[id(b"")] ListArgs as clap :: Args > ::
                           augment_args_for_update(__clap_subcommand)
                       } ; __clap_subcommand
                   }) ; ; __clap_app
// ...
```

Fix patch:
diff --git a/clap_derive/src/derives/subcommand.rs b/clap_derive/src/derives/subcommand.rs
index 3ae74d01ad0..125a40f6105 100644
--- a/clap_derive/src/derives/subcommand.rs
+++ b/clap_derive/src/derives/subcommand.rs
@@ -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 {
@@ -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()=>
                                 {
@@ -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()=>
                                 {
@@ -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;
@@ -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),
@@ -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()
@@ -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 {


Test patch: