Commit 674b1c7
rust: init: add support for arbitrary paths in init macros
Previously only `ident` and generic types were supported in the
`{try_}{pin_}init!` macros. This patch allows arbitrary path fragments,
so for example `Foo::Bar` but also very complex paths such as
`<Foo as Baz>::Bar::<0, i32>`.
Internally this is accomplished by using `path` fragments. Due to some
peculiar declarative macro limitations, we have to "forget" certain
additional parsing information in the token trees. This is achieved by
using the `paste!` proc macro. It does not actually modify the input,
since no `[< >]` will be present in the input, so it just strips the
information held by declarative macros. For example, if a declarative
macro takes `$t:path` as its input, it cannot sensibly propagate this to
a macro that takes `$($p:tt)*` as its input, since the `$t` token will
only be considered one `tt` token for the second macro. If we first pipe
the tokens through `paste!`, then it parses as expected.
Suggested-by: Asahi Lina <lina@asahilina.net>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20230814084602.25699-10-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>1 parent 9e49439 commit 674b1c7
1 file changed
+35
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1000 | 1000 | | |
1001 | 1001 | | |
1002 | 1002 | | |
1003 | | - | |
| 1003 | + | |
1004 | 1004 | | |
1005 | 1005 | | |
1006 | 1006 | | |
| |||
1014 | 1014 | | |
1015 | 1015 | | |
1016 | 1016 | | |
1017 | | - | |
| 1017 | + | |
1018 | 1018 | | |
1019 | 1019 | | |
1020 | 1020 | | |
| |||
1025 | 1025 | | |
1026 | 1026 | | |
1027 | 1027 | | |
1028 | | - | |
| 1028 | + | |
1029 | 1029 | | |
1030 | 1030 | | |
1031 | 1031 | | |
| |||
1039 | 1039 | | |
1040 | 1040 | | |
1041 | 1041 | | |
1042 | | - | |
| 1042 | + | |
1043 | 1043 | | |
1044 | 1044 | | |
1045 | 1045 | | |
| |||
1050 | 1050 | | |
1051 | 1051 | | |
1052 | 1052 | | |
1053 | | - | |
| 1053 | + | |
1054 | 1054 | | |
1055 | 1055 | | |
1056 | 1056 | | |
| |||
1064 | 1064 | | |
1065 | 1065 | | |
1066 | 1066 | | |
1067 | | - | |
| 1067 | + | |
1068 | 1068 | | |
1069 | 1069 | | |
1070 | 1070 | | |
| |||
1075 | 1075 | | |
1076 | 1076 | | |
1077 | 1077 | | |
1078 | | - | |
| 1078 | + | |
1079 | 1079 | | |
1080 | 1080 | | |
1081 | 1081 | | |
| |||
1094 | 1094 | | |
1095 | 1095 | | |
1096 | 1096 | | |
1097 | | - | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
1098 | 1102 | | |
1099 | 1103 | | |
1100 | 1104 | | |
| |||
1253 | 1257 | | |
1254 | 1258 | | |
1255 | 1259 | | |
1256 | | - | |
| 1260 | + | |
1257 | 1261 | | |
1258 | 1262 | | |
1259 | 1263 | | |
| |||
1270 | 1274 | | |
1271 | 1275 | | |
1272 | 1276 | | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
1277 | 1287 | | |
1278 | 1288 | | |
1279 | 1289 | | |
1280 | 1290 | | |
1281 | | - | |
| 1291 | + | |
1282 | 1292 | | |
1283 | 1293 | | |
1284 | 1294 | | |
1285 | 1295 | | |
1286 | 1296 | | |
1287 | 1297 | | |
1288 | 1298 | | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
1292 | 1308 | | |
1293 | 1309 | | |
1294 | 1310 | | |
1295 | 1311 | | |
1296 | | - | |
| 1312 | + | |
1297 | 1313 | | |
1298 | 1314 | | |
1299 | 1315 | | |
| |||
1306 | 1322 | | |
1307 | 1323 | | |
1308 | 1324 | | |
1309 | | - | |
| 1325 | + | |
1310 | 1326 | | |
1311 | 1327 | | |
1312 | 1328 | | |
| |||
0 commit comments