[legacy] Allow other attributes in #[pin_data] structs #93
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.
When the
__pin_data!(find_pinned_fields:part of the macro encounters an unknown attribute (anything apart from$[pin]) before a field, it is put into the accumulator and the macro proceeds further. Whatever is in the accumulator is later saved into$fieldsand then also into$pinnedor$not_pinneddepending on whether that field is pinned. Pinned fields, with all their unknown attributes are also used in the internal__Unpinstruct.A field can have multiple different attributes, mostly belonging into two different categories. Built-in (defined by the language itself) and arbitrary (any other attribute that is used by another proc-macro crate).
Out of the built-in ones [1] the only things that make sense to be usable for struct fields are most probably just "cfg", "doc", lint levels ("allow", "expect", "warn", "deny", "forbid"), and "deprecated". Out of these the only one that makes sense to keep around for the pin_data macro is "cfg" since that one does a conditional compilation and we only want the members to be included if they are included in the original struct.
From the arbitrary (basically unknown) ones there is no reason for them to be used, mainly because they will likely be part of a derive which will not be included for the
__Unpinstruct, therefore making the code fail to compile if included. Since those need to be kept for the original struct, move them to the$fieldsinstead of$accumin order not to pollute thestruct __Unpinwith unknown attributes.To put this all together, add a test with a custom attribute that fails without this fix. Unfortunately, another crate needs to be added for the test.
[1] https://doc.rust-lang.org/reference/attributes.html#built-in-attributes-index