You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[bitfield(u16)]
/// X axis output value
pub struct OutX{
#[bits(16)]
val: i16,
}
error: &-masking with zero
--> src/lib.rs:564:1
|
564 | #[bitfield(u16)]
| ^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
= note: #[deny(clippy::bad_bit_mask)] on by default
= note: this error originates in the attribute macro bitfield (in Nightly builds, run with -Z macro-backtrace for more info)
I have debugged it and tracked it down to a debug assert, and propose this change that captures the same logic without causing errors in clippy:
index d0e0c39..669947b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -727,7 +727,7 @@ fn parse_field(attrs: &[syn::Attribute], ty: &syn::Type, ignore: bool) -> syn::R
// Bounds check and remove leading ones from negative values
ret.into = quote! {{
#[allow(unused_comparisons)]
debug_assert!(if this >= 0 { this & !#mask == 0 } else { !this & !#mask == 0 }, "value out of bounds");
debug_assert!(if this >= 0 { this | #mask == #mask } else { !(this | #mask) == 0 }, "value out of bounds");
(this & #mask) as _
}};
}
The text was updated successfully, but these errors were encountered:
snakehand
added a commit
to snakehand/bitfield-struct-rs
that referenced
this issue
Oct 25, 2023
Avoid performing logical and on !mask as this will cause a clippy lint error if result is 0.
Reformulate boolean check to os logial or opereations instead.
This struct produces a clippy error:
#[bitfield(u16)]
/// X axis output value
pub struct OutX{
#[bits(16)]
val: i16,
}
error: &-masking with zero
--> src/lib.rs:564:1
|
564 | #[bitfield(u16)]
| ^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
= note:
#[deny(clippy::bad_bit_mask)]
on by default= note: this error originates in the attribute macro
bitfield
(in Nightly builds, run with -Z macro-backtrace for more info)I have debugged it and tracked it down to a debug assert, and propose this change that captures the same logic without causing errors in clippy:
index d0e0c39..669947b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -727,7 +727,7 @@ fn parse_field(attrs: &[syn::Attribute], ty: &syn::Type, ignore: bool) -> syn::R
// Bounds check and remove leading ones from negative values
ret.into = quote! {{
#[allow(unused_comparisons)]
The text was updated successfully, but these errors were encountered: