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

derive(ArgEnum) should be distinct from derive(Clap) #2584

Closed
2 tasks done
epage opened this issue Jul 14, 2021 · 0 comments · Fixed by #2585
Closed
2 tasks done

derive(ArgEnum) should be distinct from derive(Clap) #2584

epage opened this issue Jul 14, 2021 · 0 comments · Fixed by #2585
Labels
A-derive Area: #[derive]` macro API C-bug Category: Updating dependencies
Milestone

Comments

@epage
Copy link
Member

epage commented Jul 14, 2021

Please complete the following tasks

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

Rust Version

rustc 1.53.0 (53cb7b09b 2021-06-17)

Clap Version

3be79b9

Minimal reproducible code

Naively just using the "magic" struct

#[derive(clap::Clap)]
enum Level {
  Info,
  Warn,
  Error,
}

Intentionally creating subcommand

#[derive(clap::Clap)]
enum Action {
  Add,
  Remove,
}

Steps to reproduce the bug with the above code

Can use arg in wrong case

#[derive(clap::Clap)]
struct Args {
  #[clap(subcommand)]
  level: Level,
}

Can use subcommand in wrong case

#[derive(clap::Clap)]
struct Args {
    #[clap(arg_enum)]
    action: Action,
}

Actual Behaviour

API can be used in the wrong way

Expected Behaviour

Compile errors

Additional Context

This is split out of #2005, see

Debug Output

No response

@epage epage added the C-bug Category: Updating dependencies label Jul 14, 2021
@pksunkara pksunkara added this to the 3.0 milestone Jul 14, 2021
@pksunkara pksunkara added the A-derive Area: #[derive]` macro API label Jul 14, 2021
epage added a commit to epage/clap that referenced this issue Jul 14, 2021
While having convinience derives can be helpful, deriving traits that
are not used in similar situations (`Clap` and `ArgEnum`) can make
things harder
- From a user, derives are opaque and create uncertainty on how to use
  the API if not kept crystal clear (deriving a name gives you the trait
  by that name)
- This makes documentation harder to write and read
- You can use types in unintended places, which is made worse for crate
  APIs because changing this breaks compatibility.

Fixes clap-rs#2584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-derive Area: #[derive]` macro API C-bug Category: Updating dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants