Comments (1)
Some possible solutions might be:
- Add an
#[allow(unused_braces)]
attribute to the generated implementations. - Remove the block and quote only the expression in expand_repr_from_impls_and_checks.
- Remove the block directly in
generate_bitfield_size
, and reinstate the block locally where it is required.
Solution 3 is what I would consider, albeit it requires knowledge of where blocks are needed and might require some code to discern between an actual sum and a value.
For example, if 3 was to be implemented sloppily, the following code would not work anymore:
#[bitfield]
struct Foo {
bar: B16,
baz: B16,
}
As the code generated in impl::bitfield::expand::generate_filled_check_for_aligned_bits
would be incorrectly parenthesized.
This can easily be solved locally by parenthesizing the expression itself, knowing that a 0-fields bitfield cannot exist and that the format of generate_bitfield_size
has, hence, always at least 2 addends, as follows:
fn generate_filled_check_for_aligned_bits(&self, config: &Config) -> TokenStream2 {
[...]
type Size = ::modular_bitfield::private::checks::TotalSize<[(); (#actual_bits) % 8usize]>;
[...]
Similar cases may exist but they should be findable by tracing the uses of generate_bitfield_size
.
from modular-bitfield.
Related Issues (20)
- Support for `to_u32()` conversion to `u32` and similar
- #[bitfield] on empty struct causes compilation error
- Feature Request: Ability to specify default value for field
- Is this crate maintained? HOT 1
- Implement serde derives replacement HOT 2
- Feature request: Array support HOT 3
- Into<uN> and TryFrom<uN> for uN bitfields HOT 2
- `with_*` methods should have `#[must_use]` annotation HOT 2
- Help: CheckFillsUnalignedBits unsatisfied HOT 2
- Support rust union structs HOT 1
- Feature request: Allow naming fields "Bytes" HOT 1
- Question: Array of bitfields HOT 1
- #[repr(...)] for unfilled bitfields?
- Generic structs not supported HOT 7
- [Question] Polymorphic bitfileds HOT 1
- Support for byte arrays
- `#[non_exhaustive]` enum support HOT 9
- const fn support for getters (and setters if possible) HOT 1
- How to implement signed 10 bit number? HOT 8
- [Feature Request] Better Note for (Size % 8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modular-bitfield.