Commit 3ac3432
committed
Allow other attributes in #[pin_data] structs
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 `$fields` and then also into
`$pinned` or `$not_pinned` depending on whether that field is pinned.
Pinned fields, with all their unknown attributes are also used in the
internal `__Unpin` struct.
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 `__Unpin` struct, therefore making the code
fail to compile if included. Since those need to be kept for the
original struct, move them to the `$fields` instead of `$accum` in order
not to pollute the `struct __Unpin` with 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
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>1 parent bc137a3 commit 3ac3432
File tree
7 files changed
+92
-3
lines changed- src
- test_dummy_only
- src
- tests
7 files changed
+92
-3
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
779 | 779 | | |
780 | 780 | | |
781 | 781 | | |
782 | | - | |
783 | | - | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
784 | 785 | | |
785 | 786 | | |
786 | 787 | | |
| |||
800 | 801 | | |
801 | 802 | | |
802 | 803 | | |
803 | | - | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
804 | 840 | | |
805 | 841 | | |
806 | 842 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments