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

unused_braces warning for default_value_t #3245

Closed
2 tasks done
href opened this issue Jan 3, 2022 · 7 comments · Fixed by #3246
Closed
2 tasks done

unused_braces warning for default_value_t #3245

href opened this issue Jan 3, 2022 · 7 comments · Fixed by #3246
Labels
A-derive Area: #[derive]` macro API C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@href
Copy link

href commented Jan 3, 2022

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

Minimal reproducible code

use clap::{ArgEnum, Parser, Subcommand};

#[derive(Parser)]
struct Cli {
    #[clap(subcommand)]
    command: Commands,
}

#[derive(Debug, ArgEnum, Clone)]
enum DisplayFormat {
    List,
}

impl Default for DisplayFormat {
    fn default() -> Self { DisplayFormat::List }
}

#[derive(Subcommand)]
enum Commands {
    Hosts {
        #[clap(short, long, arg_enum, default_value_t)]
        format: DisplayFormat,
    },
}

fn main() {
    let cli = Cli::parse();

    match &cli.command {
        Commands::Hosts { format } => {
            println!("Format: {:?}", format);
        }
    }
}

Steps to reproduce the bug with the above code

cargo check

Actual Behaviour

warning: unnecessary braces around method argument
  --> src/main.rs:21:39
   |
21 |         #[clap(short, long, arg_enum, default_value_t)]
   |                                       ^              ^
   |
   = note: `#[warn(unused_braces)]` on by default
help: remove these braces
   |
21 -         #[clap(short, long, arg_enum, default_value_t)]
21 +         #[clap(short, long, arg_enum, default_value_t)]
   |

warning: `hello` (bin "hello") generated 1 warning

Expected Behaviour

There should be no warning

Additional Context

Pretty inexperienced in Rust and new to Clap, so hopefully I'm not doing something wrong.

Debug Output

No response

@href href added the C-bug Category: Updating dependencies label Jan 3, 2022
epage added a commit to epage/clap that referenced this issue Jan 3, 2022
We missed covering `Args` warnings when using struct variants.

Fixes clap-rs#3245
@epage epage added A-derive Area: #[derive]` macro API E-easy Call for participation: Experience needed to fix: Easy / not much labels Jan 3, 2022
epage added a commit to epage/clap that referenced this issue Jan 3, 2022
We missed covering `Args` warnings when using struct variants.

Fixes clap-rs#3245
@href
Copy link
Author

href commented Jan 3, 2022

Thank you! That was very quick 😌

@epage
Copy link
Member

epage commented Jan 3, 2022

v3.0.1 is now released with the fix

@href
Copy link
Author

href commented Jan 3, 2022

I still seem to be getting the error with 3.0.1:

cargo check
    Checking clap v3.0.1
    Checking hello v0.1.0 (/Users/denis/Code/hello)
warning: unnecessary braces around method argument
  --> src/main.rs:21:39
   |
21 |         #[clap(short, long, arg_enum, default_value_t)]
   |                                       ^              ^
   |
   = note: `#[warn(unused_braces)]` on by default
help: remove these braces
   |
21 -         #[clap(short, long, arg_enum, default_value_t)]
21 +         #[clap(short, long, arg_enum, default_value_t)]
   |

warning: `hello` (bin "hello") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 2.18s

Same code, just with 3.0.1 in Cargo.toml.

@epage
Copy link
Member

epage commented Jan 4, 2022

Sorry, forgot to mark clap_derive for being released. It should be now.

@href
Copy link
Author

href commented Jan 4, 2022

Does this mean it will be fixed in 3.0.2, since I already have 3.0.1?

@epage
Copy link
Member

epage commented Jan 4, 2022

It is fixed in clap_derive 3.0.1. Run cargo update -p clap_derive and you should have the fix.

@href
Copy link
Author

href commented Jan 4, 2022

That did it, thank you!

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 E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants