Compiler doesn't recognise match_bool linting pragma


#1

I have a piece of code which is doing a match on a bool - I find it more readable.

match is_allowed {
    true => unverified_piece,
    false => original_piece,
}

When I run clippy on this code, I get a message like

help: consider using an if/else expression: if is_allowed { unverified_piece } else { original_piece }
|
= note: #[warn(match_bool)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.169/index.html#match_bool

if I add the pragma #[allow(match_bool)] I get a different message

warning: unknown lint: match_bool
–> src/movements/piece_keeper.rs:11:17
|
| #[allow(match_bool)]
| ^^^^^^^^^^
|
= note: #[warn(unknown_lints)] on by default

This seems inconsistent which is confusing to me. The only way to get the compiler to stop complaining is to add #[allow(unkown_lints)] above the match bool pragma.

Is this a mismatch between clippy and compiler? Is there a simpler solution that I’ve missed?

Thank you!


#2

Yes, compiler and Clippy have separate ideas of lints. You can make Clippy’s directives optional:

#[cfg_attr(feature = "cargo-clippy", allow(match_bool))]

#3

Would that be something that the clippy or compiler team be interested in aligning between those two ?


#4

In this case, you would probably still want some kind of namespacing so that clippy and rustc warning names are guaranteed to never clash, without cross-project agreement every time a new warning is introduced.


#5

Which is likely coming in the not too distant future.