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

Nested subcommands in enums gives lots of clippy warnings #3017

Closed
2 tasks done
sondr3 opened this issue Nov 12, 2021 · 2 comments · Fixed by #3018
Closed
2 tasks done

Nested subcommands in enums gives lots of clippy warnings #3017

sondr3 opened this issue Nov 12, 2021 · 2 comments · Fixed by #3018
Labels
C-bug Category: Updating dependencies

Comments

@sondr3
Copy link
Contributor

sondr3 commented Nov 12, 2021

Please complete the following tasks

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

Rust Version

rustc 1.56.1 (59eed8a2a 2021-11-01)

Clap Version

clap = "3.0.0-beta.5"

Minimal reproducible code

use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
struct Opt {
    #[clap(subcommand)]
    cmd: Option<Cmds>,
}

#[derive(Subcommand, Debug)]
enum Cmds {
    #[clap(subcommand)]
    One(OneCmd),
}

#[derive(Subcommand, Debug)]
enum OneCmd {
    Add { name: String, items: Vec<String> },
}

fn main() {
    Opt::parse();
}

Steps to reproduce the bug with the above code

cargo clippy

Actual Behaviour

❯ cargo clippy
    Checking app v.0.1.0 (/tmp/wat)
warning: this looks like an `else if` but the `else` is missing
  --> src/main.rs:17:15
   |
17 |     Add { name: String, items: Vec<String> },
   |               ^^^^^^^^^^
   |
   = note: `#[warn(clippy::suspicious_else_formatting)]` on by default
   = note: to remove this lint, add the missing `else` or add a new line before the second `if`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting

warning: this looks like an `else if` but the `else` is missing
  --> src/main.rs:17:11
   |
17 |     Add { name: String, items: Vec<String> },
   |           ^^^^^^^^^^^^^^^^^^^
   |
   = note: to remove this lint, add the missing `else` or add a new line before the second `if`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting

warning: this looks like an `else if` but the `else` is missing
  --> src/main.rs:17:15
   |
17 |     Add { name: String, items: Vec<String> },
   |               ^^^^^^^^^^
   |
   = note: to remove this lint, add the missing `else` or add a new line before the second `if`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting

Expected Behaviour

No warnings are displayed.

Additional Context

No response

Debug Output

No response

@sondr3 sondr3 added the C-bug Category: Updating dependencies label Nov 12, 2021
@bors bors bot closed this as completed in 9167fde Nov 12, 2021
@epage
Copy link
Member

epage commented Nov 12, 2021

Thanks for reporting this! Its now resolved in master. I wish there was a better way of handling warnings in macros, it feels very reactionary. We don't want to blanket disable all because there are some that might highlight a legitimate issue in our code or user code.

I wonder if macro authors have collaborated at all in sharing the most annoying warnings for code gen...

@sondr3
Copy link
Contributor Author

sondr3 commented Nov 13, 2021

Thanks for the quick fix, looking forward to a proper Clap v3 release 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants