Add run_before
and run_after
helpers for attribute ordering
#6344
Labels
enhancement
New feature or request
Milestone
Problem
After #6326, all attributes are run in the order they're specified in source code by users. However, library authors may have intended orderings for their attributes that users may get wrong. Currently, providing a good error message for this means doing something like the following for every ordering constraint:
Which in the presence of many ordering constraints is very tedious.
Happy Case
We add
std::meta::run_before
andstd::meta::run_after
helpers to issue these errors automatically if the ordering constraints are ever invalidated. These would never control the attribute ordering, they'd only issue errors if it is invalidated. Because these are normal functions placed within a function body, users could also have complex ordering constraints e.g.if foo_has_field_bar { must_run_after(fixup_bar) }
.One possible signature for these functions could be:
One difficulty is how to track more fine grained ordering relationships like that of
derive_via
andderive
wherederive_via
should run beforederive
, but only for the same trait. Ifderive_via
is called on a new traitFoo
, aderive(Eq)
should not error if run previously to thatderive_via
.A possible way to solve this is to pass additional data to the
attr
parameter of the functions above, and haverun_after
error ifrun_before
was not previously called with the same arguments (determined by equality on T):A disadvantage of this is that it requires both
run_before
andrun_after
to be used, so users can't add constraints between an attribute they control and an attribute originating from an external library.Workaround
None
Workaround Description
No response
Additional Context
No response
Project Impact
None
Blocker Context
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: