}
#[derive(Copy, Clone)]
-pub struct BitMask;
+pub struct BitMask {
+ verbose_bit_mask_threshold: u64,
+}
+
+impl BitMask {
+ pub fn new(verbose_bit_mask_threshold: u64) -> Self {
+ Self {
+ verbose_bit_mask_threshold: verbose_bit_mask_threshold,
+ }
+ }
+}
impl LintPass for BitMask {
fn get_lints(&self) -> LintArray {
let Expr_::ExprLit(ref lit1) = right.node,
let LitKind::Int(0, _) = lit1.node,
n.leading_zeros() == n.count_zeros(),
+ n > u128::from(self.verbose_bit_mask_threshold),
], {
span_lint_and_then(cx,
VERBOSE_BIT_MASK,
reg.register_early_lint_pass(box enum_variants::EnumVariantNames::new(conf.enum_variant_name_threshold));
reg.register_late_lint_pass(box enum_glob_use::EnumGlobUse);
reg.register_late_lint_pass(box enum_clike::UnportableVariant);
- reg.register_late_lint_pass(box bit_mask::BitMask);
+ reg.register_late_lint_pass(box bit_mask::BitMask::new(conf.verbose_bit_mask_threshold));
reg.register_late_lint_pass(box ptr::PointerPass);
reg.register_late_lint_pass(box needless_bool::NeedlessBool);
reg.register_late_lint_pass(box needless_bool::BoolComparison);
(enum_variant_name_threshold, "enum_variant_name_threshold", 3 => u64),
/// Lint: LARGE_ENUM_VARIANT. The maximum size of a emum's variant to avoid box suggestion
(enum_variant_size_threshold, "enum_variant_size_threshold", 200 => u64),
+ /// Lint: VERBOSE_BIT_MASK. The maximum size of a bit mask, that won't be checked on verbosity
+ (verbose_bit_mask_threshold, "verbose_bit_mask_threshold", 1 => u64),
}
/// Search for the configuration file.
|
= note: `-D bad-bit-mask` implied by `-D warnings`
-error: bit mask could be simplified with a call to `trailing_zeros`
- --> $DIR/bit_masks.rs:12:5
- |
-12 | x & 0 == 0;
- | ^^^^^^^^^^ help: try: `x.trailing_zeros() >= 0`
- |
- = note: `-D verbose-bit-mask` implied by `-D warnings`
-
-error: bit mask could be simplified with a call to `trailing_zeros`
- --> $DIR/bit_masks.rs:14:5
- |
-14 | x & 1 == 0; //ok, compared with zero
- | ^^^^^^^^^^ help: try: `x.trailing_zeros() >= 1`
-
error: incompatible bit mask: `_ & 2` can never be equal to `1`
--> $DIR/bit_masks.rs:15:5
|
55 | x | 1 >= 8;
| ^^^^^^^^^^
-error: aborting due to 17 previous errors
+error: aborting due to 15 previous errors
-error: error reading Clippy's configuration file: unknown field `foobar`, expected one of `blacklisted-names`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `third-party`
+error: error reading Clippy's configuration file: unknown field `foobar`, expected one of `blacklisted-names`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `third-party`
error: aborting due to previous error
let _ = #[clippy(author)] (x & 0b1111 == 0); // suggest trailing_zeros
let _ = x & 0b1_1111 == 0; // suggest trailing_zeros
let _ = x & 0b1_1010 == 0; // do not lint
+ let _ = x & 1 == 0; // do not lint
}