Commit d4d276f
committed
Rollup merge of rust-lang#38842 - abonander:proc_macro_attribute, r=jseyfried
Implement `#[proc_macro_attribute]`
This implements `#[proc_macro_attribute]` as described in rust-lang/rfcs#1566
The following major (hopefully non-breaking) changes are included:
* Refactor `proc_macro::TokenStream` to use `syntax::tokenstream::TokenStream`.
* `proc_macro::tokenstream::TokenStream` no longer emits newlines between items, this can be trivially restored if desired
* `proc_macro::TokenStream::from_str` does not try to parse an item anymore, moved to `impl MultiItemModifier for CustomDerive` with more informative error message
* Implement `#[proc_macro_attribute]`, which expects functions of the kind `fn(TokenStream, TokenStream) -> TokenStream`
* Reactivated `#![feature(proc_macro)]` and gated `#[proc_macro_attribute]` under it
* `#![feature(proc_macro)]` and `#![feature(custom_attribute)]` are mutually exclusive
* adding `#![feature(proc_macro)]` makes the expansion pass assume that any attributes that are not built-in, or introduced by existing syntax extensions, are proc-macro attributes
* Fix `feature_gate::find_lang_feature_issue()` to not use `unwrap()`
* This change wasn't necessary for this PR, but it helped debugging a problem where I was using the wrong feature string.
* Move "completed feature gate checking" pass to after "name resolution" pass
* This was necessary for proper feature-gating of `#[proc_macro_attribute]` invocations when the `proc_macro` feature flag isn't set.
Prototype/Litmus Test: [Implementation](https://github.com/abonander/anterofit/blob/proc_macro/service-attr/src/lib.rs#L13) -- [Usage](https://github.com/abonander/anterofit/blob/proc_macro/service-attr/examples/post_service.rs#L35)File tree
24 files changed
+613
-127
lines changed- src
- libproc_macro
- librustc_driver
- librustc_metadata
- librustc_resolve
- libsyntax_ext
- deriving
- libsyntax
- ext
- test
- compile-fail-fulldeps/proc-macro
- auxiliary
- compile-fail
- run-pass-fulldeps/proc-macro
- auxiliary
- tools/tidy/src
24 files changed
+613
-127
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
84 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
88 | 112 | | |
89 | 113 | | |
90 | | - | |
| 114 | + | |
91 | 115 | | |
92 | 116 | | |
93 | 117 | | |
| |||
96 | 120 | | |
97 | 121 | | |
98 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
99 | 127 | | |
100 | 128 | | |
101 | 129 | | |
| |||
125 | 153 | | |
126 | 154 | | |
127 | 155 | | |
128 | | - | |
| 156 | + | |
| 157 | + | |
129 | 158 | | |
130 | 159 | | |
131 | 160 | | |
132 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
133 | 167 | | |
134 | 168 | | |
135 | 169 | | |
| |||
138 | 172 | | |
139 | 173 | | |
140 | 174 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
153 | 179 | | |
154 | 180 | | |
155 | 181 | | |
156 | 182 | | |
157 | 183 | | |
158 | 184 | | |
159 | 185 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 186 | + | |
166 | 187 | | |
167 | 188 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
681 | 681 | | |
682 | 682 | | |
683 | 683 | | |
| 684 | + | |
684 | 685 | | |
685 | 686 | | |
686 | 687 | | |
| |||
740 | 741 | | |
741 | 742 | | |
742 | 743 | | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | 744 | | |
755 | 745 | | |
756 | 746 | | |
| |||
768 | 758 | | |
769 | 759 | | |
770 | 760 | | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
771 | 772 | | |
772 | 773 | | |
773 | 774 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
| 581 | + | |
581 | 582 | | |
582 | 583 | | |
583 | 584 | | |
| |||
613 | 614 | | |
614 | 615 | | |
615 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
616 | 626 | | |
617 | 627 | | |
618 | 628 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
1123 | 1123 | | |
1124 | 1124 | | |
1125 | 1125 | | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
1126 | 1132 | | |
1127 | 1133 | | |
1128 | 1134 | | |
| |||
1227 | 1233 | | |
1228 | 1234 | | |
1229 | 1235 | | |
| 1236 | + | |
| 1237 | + | |
1230 | 1238 | | |
1231 | 1239 | | |
1232 | 1240 | | |
| |||
1284 | 1292 | | |
1285 | 1293 | | |
1286 | 1294 | | |
1287 | | - | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
1288 | 1298 | | |
1289 | 1299 | | |
1290 | 1300 | | |
| |||
1296 | 1306 | | |
1297 | 1307 | | |
1298 | 1308 | | |
| 1309 | + | |
| 1310 | + | |
1299 | 1311 | | |
1300 | 1312 | | |
1301 | 1313 | | |
| |||
1525 | 1537 | | |
1526 | 1538 | | |
1527 | 1539 | | |
| 1540 | + | |
| 1541 | + | |
1528 | 1542 | | |
1529 | 1543 | | |
1530 | 1544 | | |
| |||
1554 | 1568 | | |
1555 | 1569 | | |
1556 | 1570 | | |
| 1571 | + | |
| 1572 | + | |
1557 | 1573 | | |
1558 | 1574 | | |
1559 | 1575 | | |
| |||
1738 | 1754 | | |
1739 | 1755 | | |
1740 | 1756 | | |
| 1757 | + | |
1741 | 1758 | | |
1742 | 1759 | | |
1743 | 1760 | | |
| |||
3184 | 3201 | | |
3185 | 3202 | | |
3186 | 3203 | | |
| 3204 | + | |
| 3205 | + | |
| 3206 | + | |
| 3207 | + | |
| 3208 | + | |
| 3209 | + | |
| 3210 | + | |
| 3211 | + | |
| 3212 | + | |
| 3213 | + | |
| 3214 | + | |
| 3215 | + | |
| 3216 | + | |
| 3217 | + | |
| 3218 | + | |
| 3219 | + | |
| 3220 | + | |
| 3221 | + | |
| 3222 | + | |
| 3223 | + | |
| 3224 | + | |
| 3225 | + | |
| 3226 | + | |
| 3227 | + | |
| 3228 | + | |
3187 | 3229 | | |
3188 | 3230 | | |
3189 | 3231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
| |||
373 | 377 | | |
374 | 378 | | |
375 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
376 | 384 | | |
377 | 385 | | |
378 | 386 | | |
| |||
469 | 477 | | |
470 | 478 | | |
471 | 479 | | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
472 | 513 | | |
0 commit comments