Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Subcommand attribute not supported for unit type #3211

Closed
2 tasks done
dunnock opened this issue Dec 23, 2021 · 3 comments
Closed
2 tasks done

Regression: Subcommand attribute not supported for unit type #3211

dunnock opened this issue Dec 23, 2021 · 3 comments
Labels
C-bug Category: Updating dependencies S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

Comments

@dunnock
Copy link

dunnock commented Dec 23, 2021

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Rust Version

rustc 1.57.0 (f1edd0429 2021-11-29)

Clap Version

3.0.0-rc.7

Minimal reproducible code

use clap::{Parser, Subcommand};                                                                                                                        
  
  #[derive(Parser)]                                                                                                                        
  struct Opt {                                                            
      #[clap(subcommand)]                                                 
      cmd: CmdOptions,
  }                                                                       
                                                              
 #[derive(Subcommand)]   //  ■ proc-macro derive produced unparseable tokens                                                                                                                        
  enum CmdOptions {
      CmdStruct {          
          #[clap(subcommand)]                                                                                                                                                                                                               
          cmd: Cmd2      
      },                                                                                                                                                                                                                 
     CmdUnit(#[clap(subcommand)] Cmd2)   //  ■ expected type, found `#`  expected type                                                                                                                               
  }                                                                  
                                                                                                                                                                                              
  #[derive(Subcommand)]                                              
  enum Cmd2 {                                                                                                                        
      Command
  }

fn main() {}

Steps to reproduce the bug with the above code

cargo build produces compilation errors

Actual Behaviour

❯ cargo build
   Compiling clap-derive-bug v0.1.0 (/home/maxim/src/rust/clap-derive-bug)
error: expected type, found `#`
  --> src/main.rs:15:13
   |
15 |     CmdUnit(#[clap(subcommand)] Cmd2)
   |             ^ expected type

error: proc-macro derive produced unparseable tokens
 --> src/main.rs:9:10
  |
9 | #[derive(Subcommand)]
  |          ^^^^^^^^^^

error: could not compile `clap-derive-bug` due to 2 previous errors

Expected Behaviour

#[clap(subcommand)] macro is supported for unit structs according to #3094

Additional Context

No response

Debug Output

No response

@dunnock dunnock added the C-bug Category: Updating dependencies label Dec 23, 2021
@epage
Copy link
Member

epage commented Dec 23, 2021

We support the attribute on the variant, not on the tuple's element, similar to flatten.

This was missing from the derive reference but I just added it, see https://github.com/clap-rs/clap/blob/master/examples/derive_ref/README.md#app-attributes

@epage
Copy link
Member

epage commented Dec 23, 2021

Also, that linked discussion links out to a PR with an example: #2587

@epage epage added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 23, 2021
@epage
Copy link
Member

epage commented Dec 27, 2021

I'm assuming what I point to resolves this and am closing this out. Feel free to say otherwise!

@epage epage closed this as completed Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

No branches or pull requests

2 participants