-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the unnecessary braces around From implementations. #66
Comments
Some possible solutions might be:
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:
As the code generated in This can easily be solved locally by parenthesizing the expression itself, knowing that a 0-fields bitfield cannot exist and that the format of
Similar cases may exist but they should be findable by tracing the uses of |
The modular bitfield crate produces an unneccesary braces warning when `From` implementations are generated. See: Robbepop/modular-bitfield#66 A pull request ( Robbepop/modular-bitfield#68 ) to resolve this was provided. Since it is not yet accepted mainstream, the `modular-bitfield` dependency was temporarily moved to a custom fork to move forward with the removal of compilation warnings.
Recently, `generate_bitfield_size` was modified to return an expression not contained in a block, to avoid generating an `unused_braces` warning. See: Robbepop#66 To simplify the reading of the generated code and avoid ambiguities with operators' precedence, further parenthesization was added to the expression itself. The new parenthesization generates an `unused_parenthesis` warning and is now removed.
I'm currently using modular-bitfield for a project and am incurring in warnings generated by the the crate.
When a bitfield structure is annotated with a
repr
representation, the generated code will implement From-conversions to and from the represented type.For example:
Would produce the following code:
In the where clause of the From implementations, the constant expression that gives the length of the of the array is enclosed in braces which are unneeded, producing the following compiler warning:
This From expansion seems to happen in
impl::bitfield::expand::expand_repr_from_impls_and_checks
, where the following lines expand to the warned-about code:Then, in
generate_target_or_actual_bitfield_size
, if the configuration has aNone
value for thebits
field, the generation is delegated togenerate_bitfield_size
which generates the expression with the unneeded braces:I consider that the correct behavior here would be to avoid generating a warning by removing the braces when there is no need for them.
If it is desirable for the project to have this change, I would gladly make it myself as I need it for my project.
The text was updated successfully, but these errors were encountered: