feat: Add a relative ordering for attributes #6319
Closed
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.
Description
Problem*
Resolves #6271
Summary*
Wanted to get this before the discussion tomorrow for reference.
Adds a user-defined relative ordering for attributes which orders attributes by annotations placed by the library author of the attribute. This is done with the new
#[run_before(attr)]
and#[run_after(attr)]
attributes which accept another attribute as an argument. Internally, the compiler builds a graph for attributes and topologically sorts it. Then the compiler sorts each attribute usage according to that topological ordering.TODO:
todo!()
s in the codederive
to avoid errors there.derive
d traits are not found byget_trait_impl
#6143 would still exist in the case of one attribute applied to several different items, checking for past work. Different attributes will always be on different steps however.Additional Context
If needed, users can still override an attribute's order by making their own wrapper for the attribute
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.