Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In Rust using clippy how can I disable clippy::struct-excessive-bools?

When I run "cargo clippy — -W clippy::pedantic" on the code below I get the message:

note: `-W clippy::struct-excessive-bools` implied by `-W clippy::pedantic`

help: consider using a state machine or refactoring bools into two-variant enums

help: for further information visit https://rust-lang.github.io/rust clippy/master/index.html#struct_excessive_bool

I have tried to disable this with #[allow(clippy::clippy::struct-excessive-bools)] but that fails:

5 | #[allow(clippy::clippy::struct-excessive-bools)]
  |                         ^^^^^^ expected identifier, found keyword

Is using #[allow(clippy::clippy::pedantic)] the only solution?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

”’

use clap::Parser;

#[derive(Parser, Default, Debug)]
#[clap(version, about)]
#[allow(clippy::clippy::struct-excessive-bools)]
struct Arguments {
    #[clap(short, long)]
    /// Set aaa
    aaa: bool,

    #[clap(short, long)]
    /// Set bbb
    bbb: bool,

    #[clap(short, long)]
    /// Set ccc
    ccc: bool,

    #[clap(short, long)]
    /// Set ddd
    ddd: bool,
}

fn main() {
    let args = Arguments::parse();
    dbg!(args);
}

”’

>Solution :

The lint is named clippy::struct_excessive_bools, with underscores instead of hyphens; and it doesn’t need additional namespacing. #[allow(clippy::struct_excessive_bools)] works – run Clippy with the "Tools" button at the top-right corner with and without the attribute to see.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading