Issue 25/avoiding the missing generation of getters for the test build #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #25.
Recently, the getters for the priority field in
uavcan::session_id::message::MessageSessionId
were disabled from beinggenerated 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, suchthat is needed, but only when testing.
The general way to do this, would be to add a
#[cfg_attr(...)]
for theskip
attribute to avoid generating it during testing.
Unfortunately,
cfg*
attributes are not expanded beforeproc_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 thecfg
attributes areevaluated before the expansion of the following macros.
For this reason, the
cfg_eval
was activated, a#[cfg_eval]
attribute wasadded to
MessageSessionId
and acfg_attr
conditioned ontest
was added tothe 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 theskip
attribute and one without, conditioning the whole structure, instead of afield attribute, on
test
.Nonetheless, being nightly only is not considered a problem for this crate
usage and the "forward-correct" solution was thus preferred.