Skip to content
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

Issue 25/avoiding the missing generation of getters for the test build #26

Conversation

diseraluca
Copy link
Owner

Resolves #25.

Recently, the getters for the priority field in
uavcan::session_id::message::MessageSessionId were disabled from being
generated to avoid an unused warning, as they are, indeed, unused in the build
codebase.

Nonetheless, the getter for priority is actually used by one of the tests, such
that is needed, but only when testing.

The general way to do this, would be to add a #[cfg_attr(...)] for the skip
attribute to avoid generating it during testing.

Unfortunately, cfg* attributes are not expanded before proc_macro_attributes
expansion and the modular-bitfield does not manage them manually.

This is a general problem in the proc-macro environment, with an example being
taiki-e/pin-project#68.

The rust team is working on a solution to this, see, for example:

https://doc.rust-lang.org/beta/unstable-book/library-features/cfg-eval.html
https://doc.rust-lang.org/beta/unstable-book/language-features/macro-attributes-in-derive-output.html

And the related issues.

In particular, cfg_eval provides a way to ensure that the cfg attributes are
evaluated before the expansion of the following macros.

For this reason, the cfg_eval was activated, a #[cfg_eval] attribute was
added to MessageSessionId and a cfg_attr conditioned on test was added to
the priority field of the same structure.

As this is not yet stabilized, the crate now depends on nightly, and cannot be
compiled in stable.

It was possible to provide workarounds to avoid moving outside stable.
For example, by duplicating MessageSessionsId and providing a version with the
skip attribute and one without, conditioning the whole structure, instead of a
field attribute, on test.

Nonetheless, being nightly only is not considered a problem for this crate
usage and the "forward-correct" solution was thus preferred.

Recently, the getters for the priority field in
`uavcan::session_id::message::MessageSessionId` were disabled from being
generated to avoid an unused warning, as they are, indeed, unused in the build
codebase.

Nonetheless, the getter for `priority` is actually used by one of the tests, such
that is needed, but only when testing.

The general way to do this, would be to add a `#[cfg_attr(...)]` for the `skip`
attribute to avoid generating it during testing.

Unfortunately, `cfg*` attributes are not expanded before `proc_macro_attributes`
expansion and the `modular-bitfield` does not manage them manually.

This is a general problem in the proc-macro environment, with an example being
taiki-e/pin-project#68.

The rust team is working on a solution to this, see, for example:

https://doc.rust-lang.org/beta/unstable-book/library-features/cfg-eval.html
https://doc.rust-lang.org/beta/unstable-book/language-features/macro-attributes-in-derive-output.html

And the related issues.

In particular, `cfg_eval` provides a way to ensure that the `cfg` attributes are
evaluated before the expansion of the following macros.

For this reason, the `cfg_eval` was activated, a `#[cfg_eval]` attribute was
added to `MessageSessionId` and a `cfg_attr` conditioned on `test` was added to
the priority field of the same structure.

As this is not yet stabilized, the crate now depends on nightly, and cannot be
compiled in stable.

It was possible to provide workarounds to avoid moving outside stable.
For example, by duplicating `MessageSessionsId` and providing a version with the
`skip` attribute and one without, conditioning the whole structure, instead of a
field attribute, on `test`.

Nonetheless, being nightly only is not considered a problem for this crate
usage and the "forward-correct" solution was thus preferred.
@diseraluca diseraluca added bug Something isn't working testing labels May 31, 2021
@diseraluca diseraluca self-assigned this May 31, 2021
@diseraluca diseraluca merged commit 966b3a7 into main May 31, 2021
@diseraluca diseraluca deleted the issue_25/avoiding_the_missing_generation_of_getters_for_the_test_build branch June 29, 2021 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid missing modular-bitfield-generated method in tests.
1 participant