diff options
-rw-r--r-- | Cargo.lock | 114 | ||||
-rw-r--r-- | crates/flycheck/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/generate_derive.rs | 4 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/generate_impl.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/type_ref.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_implementation.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/html.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/test_data/rainbow_highlighting.html | 12 | ||||
-rw-r--r-- | crates/ra_proc_macro_srv/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_project_model/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/expr_ext.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated/nodes.rs | 3039 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/node_ext.rs | 16 | ||||
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 25 | ||||
-rw-r--r-- | xtask/Cargo.toml | 9 | ||||
-rw-r--r-- | xtask/src/ast_src.rs | 2001 | ||||
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 224 | ||||
-rw-r--r-- | xtask/src/codegen/rust.ungram | 529 | ||||
-rw-r--r-- | xtask/tests/tidy.rs | 1 |
21 files changed, 1624 insertions, 4386 deletions
diff --git a/Cargo.lock b/Cargo.lock index ff225399e..3e685b7f1 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -102,13 +102,12 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" | |||
102 | 102 | ||
103 | [[package]] | 103 | [[package]] |
104 | name = "cargo_metadata" | 104 | name = "cargo_metadata" |
105 | version = "0.10.0" | 105 | version = "0.11.1" |
106 | source = "registry+https://github.com/rust-lang/crates.io-index" | 106 | source = "registry+https://github.com/rust-lang/crates.io-index" |
107 | checksum = "b8de60b887edf6d74370fc8eb177040da4847d971d6234c7b13a6da324ef0caf" | 107 | checksum = "89fec17b16f1ac67908af82e47d0a90a7afd0e1827b181cd77504323d3263d35" |
108 | dependencies = [ | 108 | dependencies = [ |
109 | "semver", | 109 | "semver", |
110 | "serde", | 110 | "serde", |
111 | "serde_derive", | ||
112 | "serde_json", | 111 | "serde_json", |
113 | ] | 112 | ] |
114 | 113 | ||
@@ -319,9 +318,9 @@ dependencies = [ | |||
319 | 318 | ||
320 | [[package]] | 319 | [[package]] |
321 | name = "filetime" | 320 | name = "filetime" |
322 | version = "0.2.10" | 321 | version = "0.2.11" |
323 | source = "registry+https://github.com/rust-lang/crates.io-index" | 322 | source = "registry+https://github.com/rust-lang/crates.io-index" |
324 | checksum = "affc17579b132fc2461adf7c575cc6e8b134ebca52c51f5411388965227dc695" | 323 | checksum = "e500da2fab70bdc43f8f0e0b350a227f31c72311c56aba48f01d5cd62bb0345b" |
325 | dependencies = [ | 324 | dependencies = [ |
326 | "cfg-if", | 325 | "cfg-if", |
327 | "libc", | 326 | "libc", |
@@ -401,17 +400,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
401 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" | 400 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" |
402 | 401 | ||
403 | [[package]] | 402 | [[package]] |
404 | name = "getrandom" | ||
405 | version = "0.1.14" | ||
406 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
407 | checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" | ||
408 | dependencies = [ | ||
409 | "cfg-if", | ||
410 | "libc", | ||
411 | "wasi", | ||
412 | ] | ||
413 | |||
414 | [[package]] | ||
415 | name = "gimli" | 403 | name = "gimli" |
416 | version = "0.22.0" | 404 | version = "0.22.0" |
417 | source = "registry+https://github.com/rust-lang/crates.io-index" | 405 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -565,9 +553,9 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" | |||
565 | 553 | ||
566 | [[package]] | 554 | [[package]] |
567 | name = "libc" | 555 | name = "libc" |
568 | version = "0.2.73" | 556 | version = "0.2.74" |
569 | source = "registry+https://github.com/rust-lang/crates.io-index" | 557 | source = "registry+https://github.com/rust-lang/crates.io-index" |
570 | checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" | 558 | checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" |
571 | 559 | ||
572 | [[package]] | 560 | [[package]] |
573 | name = "libloading" | 561 | name = "libloading" |
@@ -811,6 +799,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
811 | checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" | 799 | checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" |
812 | 800 | ||
813 | [[package]] | 801 | [[package]] |
802 | name = "oorandom" | ||
803 | version = "11.1.2" | ||
804 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
805 | checksum = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c" | ||
806 | |||
807 | [[package]] | ||
814 | name = "parking_lot" | 808 | name = "parking_lot" |
815 | version = "0.11.0" | 809 | version = "0.11.0" |
816 | source = "registry+https://github.com/rust-lang/crates.io-index" | 810 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -869,12 +863,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
869 | checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" | 863 | checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" |
870 | 864 | ||
871 | [[package]] | 865 | [[package]] |
872 | name = "ppv-lite86" | ||
873 | version = "0.2.8" | ||
874 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
875 | checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" | ||
876 | |||
877 | [[package]] | ||
878 | name = "proc-macro2" | 866 | name = "proc-macro2" |
879 | version = "1.0.19" | 867 | version = "1.0.19" |
880 | source = "registry+https://github.com/rust-lang/crates.io-index" | 868 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1046,6 +1034,7 @@ dependencies = [ | |||
1046 | "indexmap", | 1034 | "indexmap", |
1047 | "itertools", | 1035 | "itertools", |
1048 | "log", | 1036 | "log", |
1037 | "oorandom", | ||
1049 | "ra_assists", | 1038 | "ra_assists", |
1050 | "ra_cfg", | 1039 | "ra_cfg", |
1051 | "ra_db", | 1040 | "ra_db", |
@@ -1056,7 +1045,6 @@ dependencies = [ | |||
1056 | "ra_ssr", | 1045 | "ra_ssr", |
1057 | "ra_syntax", | 1046 | "ra_syntax", |
1058 | "ra_text_edit", | 1047 | "ra_text_edit", |
1059 | "rand", | ||
1060 | "rustc-hash", | 1048 | "rustc-hash", |
1061 | "stdx", | 1049 | "stdx", |
1062 | "test_utils", | 1050 | "test_utils", |
@@ -1218,57 +1206,6 @@ dependencies = [ | |||
1218 | ] | 1206 | ] |
1219 | 1207 | ||
1220 | [[package]] | 1208 | [[package]] |
1221 | name = "rand" | ||
1222 | version = "0.7.3" | ||
1223 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1224 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" | ||
1225 | dependencies = [ | ||
1226 | "getrandom", | ||
1227 | "libc", | ||
1228 | "rand_chacha", | ||
1229 | "rand_core", | ||
1230 | "rand_hc", | ||
1231 | "rand_pcg", | ||
1232 | ] | ||
1233 | |||
1234 | [[package]] | ||
1235 | name = "rand_chacha" | ||
1236 | version = "0.2.2" | ||
1237 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1238 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" | ||
1239 | dependencies = [ | ||
1240 | "ppv-lite86", | ||
1241 | "rand_core", | ||
1242 | ] | ||
1243 | |||
1244 | [[package]] | ||
1245 | name = "rand_core" | ||
1246 | version = "0.5.1" | ||
1247 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1248 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" | ||
1249 | dependencies = [ | ||
1250 | "getrandom", | ||
1251 | ] | ||
1252 | |||
1253 | [[package]] | ||
1254 | name = "rand_hc" | ||
1255 | version = "0.2.0" | ||
1256 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1257 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" | ||
1258 | dependencies = [ | ||
1259 | "rand_core", | ||
1260 | ] | ||
1261 | |||
1262 | [[package]] | ||
1263 | name = "rand_pcg" | ||
1264 | version = "0.2.1" | ||
1265 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1266 | checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" | ||
1267 | dependencies = [ | ||
1268 | "rand_core", | ||
1269 | ] | ||
1270 | |||
1271 | [[package]] | ||
1272 | name = "rayon" | 1209 | name = "rayon" |
1273 | version = "1.3.1" | 1210 | version = "1.3.1" |
1274 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1211 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1354,6 +1291,7 @@ dependencies = [ | |||
1354 | "lsp-server", | 1291 | "lsp-server", |
1355 | "lsp-types", | 1292 | "lsp-types", |
1356 | "mimalloc", | 1293 | "mimalloc", |
1294 | "oorandom", | ||
1357 | "parking_lot", | 1295 | "parking_lot", |
1358 | "pico-args", | 1296 | "pico-args", |
1359 | "ra_cfg", | 1297 | "ra_cfg", |
@@ -1372,7 +1310,6 @@ dependencies = [ | |||
1372 | "ra_text_edit", | 1310 | "ra_text_edit", |
1373 | "ra_toolchain", | 1311 | "ra_toolchain", |
1374 | "ra_tt", | 1312 | "ra_tt", |
1375 | "rand", | ||
1376 | "rayon", | 1313 | "rayon", |
1377 | "rustc-hash", | 1314 | "rustc-hash", |
1378 | "serde", | 1315 | "serde", |
@@ -1414,16 +1351,16 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" | |||
1414 | 1351 | ||
1415 | [[package]] | 1352 | [[package]] |
1416 | name = "salsa" | 1353 | name = "salsa" |
1417 | version = "0.15.0" | 1354 | version = "0.15.1" |
1418 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1355 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1419 | checksum = "885b4b99dde959decc84e85dd943bd140b4aabd62db2f8206ef5270f77ec20b9" | 1356 | checksum = "d4cdc109fcc9e9450c7ef47fb7474e99bffd51799da03ed0a6c7f0e2cb3848a6" |
1420 | dependencies = [ | 1357 | dependencies = [ |
1421 | "crossbeam-utils", | 1358 | "crossbeam-utils", |
1422 | "indexmap", | 1359 | "indexmap", |
1423 | "lock_api", | 1360 | "lock_api", |
1424 | "log", | 1361 | "log", |
1362 | "oorandom", | ||
1425 | "parking_lot", | 1363 | "parking_lot", |
1426 | "rand", | ||
1427 | "rustc-hash", | 1364 | "rustc-hash", |
1428 | "salsa-macros", | 1365 | "salsa-macros", |
1429 | "smallvec", | 1366 | "smallvec", |
@@ -1484,9 +1421,9 @@ dependencies = [ | |||
1484 | 1421 | ||
1485 | [[package]] | 1422 | [[package]] |
1486 | name = "semver" | 1423 | name = "semver" |
1487 | version = "0.9.0" | 1424 | version = "0.10.0" |
1488 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1425 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1489 | checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" | 1426 | checksum = "394cec28fa623e00903caf7ba4fa6fb9a0e260280bb8cdbbba029611108a0190" |
1490 | dependencies = [ | 1427 | dependencies = [ |
1491 | "semver-parser", | 1428 | "semver-parser", |
1492 | "serde", | 1429 | "serde", |
@@ -1750,6 +1687,12 @@ dependencies = [ | |||
1750 | ] | 1687 | ] |
1751 | 1688 | ||
1752 | [[package]] | 1689 | [[package]] |
1690 | name = "ungrammar" | ||
1691 | version = "0.1.0" | ||
1692 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1693 | checksum = "0ee12e4891ab3acc2d95d5023022ace22020247bb8a8d1ece875a443f7dab37d" | ||
1694 | |||
1695 | [[package]] | ||
1753 | name = "unicode-bidi" | 1696 | name = "unicode-bidi" |
1754 | version = "0.3.4" | 1697 | version = "0.3.4" |
1755 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1698 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1826,12 +1769,6 @@ dependencies = [ | |||
1826 | ] | 1769 | ] |
1827 | 1770 | ||
1828 | [[package]] | 1771 | [[package]] |
1829 | name = "wasi" | ||
1830 | version = "0.9.0+wasi-snapshot-preview1" | ||
1831 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1832 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" | ||
1833 | |||
1834 | [[package]] | ||
1835 | name = "winapi" | 1772 | name = "winapi" |
1836 | version = "0.2.8" | 1773 | version = "0.2.8" |
1837 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1774 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1893,5 +1830,6 @@ dependencies = [ | |||
1893 | "pico-args", | 1830 | "pico-args", |
1894 | "proc-macro2", | 1831 | "proc-macro2", |
1895 | "quote", | 1832 | "quote", |
1833 | "ungrammar", | ||
1896 | "walkdir", | 1834 | "walkdir", |
1897 | ] | 1835 | ] |
diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml index bea485694..ff8a1e568 100644 --- a/crates/flycheck/Cargo.toml +++ b/crates/flycheck/Cargo.toml | |||
@@ -11,7 +11,7 @@ doctest = false | |||
11 | [dependencies] | 11 | [dependencies] |
12 | crossbeam-channel = "0.4.0" | 12 | crossbeam-channel = "0.4.0" |
13 | log = "0.4.8" | 13 | log = "0.4.8" |
14 | cargo_metadata = "0.10.0" | 14 | cargo_metadata = "0.11.1" |
15 | serde_json = "1.0.48" | 15 | serde_json = "1.0.48" |
16 | jod-thread = "0.1.1" | 16 | jod-thread = "0.1.1" |
17 | ra_toolchain = { path = "../ra_toolchain" } | 17 | ra_toolchain = { path = "../ra_toolchain" } |
diff --git a/crates/ra_assists/src/handlers/generate_derive.rs b/crates/ra_assists/src/handlers/generate_derive.rs index 6ccf39900..90ece9fab 100644 --- a/crates/ra_assists/src/handlers/generate_derive.rs +++ b/crates/ra_assists/src/handlers/generate_derive.rs | |||
@@ -26,7 +26,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
26 | // ``` | 26 | // ``` |
27 | pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 27 | pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
28 | let cap = ctx.config.snippet_cap?; | 28 | let cap = ctx.config.snippet_cap?; |
29 | let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; | 29 | let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?; |
30 | let node_start = derive_insertion_offset(&nominal)?; | 30 | let node_start = derive_insertion_offset(&nominal)?; |
31 | let target = nominal.syntax().text_range(); | 31 | let target = nominal.syntax().text_range(); |
32 | acc.add( | 32 | acc.add( |
@@ -58,7 +58,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option< | |||
58 | } | 58 | } |
59 | 59 | ||
60 | // Insert `derive` after doc comments. | 60 | // Insert `derive` after doc comments. |
61 | fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> { | 61 | fn derive_insertion_offset(nominal: &ast::AdtDef) -> Option<TextSize> { |
62 | let non_ws_child = nominal | 62 | let non_ws_child = nominal |
63 | .syntax() | 63 | .syntax() |
64 | .children_with_tokens() | 64 | .children_with_tokens() |
diff --git a/crates/ra_assists/src/handlers/generate_impl.rs b/crates/ra_assists/src/handlers/generate_impl.rs index cbbac1d7f..42eb4defa 100644 --- a/crates/ra_assists/src/handlers/generate_impl.rs +++ b/crates/ra_assists/src/handlers/generate_impl.rs | |||
@@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; | |||
23 | // } | 23 | // } |
24 | // ``` | 24 | // ``` |
25 | pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 25 | pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
26 | let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; | 26 | let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?; |
27 | let name = nominal.name()?; | 27 | let name = nominal.name()?; |
28 | let target = nominal.syntax().text_range(); | 28 | let target = nominal.syntax().text_range(); |
29 | acc.add( | 29 | acc.add( |
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index e90b2a0b9..970fc9af5 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! HIR for references to types. Paths in these are not yet resolved. They can | 1 | //! HIR for references to types. Paths in these are not yet resolved. They can |
2 | //! be directly created from an ast::TypeRef, without further queries. | 2 | //! be directly created from an ast::TypeRef, without further queries. |
3 | 3 | ||
4 | use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner}; | 4 | use ra_syntax::ast::{self, TypeAscriptionOwner}; |
5 | 5 | ||
6 | use crate::{body::LowerCtx, path::Path}; | 6 | use crate::{body::LowerCtx, path::Path}; |
7 | 7 | ||
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 6f8107491..f4181c4eb 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml | |||
@@ -17,7 +17,7 @@ indexmap = "1.3.2" | |||
17 | itertools = "0.9.0" | 17 | itertools = "0.9.0" |
18 | log = "0.4.8" | 18 | log = "0.4.8" |
19 | rustc-hash = "1.1.0" | 19 | rustc-hash = "1.1.0" |
20 | rand = { version = "0.7.3", features = ["small_rng"] } | 20 | oorandom = "11.1.2" |
21 | 21 | ||
22 | stdx = { path = "../stdx" } | 22 | stdx = { path = "../stdx" } |
23 | 23 | ||
diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index 3ee048f28..16a61d071 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs | |||
@@ -23,7 +23,7 @@ pub(crate) fn goto_implementation( | |||
23 | 23 | ||
24 | let krate = sema.to_module_def(position.file_id)?.krate(); | 24 | let krate = sema.to_module_def(position.file_id)?.krate(); |
25 | 25 | ||
26 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { | 26 | if let Some(nominal_def) = find_node_at_offset::<ast::AdtDef>(&syntax, position.offset) { |
27 | return Some(RangeInfo::new( | 27 | return Some(RangeInfo::new( |
28 | nominal_def.syntax().text_range(), | 28 | nominal_def.syntax().text_range(), |
29 | impls_for_def(&sema, &nominal_def, krate)?, | 29 | impls_for_def(&sema, &nominal_def, krate)?, |
@@ -40,13 +40,13 @@ pub(crate) fn goto_implementation( | |||
40 | 40 | ||
41 | fn impls_for_def( | 41 | fn impls_for_def( |
42 | sema: &Semantics<RootDatabase>, | 42 | sema: &Semantics<RootDatabase>, |
43 | node: &ast::NominalDef, | 43 | node: &ast::AdtDef, |
44 | krate: Crate, | 44 | krate: Crate, |
45 | ) -> Option<Vec<NavigationTarget>> { | 45 | ) -> Option<Vec<NavigationTarget>> { |
46 | let ty = match node { | 46 | let ty = match node { |
47 | ast::NominalDef::StructDef(def) => sema.to_def(def)?.ty(sema.db), | 47 | ast::AdtDef::StructDef(def) => sema.to_def(def)?.ty(sema.db), |
48 | ast::NominalDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), | 48 | ast::AdtDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), |
49 | ast::NominalDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), | 49 | ast::AdtDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), |
50 | }; | 50 | }; |
51 | 51 | ||
52 | let impls = ImplDef::all_in_crate(sema.db, krate); | 52 | let impls = ImplDef::all_in_crate(sema.db, krate); |
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index 0be55bca9..a5e7d2867 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | //! Renders a bit of code as HTML. | 1 | //! Renders a bit of code as HTML. |
2 | 2 | ||
3 | use oorandom::Rand32; | ||
3 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
4 | use ra_syntax::{AstNode, TextRange, TextSize}; | 5 | use ra_syntax::{AstNode, TextRange, TextSize}; |
5 | 6 | ||
@@ -9,13 +10,12 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
9 | let parse = db.parse(file_id); | 10 | let parse = db.parse(file_id); |
10 | 11 | ||
11 | fn rainbowify(seed: u64) -> String { | 12 | fn rainbowify(seed: u64) -> String { |
12 | use rand::prelude::*; | 13 | let mut rng = Rand32::new(seed); |
13 | let mut rng = SmallRng::seed_from_u64(seed); | ||
14 | format!( | 14 | format!( |
15 | "hsl({h},{s}%,{l}%)", | 15 | "hsl({h},{s}%,{l}%)", |
16 | h = rng.gen_range::<u16, _, _>(0, 361), | 16 | h = rng.rand_range(0..361), |
17 | s = rng.gen_range::<u16, _, _>(42, 99), | 17 | s = rng.rand_range(42..99), |
18 | l = rng.gen_range::<u16, _, _>(40, 91), | 18 | l = rng.rand_range(40..91), |
19 | ) | 19 | ) |
20 | } | 20 | } |
21 | 21 | ||
diff --git a/crates/ra_ide/test_data/rainbow_highlighting.html b/crates/ra_ide/test_data/rainbow_highlighting.html index 08d83302c..401e87a73 100644 --- a/crates/ra_ide/test_data/rainbow_highlighting.html +++ b/crates/ra_ide/test_data/rainbow_highlighting.html | |||
@@ -36,14 +36,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
36 | .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } | 36 | .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } |
37 | </style> | 37 | </style> |
38 | <pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 38 | <pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
39 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> | 39 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> |
40 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 40 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(76,47%,83%);">x</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
41 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 41 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(15,86%,51%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
42 | 42 | ||
43 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> <span class="operator">=</span> <span class="string_literal">"other color please!"</span><span class="punctuation">;</span> | 43 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(127,71%,87%);">x</span> <span class="operator">=</span> <span class="string_literal">"other color please!"</span><span class="punctuation">;</span> |
44 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 44 | <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(90,74%,79%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(127,71%,87%);">x</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
45 | <span class="punctuation">}</span> | 45 | <span class="punctuation">}</span> |
46 | 46 | ||
47 | <span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 47 | <span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
48 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> | 48 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> |
49 | <span class="punctuation">}</span></code></pre> \ No newline at end of file | 49 | <span class="punctuation">}</span></code></pre> \ No newline at end of file |
diff --git a/crates/ra_proc_macro_srv/Cargo.toml b/crates/ra_proc_macro_srv/Cargo.toml index 12ce497f8..bc119a6c7 100644 --- a/crates/ra_proc_macro_srv/Cargo.toml +++ b/crates/ra_proc_macro_srv/Cargo.toml | |||
@@ -19,7 +19,7 @@ memmap = "0.7" | |||
19 | test_utils = { path = "../test_utils" } | 19 | test_utils = { path = "../test_utils" } |
20 | 20 | ||
21 | [dev-dependencies] | 21 | [dev-dependencies] |
22 | cargo_metadata = "0.10.0" | 22 | cargo_metadata = "0.11.1" |
23 | difference = "2.0.0" | 23 | difference = "2.0.0" |
24 | # used as proc macro test target | 24 | # used as proc macro test target |
25 | serde_derive = "1.0.106" | 25 | serde_derive = "1.0.106" |
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml index 827eb7e28..99adea8e4 100644 --- a/crates/ra_project_model/Cargo.toml +++ b/crates/ra_project_model/Cargo.toml | |||
@@ -12,7 +12,7 @@ doctest = false | |||
12 | log = "0.4.8" | 12 | log = "0.4.8" |
13 | rustc-hash = "1.1.0" | 13 | rustc-hash = "1.1.0" |
14 | 14 | ||
15 | cargo_metadata = "0.10.0" | 15 | cargo_metadata = "0.11.1" |
16 | 16 | ||
17 | ra_arena = { path = "../ra_arena" } | 17 | ra_arena = { path = "../ra_arena" } |
18 | ra_cfg = { path = "../ra_cfg" } | 18 | ra_cfg = { path = "../ra_cfg" } |
diff --git a/crates/ra_syntax/src/ast/expr_ext.rs b/crates/ra_syntax/src/ast/expr_ext.rs index db5438d68..69c85c809 100644 --- a/crates/ra_syntax/src/ast/expr_ext.rs +++ b/crates/ra_syntax/src/ast/expr_ext.rs | |||
@@ -7,6 +7,8 @@ use crate::{ | |||
7 | SyntaxToken, T, | 7 | SyntaxToken, T, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | impl ast::AttrsOwner for ast::Expr {} | ||
11 | |||
10 | impl ast::Expr { | 12 | impl ast::Expr { |
11 | pub fn is_block_like(&self) -> bool { | 13 | pub fn is_block_like(&self) -> bool { |
12 | match self { | 14 | match self { |
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 58141da11..04a4d354c 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs | |||
@@ -5,50 +5,34 @@ use crate::{ | |||
5 | SyntaxKind::{self, *}, | 5 | SyntaxKind::{self, *}, |
6 | SyntaxNode, SyntaxToken, T, | 6 | SyntaxNode, SyntaxToken, T, |
7 | }; | 7 | }; |
8 | /// The entire Rust source file. Includes all top-level inner attributes and module items. | ||
9 | /// | ||
10 | /// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html) | ||
11 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 8 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
12 | pub struct SourceFile { | 9 | pub struct SourceFile { |
13 | pub(crate) syntax: SyntaxNode, | 10 | pub(crate) syntax: SyntaxNode, |
14 | } | 11 | } |
15 | impl ast::ModuleItemOwner for SourceFile {} | ||
16 | impl ast::AttrsOwner for SourceFile {} | 12 | impl ast::AttrsOwner for SourceFile {} |
17 | impl ast::DocCommentsOwner for SourceFile {} | 13 | impl ast::ModuleItemOwner for SourceFile {} |
18 | impl SourceFile { | 14 | impl SourceFile {} |
19 | pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } | 15 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
20 | } | 16 | pub struct Attr { |
21 | /// Function definition either with body or not. | 17 | pub(crate) syntax: SyntaxNode, |
22 | /// Includes all of its attributes and doc comments. | 18 | } |
23 | /// | 19 | impl Attr { |
24 | /// ``` | 20 | pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) } |
25 | /// ❰ | 21 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } |
26 | /// /// Docs | 22 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
27 | /// #[attr] | 23 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
28 | /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 | 24 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
29 | /// where | 25 | pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) } |
30 | /// T: Debug | 26 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
31 | /// { | 27 | } |
32 | /// 42 | ||
33 | /// } | ||
34 | /// ❱ | ||
35 | /// | ||
36 | /// extern "C" { | ||
37 | /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱ | ||
38 | /// } | ||
39 | /// ``` | ||
40 | /// | ||
41 | /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
42 | /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions) | ||
43 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 28 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
44 | pub struct FnDef { | 29 | pub struct FnDef { |
45 | pub(crate) syntax: SyntaxNode, | 30 | pub(crate) syntax: SyntaxNode, |
46 | } | 31 | } |
47 | impl ast::VisibilityOwner for FnDef {} | 32 | impl ast::AttrsOwner for FnDef {} |
48 | impl ast::NameOwner for FnDef {} | 33 | impl ast::NameOwner for FnDef {} |
34 | impl ast::VisibilityOwner for FnDef {} | ||
49 | impl ast::TypeParamsOwner for FnDef {} | 35 | impl ast::TypeParamsOwner for FnDef {} |
50 | impl ast::DocCommentsOwner for FnDef {} | ||
51 | impl ast::AttrsOwner for FnDef {} | ||
52 | impl FnDef { | 36 | impl FnDef { |
53 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | 37 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } |
54 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 38 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
@@ -61,13 +45,53 @@ impl FnDef { | |||
61 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 45 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
62 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 46 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
63 | } | 47 | } |
64 | /// Return type annotation. | 48 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
65 | /// | 49 | pub struct Visibility { |
66 | /// ``` | 50 | pub(crate) syntax: SyntaxNode, |
67 | /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } | 51 | } |
68 | /// ``` | 52 | impl Visibility { |
69 | /// | 53 | pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) } |
70 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | 54 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } |
55 | pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) } | ||
56 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
57 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | ||
58 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } | ||
59 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
60 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
61 | } | ||
62 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
63 | pub struct Abi { | ||
64 | pub(crate) syntax: SyntaxNode, | ||
65 | } | ||
66 | impl Abi {} | ||
67 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
68 | pub struct Name { | ||
69 | pub(crate) syntax: SyntaxNode, | ||
70 | } | ||
71 | impl Name { | ||
72 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | ||
73 | } | ||
74 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
75 | pub struct TypeParamList { | ||
76 | pub(crate) syntax: SyntaxNode, | ||
77 | } | ||
78 | impl TypeParamList { | ||
79 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | ||
80 | pub fn type_params(&self) -> AstChildren<TypeParam> { support::children(&self.syntax) } | ||
81 | pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> { support::children(&self.syntax) } | ||
82 | pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) } | ||
83 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | ||
84 | } | ||
85 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
86 | pub struct ParamList { | ||
87 | pub(crate) syntax: SyntaxNode, | ||
88 | } | ||
89 | impl ParamList { | ||
90 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
91 | pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) } | ||
92 | pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } | ||
93 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
94 | } | ||
71 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 95 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
72 | pub struct RetType { | 96 | pub struct RetType { |
73 | pub(crate) syntax: SyntaxNode, | 97 | pub(crate) syntax: SyntaxNode, |
@@ -76,204 +100,105 @@ impl RetType { | |||
76 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } | 100 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } |
77 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 101 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
78 | } | 102 | } |
79 | /// Struct definition. | 103 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
80 | /// Includes all of its attributes and doc comments. | 104 | pub struct WhereClause { |
81 | /// | 105 | pub(crate) syntax: SyntaxNode, |
82 | /// ``` | 106 | } |
83 | /// ❰ | 107 | impl WhereClause { |
84 | /// /// Docs | 108 | pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } |
85 | /// #[attr] | 109 | pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } |
86 | /// struct Foo<T> where T: Debug { | 110 | } |
87 | /// /// Docs | 111 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
88 | /// #[attr] | 112 | pub struct BlockExpr { |
89 | /// pub a: u32, | 113 | pub(crate) syntax: SyntaxNode, |
90 | /// b: T, | 114 | } |
91 | /// } | 115 | impl ast::AttrsOwner for BlockExpr {} |
92 | /// ❱ | 116 | impl ast::ModuleItemOwner for BlockExpr {} |
93 | /// | 117 | impl BlockExpr { |
94 | /// ❰ struct Foo; ❱ | 118 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } |
95 | /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ | 119 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
96 | /// ``` | 120 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } |
97 | /// | 121 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
98 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | 122 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
123 | } | ||
99 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 124 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
100 | pub struct StructDef { | 125 | pub struct StructDef { |
101 | pub(crate) syntax: SyntaxNode, | 126 | pub(crate) syntax: SyntaxNode, |
102 | } | 127 | } |
103 | impl ast::VisibilityOwner for StructDef {} | 128 | impl ast::AttrsOwner for StructDef {} |
104 | impl ast::NameOwner for StructDef {} | 129 | impl ast::NameOwner for StructDef {} |
130 | impl ast::VisibilityOwner for StructDef {} | ||
105 | impl ast::TypeParamsOwner for StructDef {} | 131 | impl ast::TypeParamsOwner for StructDef {} |
106 | impl ast::AttrsOwner for StructDef {} | ||
107 | impl ast::DocCommentsOwner for StructDef {} | ||
108 | impl StructDef { | 132 | impl StructDef { |
109 | pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) } | 133 | pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) } |
110 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } | ||
111 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 134 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
135 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } | ||
136 | } | ||
137 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
138 | pub struct RecordFieldDefList { | ||
139 | pub(crate) syntax: SyntaxNode, | ||
140 | } | ||
141 | impl RecordFieldDefList { | ||
142 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
143 | pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } | ||
144 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
145 | } | ||
146 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
147 | pub struct TupleFieldDefList { | ||
148 | pub(crate) syntax: SyntaxNode, | ||
149 | } | ||
150 | impl TupleFieldDefList { | ||
151 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
152 | pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } | ||
153 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
112 | } | 154 | } |
113 | /// Union definition. | ||
114 | /// Includes all of its attributes and doc comments. | ||
115 | /// | ||
116 | /// ``` | ||
117 | /// ❰ | ||
118 | /// /// Docs | ||
119 | /// #[attr] | ||
120 | /// pub union Foo<T> where T: Debug { | ||
121 | /// /// Docs | ||
122 | /// #[attr] | ||
123 | /// a: T, | ||
124 | /// b: u32, | ||
125 | /// } | ||
126 | /// ❱ | ||
127 | /// ``` | ||
128 | /// | ||
129 | /// [Reference](https://doc.rust-lang.org/reference/items/unions.html) | ||
130 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 155 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
131 | pub struct UnionDef { | 156 | pub struct UnionDef { |
132 | pub(crate) syntax: SyntaxNode, | 157 | pub(crate) syntax: SyntaxNode, |
133 | } | 158 | } |
134 | impl ast::VisibilityOwner for UnionDef {} | 159 | impl ast::AttrsOwner for UnionDef {} |
135 | impl ast::NameOwner for UnionDef {} | 160 | impl ast::NameOwner for UnionDef {} |
161 | impl ast::VisibilityOwner for UnionDef {} | ||
136 | impl ast::TypeParamsOwner for UnionDef {} | 162 | impl ast::TypeParamsOwner for UnionDef {} |
137 | impl ast::AttrsOwner for UnionDef {} | ||
138 | impl ast::DocCommentsOwner for UnionDef {} | ||
139 | impl UnionDef { | 163 | impl UnionDef { |
140 | pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) } | 164 | pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) } |
141 | pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> { | 165 | pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> { |
142 | support::child(&self.syntax) | 166 | support::child(&self.syntax) |
143 | } | 167 | } |
144 | } | 168 | } |
145 | /// Record field definition list including enclosing curly braces. | ||
146 | /// | ||
147 | /// ``` | ||
148 | /// struct Foo // same for union | ||
149 | /// ❰ | ||
150 | /// { | ||
151 | /// a: u32, | ||
152 | /// b: bool, | ||
153 | /// } | ||
154 | /// ❱ | ||
155 | /// ``` | ||
156 | /// | ||
157 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
158 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
159 | pub struct RecordFieldDefList { | ||
160 | pub(crate) syntax: SyntaxNode, | ||
161 | } | ||
162 | impl RecordFieldDefList { | ||
163 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
164 | pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } | ||
165 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
166 | } | ||
167 | /// Record field definition including its attributes and doc comments. | ||
168 | /// | ||
169 | /// ` `` | ||
170 | /// same for union | ||
171 | /// struct Foo { | ||
172 | /// ❰ | ||
173 | /// /// Docs | ||
174 | /// #[attr] | ||
175 | /// pub a: u32 | ||
176 | /// ❱ | ||
177 | /// | ||
178 | /// ❰ b: bool ❱ | ||
179 | /// } | ||
180 | /// ``` | ||
181 | /// | ||
182 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
183 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 169 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
184 | pub struct RecordFieldDef { | 170 | pub struct RecordFieldDef { |
185 | pub(crate) syntax: SyntaxNode, | 171 | pub(crate) syntax: SyntaxNode, |
186 | } | 172 | } |
187 | impl ast::VisibilityOwner for RecordFieldDef {} | ||
188 | impl ast::NameOwner for RecordFieldDef {} | ||
189 | impl ast::AttrsOwner for RecordFieldDef {} | 173 | impl ast::AttrsOwner for RecordFieldDef {} |
190 | impl ast::DocCommentsOwner for RecordFieldDef {} | 174 | impl ast::NameOwner for RecordFieldDef {} |
175 | impl ast::VisibilityOwner for RecordFieldDef {} | ||
191 | impl ast::TypeAscriptionOwner for RecordFieldDef {} | 176 | impl ast::TypeAscriptionOwner for RecordFieldDef {} |
192 | impl RecordFieldDef {} | 177 | impl RecordFieldDef { |
193 | /// Tuple field definition list including enclosing parens. | 178 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
194 | /// | ||
195 | /// ``` | ||
196 | /// struct Foo ❰ (u32, String, Vec<u32>) ❱; | ||
197 | /// ``` | ||
198 | /// | ||
199 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
200 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
201 | pub struct TupleFieldDefList { | ||
202 | pub(crate) syntax: SyntaxNode, | ||
203 | } | ||
204 | impl TupleFieldDefList { | ||
205 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
206 | pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } | ||
207 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
208 | } | 179 | } |
209 | /// Tuple field definition including its attributes. | ||
210 | /// | ||
211 | /// ``` | ||
212 | /// struct Foo(❰ #[attr] u32 ❱); | ||
213 | /// ``` | ||
214 | /// | ||
215 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
216 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 180 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
217 | pub struct TupleFieldDef { | 181 | pub struct TupleFieldDef { |
218 | pub(crate) syntax: SyntaxNode, | 182 | pub(crate) syntax: SyntaxNode, |
219 | } | 183 | } |
220 | impl ast::VisibilityOwner for TupleFieldDef {} | ||
221 | impl ast::AttrsOwner for TupleFieldDef {} | 184 | impl ast::AttrsOwner for TupleFieldDef {} |
185 | impl ast::NameOwner for TupleFieldDef {} | ||
186 | impl ast::VisibilityOwner for TupleFieldDef {} | ||
222 | impl TupleFieldDef { | 187 | impl TupleFieldDef { |
223 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 188 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
224 | } | 189 | } |
225 | /// Enum definition. | ||
226 | /// Includes all of its attributes and doc comments. | ||
227 | /// | ||
228 | /// ``` | ||
229 | /// ❰ | ||
230 | /// /// Docs | ||
231 | /// #[attr] | ||
232 | /// pub enum Foo<T> where T: Debug { | ||
233 | /// /// Docs | ||
234 | /// #[attr] | ||
235 | /// Bar, | ||
236 | /// Baz(#[attr] u32), | ||
237 | /// Bruh { | ||
238 | /// a: u32, | ||
239 | /// /// Docs | ||
240 | /// #[attr] | ||
241 | /// b: T, | ||
242 | /// } | ||
243 | /// } | ||
244 | /// ❱ | ||
245 | /// ``` | ||
246 | /// | ||
247 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
248 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 190 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
249 | pub struct EnumDef { | 191 | pub struct EnumDef { |
250 | pub(crate) syntax: SyntaxNode, | 192 | pub(crate) syntax: SyntaxNode, |
251 | } | 193 | } |
252 | impl ast::VisibilityOwner for EnumDef {} | 194 | impl ast::AttrsOwner for EnumDef {} |
253 | impl ast::NameOwner for EnumDef {} | 195 | impl ast::NameOwner for EnumDef {} |
196 | impl ast::VisibilityOwner for EnumDef {} | ||
254 | impl ast::TypeParamsOwner for EnumDef {} | 197 | impl ast::TypeParamsOwner for EnumDef {} |
255 | impl ast::AttrsOwner for EnumDef {} | ||
256 | impl ast::DocCommentsOwner for EnumDef {} | ||
257 | impl EnumDef { | 198 | impl EnumDef { |
258 | pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } | 199 | pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } |
259 | pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } | 200 | pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } |
260 | } | 201 | } |
261 | /// Enum variant definition list including enclosing curly braces. | ||
262 | /// | ||
263 | /// ``` | ||
264 | /// enum Foo | ||
265 | /// ❰ | ||
266 | /// { | ||
267 | /// Bar, | ||
268 | /// Baz(u32), | ||
269 | /// Bruh { | ||
270 | /// a: u32 | ||
271 | /// } | ||
272 | /// } | ||
273 | /// ❱ | ||
274 | /// ``` | ||
275 | /// | ||
276 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
277 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 202 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
278 | pub struct EnumVariantList { | 203 | pub struct EnumVariantList { |
279 | pub(crate) syntax: SyntaxNode, | 204 | pub(crate) syntax: SyntaxNode, |
@@ -283,56 +208,25 @@ impl EnumVariantList { | |||
283 | pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } | 208 | pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } |
284 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 209 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
285 | } | 210 | } |
286 | /// Enum variant definition including its attributes and discriminant value definition. | ||
287 | /// | ||
288 | /// ``` | ||
289 | /// enum Foo { | ||
290 | /// ❰ | ||
291 | /// /// Docs | ||
292 | /// #[attr] | ||
293 | /// Bar | ||
294 | /// ❱ | ||
295 | /// | ||
296 | /// // same for tuple and record variants | ||
297 | /// } | ||
298 | /// ``` | ||
299 | /// | ||
300 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
301 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 211 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
302 | pub struct EnumVariant { | 212 | pub struct EnumVariant { |
303 | pub(crate) syntax: SyntaxNode, | 213 | pub(crate) syntax: SyntaxNode, |
304 | } | 214 | } |
305 | impl ast::VisibilityOwner for EnumVariant {} | ||
306 | impl ast::NameOwner for EnumVariant {} | ||
307 | impl ast::DocCommentsOwner for EnumVariant {} | ||
308 | impl ast::AttrsOwner for EnumVariant {} | 215 | impl ast::AttrsOwner for EnumVariant {} |
216 | impl ast::NameOwner for EnumVariant {} | ||
217 | impl ast::VisibilityOwner for EnumVariant {} | ||
309 | impl EnumVariant { | 218 | impl EnumVariant { |
310 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } | 219 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } |
311 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 220 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
312 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 221 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
313 | } | 222 | } |
314 | /// Trait definition. | ||
315 | /// Includes all of its attributes and doc comments. | ||
316 | /// | ||
317 | /// ``` | ||
318 | /// ❰ | ||
319 | /// /// Docs | ||
320 | /// #[attr] | ||
321 | /// pub unsafe trait Foo<T>: Debug where T: Debug { | ||
322 | /// // ... | ||
323 | /// } | ||
324 | /// ❱ | ||
325 | /// ``` | ||
326 | /// | ||
327 | /// [Reference](https://doc.rust-lang.org/reference/items/traits.html) | ||
328 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 223 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
329 | pub struct TraitDef { | 224 | pub struct TraitDef { |
330 | pub(crate) syntax: SyntaxNode, | 225 | pub(crate) syntax: SyntaxNode, |
331 | } | 226 | } |
332 | impl ast::VisibilityOwner for TraitDef {} | ||
333 | impl ast::NameOwner for TraitDef {} | ||
334 | impl ast::AttrsOwner for TraitDef {} | 227 | impl ast::AttrsOwner for TraitDef {} |
335 | impl ast::DocCommentsOwner for TraitDef {} | 228 | impl ast::NameOwner for TraitDef {} |
229 | impl ast::VisibilityOwner for TraitDef {} | ||
336 | impl ast::TypeParamsOwner for TraitDef {} | 230 | impl ast::TypeParamsOwner for TraitDef {} |
337 | impl ast::TypeBoundsOwner for TraitDef {} | 231 | impl ast::TypeBoundsOwner for TraitDef {} |
338 | impl TraitDef { | 232 | impl TraitDef { |
@@ -341,62 +235,13 @@ impl TraitDef { | |||
341 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } | 235 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } |
342 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 236 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
343 | } | 237 | } |
344 | /// Module definition either with body or not. | ||
345 | /// Includes all of its inner and outer attributes, module items, doc comments. | ||
346 | /// | ||
347 | /// ``` | ||
348 | /// ❰ | ||
349 | /// /// Docs | ||
350 | /// #[attr] | ||
351 | /// pub mod foo; | ||
352 | /// ❱ | ||
353 | /// | ||
354 | /// ❰ | ||
355 | /// /// Docs | ||
356 | /// #[attr] | ||
357 | /// pub mod bar { | ||
358 | /// //! Inner docs | ||
359 | /// #![inner_attr] | ||
360 | /// } | ||
361 | /// ❱ | ||
362 | /// ``` | ||
363 | /// | ||
364 | /// [Reference](https://doc.rust-lang.org/reference/items/modules.html) | ||
365 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 238 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
366 | pub struct Module { | 239 | pub struct TypeBoundList { |
367 | pub(crate) syntax: SyntaxNode, | 240 | pub(crate) syntax: SyntaxNode, |
368 | } | 241 | } |
369 | impl ast::VisibilityOwner for Module {} | 242 | impl TypeBoundList { |
370 | impl ast::NameOwner for Module {} | 243 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } |
371 | impl ast::AttrsOwner for Module {} | ||
372 | impl ast::DocCommentsOwner for Module {} | ||
373 | impl Module { | ||
374 | pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) } | ||
375 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | ||
376 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
377 | } | 244 | } |
378 | /// Item defintion list. | ||
379 | /// This is used for both top-level items and impl block items. | ||
380 | /// | ||
381 | /// ``` | ||
382 | /// ❰ | ||
383 | /// fn foo {} | ||
384 | /// struct Bar; | ||
385 | /// enum Baz; | ||
386 | /// trait Bruh; | ||
387 | /// const BRUUH: u32 = 42; | ||
388 | /// ❱ | ||
389 | /// | ||
390 | /// impl Foo | ||
391 | /// ❰ | ||
392 | /// { | ||
393 | /// fn bar() {} | ||
394 | /// const BAZ: u32 = 42; | ||
395 | /// } | ||
396 | /// ❱ | ||
397 | /// ``` | ||
398 | /// | ||
399 | /// [Reference](https://doc.rust-lang.org/reference/items.html) | ||
400 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 245 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
401 | pub struct ItemList { | 246 | pub struct ItemList { |
402 | pub(crate) syntax: SyntaxNode, | 247 | pub(crate) syntax: SyntaxNode, |
@@ -407,91 +252,58 @@ impl ItemList { | |||
407 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } | 252 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } |
408 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 253 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
409 | } | 254 | } |
410 | /// Constant variable definition. | 255 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
411 | /// Includes all of its attributes and doc comments. | 256 | pub struct Module { |
412 | /// | 257 | pub(crate) syntax: SyntaxNode, |
413 | /// ``` | 258 | } |
414 | /// ❰ | 259 | impl ast::AttrsOwner for Module {} |
415 | /// /// Docs | 260 | impl ast::NameOwner for Module {} |
416 | /// #[attr] | 261 | impl ast::VisibilityOwner for Module {} |
417 | /// pub const FOO: u32 = 42; | 262 | impl Module { |
418 | /// ❱ | 263 | pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) } |
419 | /// ``` | 264 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
420 | /// | 265 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
421 | /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) | 266 | } |
422 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 267 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
423 | pub struct ConstDef { | 268 | pub struct ConstDef { |
424 | pub(crate) syntax: SyntaxNode, | 269 | pub(crate) syntax: SyntaxNode, |
425 | } | 270 | } |
426 | impl ast::VisibilityOwner for ConstDef {} | ||
427 | impl ast::NameOwner for ConstDef {} | ||
428 | impl ast::TypeParamsOwner for ConstDef {} | ||
429 | impl ast::AttrsOwner for ConstDef {} | 271 | impl ast::AttrsOwner for ConstDef {} |
430 | impl ast::DocCommentsOwner for ConstDef {} | 272 | impl ast::NameOwner for ConstDef {} |
273 | impl ast::VisibilityOwner for ConstDef {} | ||
431 | impl ast::TypeAscriptionOwner for ConstDef {} | 274 | impl ast::TypeAscriptionOwner for ConstDef {} |
432 | impl ConstDef { | 275 | impl ConstDef { |
433 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | 276 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } |
434 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 277 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
278 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
435 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 279 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
436 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 280 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
437 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 281 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
438 | } | 282 | } |
439 | /// Static variable definition. | ||
440 | /// Includes all of its attributes and doc comments. | ||
441 | /// | ||
442 | /// ``` | ||
443 | /// ❰ | ||
444 | /// /// Docs | ||
445 | /// #[attr] | ||
446 | /// pub static mut FOO: u32 = 42; | ||
447 | /// ❱ | ||
448 | /// ``` | ||
449 | /// | ||
450 | /// [Reference](https://doc.rust-lang.org/reference/items/static-items.html) | ||
451 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 283 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
452 | pub struct StaticDef { | 284 | pub struct StaticDef { |
453 | pub(crate) syntax: SyntaxNode, | 285 | pub(crate) syntax: SyntaxNode, |
454 | } | 286 | } |
455 | impl ast::VisibilityOwner for StaticDef {} | ||
456 | impl ast::NameOwner for StaticDef {} | ||
457 | impl ast::TypeParamsOwner for StaticDef {} | ||
458 | impl ast::AttrsOwner for StaticDef {} | 287 | impl ast::AttrsOwner for StaticDef {} |
459 | impl ast::DocCommentsOwner for StaticDef {} | 288 | impl ast::NameOwner for StaticDef {} |
289 | impl ast::VisibilityOwner for StaticDef {} | ||
460 | impl ast::TypeAscriptionOwner for StaticDef {} | 290 | impl ast::TypeAscriptionOwner for StaticDef {} |
461 | impl StaticDef { | 291 | impl StaticDef { |
462 | pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } | 292 | pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } |
463 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 293 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
294 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
464 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 295 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
465 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 296 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
466 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 297 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
467 | } | 298 | } |
468 | /// Type alias definition. | ||
469 | /// Includes associated type clauses with type bounds. | ||
470 | /// | ||
471 | /// ``` | ||
472 | /// ❰ | ||
473 | /// /// Docs | ||
474 | /// #[attr] | ||
475 | /// pub type Foo<T> where T: Debug = T; | ||
476 | /// ❱ | ||
477 | /// | ||
478 | /// trait Bar { | ||
479 | /// ❰ type Baz: Debug; ❱ | ||
480 | /// ❰ type Bruh = String; ❱ | ||
481 | /// ❰ type Bruuh: Debug = u32; ❱ | ||
482 | /// } | ||
483 | /// ``` | ||
484 | /// | ||
485 | /// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html) | ||
486 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 299 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
487 | pub struct TypeAliasDef { | 300 | pub struct TypeAliasDef { |
488 | pub(crate) syntax: SyntaxNode, | 301 | pub(crate) syntax: SyntaxNode, |
489 | } | 302 | } |
490 | impl ast::VisibilityOwner for TypeAliasDef {} | 303 | impl ast::AttrsOwner for TypeAliasDef {} |
491 | impl ast::NameOwner for TypeAliasDef {} | 304 | impl ast::NameOwner for TypeAliasDef {} |
305 | impl ast::VisibilityOwner for TypeAliasDef {} | ||
492 | impl ast::TypeParamsOwner for TypeAliasDef {} | 306 | impl ast::TypeParamsOwner for TypeAliasDef {} |
493 | impl ast::AttrsOwner for TypeAliasDef {} | ||
494 | impl ast::DocCommentsOwner for TypeAliasDef {} | ||
495 | impl ast::TypeBoundsOwner for TypeAliasDef {} | 307 | impl ast::TypeBoundsOwner for TypeAliasDef {} |
496 | impl TypeAliasDef { | 308 | impl TypeAliasDef { |
497 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | 309 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } |
@@ -500,46 +312,22 @@ impl TypeAliasDef { | |||
500 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 312 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
501 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 313 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
502 | } | 314 | } |
503 | /// Inherent and trait impl definition. | ||
504 | /// Includes all of its inner and outer attributes. | ||
505 | /// | ||
506 | /// ``` | ||
507 | /// ❰ | ||
508 | /// #[attr] | ||
509 | /// unsafe impl<T> const !Foo for Bar where T: Debug { | ||
510 | /// #![inner_attr] | ||
511 | /// // ... | ||
512 | /// } | ||
513 | /// ❱ | ||
514 | /// ``` | ||
515 | /// | ||
516 | /// [Reference](https://doc.rust-lang.org/reference/items/implementations.html) | ||
517 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 315 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
518 | pub struct ImplDef { | 316 | pub struct ImplDef { |
519 | pub(crate) syntax: SyntaxNode, | 317 | pub(crate) syntax: SyntaxNode, |
520 | } | 318 | } |
521 | impl ast::TypeParamsOwner for ImplDef {} | ||
522 | impl ast::AttrsOwner for ImplDef {} | 319 | impl ast::AttrsOwner for ImplDef {} |
523 | impl ast::DocCommentsOwner for ImplDef {} | 320 | impl ast::VisibilityOwner for ImplDef {} |
321 | impl ast::TypeParamsOwner for ImplDef {} | ||
524 | impl ImplDef { | 322 | impl ImplDef { |
525 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
526 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 323 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
324 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
527 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | 325 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } |
528 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | 326 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } |
529 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | 327 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } |
530 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | 328 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } |
531 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 329 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
532 | } | 330 | } |
533 | /// Parenthesized type reference. | ||
534 | /// Note: parens are only used for grouping, this is not a tuple type. | ||
535 | /// | ||
536 | /// ``` | ||
537 | /// // This is effectively just `u32`. | ||
538 | /// // Single-item tuple must be defined with a trailing comma: `(u32,)` | ||
539 | /// type Foo = ❰ (u32) ❱; | ||
540 | /// | ||
541 | /// let bar: &'static ❰ (dyn Debug) ❱ = "bruh"; | ||
542 | /// ``` | ||
543 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 331 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
544 | pub struct ParenType { | 332 | pub struct ParenType { |
545 | pub(crate) syntax: SyntaxNode, | 333 | pub(crate) syntax: SyntaxNode, |
@@ -549,13 +337,6 @@ impl ParenType { | |||
549 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 337 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
550 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 338 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
551 | } | 339 | } |
552 | /// Unnamed tuple type. | ||
553 | /// | ||
554 | /// ``` | ||
555 | /// let foo: ❰ (u32, bool) ❱ = (42, true); | ||
556 | /// ``` | ||
557 | /// | ||
558 | /// [Reference](https://doc.rust-lang.org/reference/types/tuple.html) | ||
559 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 340 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
560 | pub struct TupleType { | 341 | pub struct TupleType { |
561 | pub(crate) syntax: SyntaxNode, | 342 | pub(crate) syntax: SyntaxNode, |
@@ -565,17 +346,6 @@ impl TupleType { | |||
565 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } | 346 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } |
566 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 347 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
567 | } | 348 | } |
568 | /// The never type (i.e. the exclamation point). | ||
569 | /// | ||
570 | /// ``` | ||
571 | /// type T = ❰ ! ❱; | ||
572 | /// | ||
573 | /// fn no_return() -> ❰ ! ❱ { | ||
574 | /// loop {} | ||
575 | /// } | ||
576 | /// ``` | ||
577 | /// | ||
578 | /// [Reference](https://doc.rust-lang.org/reference/types/never.html) | ||
579 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 349 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
580 | pub struct NeverType { | 350 | pub struct NeverType { |
581 | pub(crate) syntax: SyntaxNode, | 351 | pub(crate) syntax: SyntaxNode, |
@@ -583,17 +353,6 @@ pub struct NeverType { | |||
583 | impl NeverType { | 353 | impl NeverType { |
584 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | 354 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } |
585 | } | 355 | } |
586 | /// Path to a type. | ||
587 | /// Includes single identifier type names and elaborate paths with | ||
588 | /// generic parameters. | ||
589 | /// | ||
590 | /// ``` | ||
591 | /// type Foo = ❰ String ❱; | ||
592 | /// type Bar = ❰ std::vec::Vec<T> ❱; | ||
593 | /// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱; | ||
594 | /// ``` | ||
595 | /// | ||
596 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
597 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 356 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
598 | pub struct PathType { | 357 | pub struct PathType { |
599 | pub(crate) syntax: SyntaxNode, | 358 | pub(crate) syntax: SyntaxNode, |
@@ -601,14 +360,15 @@ pub struct PathType { | |||
601 | impl PathType { | 360 | impl PathType { |
602 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 361 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
603 | } | 362 | } |
604 | /// Raw pointer type. | 363 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
605 | /// | 364 | pub struct Path { |
606 | /// ``` | 365 | pub(crate) syntax: SyntaxNode, |
607 | /// type Foo = ❰ *const u32 ❱; | 366 | } |
608 | /// type Bar = ❰ *mut u32 ❱; | 367 | impl Path { |
609 | /// ``` | 368 | pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } |
610 | /// | 369 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } |
611 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut) | 370 | pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } |
371 | } | ||
612 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 372 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
613 | pub struct PointerType { | 373 | pub struct PointerType { |
614 | pub(crate) syntax: SyntaxNode, | 374 | pub(crate) syntax: SyntaxNode, |
@@ -619,13 +379,6 @@ impl PointerType { | |||
619 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 379 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
620 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 380 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
621 | } | 381 | } |
622 | /// Array type. | ||
623 | /// | ||
624 | /// ``` | ||
625 | /// type Foo = ❰ [u32; 24 - 3] ❱; | ||
626 | /// ``` | ||
627 | /// | ||
628 | /// [Reference](https://doc.rust-lang.org/reference/types/array.html) | ||
629 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 382 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
630 | pub struct ArrayType { | 383 | pub struct ArrayType { |
631 | pub(crate) syntax: SyntaxNode, | 384 | pub(crate) syntax: SyntaxNode, |
@@ -637,13 +390,6 @@ impl ArrayType { | |||
637 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 390 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
638 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 391 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
639 | } | 392 | } |
640 | /// Slice type. | ||
641 | /// | ||
642 | /// ``` | ||
643 | /// type Foo = ❰ [u8] ❱; | ||
644 | /// ``` | ||
645 | /// | ||
646 | /// [Reference](https://doc.rust-lang.org/reference/types/slice.html) | ||
647 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 393 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
648 | pub struct SliceType { | 394 | pub struct SliceType { |
649 | pub(crate) syntax: SyntaxNode, | 395 | pub(crate) syntax: SyntaxNode, |
@@ -653,13 +399,6 @@ impl SliceType { | |||
653 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 399 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
654 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 400 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
655 | } | 401 | } |
656 | /// Reference type. | ||
657 | /// | ||
658 | /// ``` | ||
659 | /// type Foo = ❰ &'static str ❱; | ||
660 | /// ``` | ||
661 | /// | ||
662 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html) | ||
663 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 402 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
664 | pub struct ReferenceType { | 403 | pub struct ReferenceType { |
665 | pub(crate) syntax: SyntaxNode, | 404 | pub(crate) syntax: SyntaxNode, |
@@ -672,13 +411,6 @@ impl ReferenceType { | |||
672 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 411 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
673 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 412 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
674 | } | 413 | } |
675 | /// Placeholder type (i.e. the underscore). | ||
676 | /// | ||
677 | /// ``` | ||
678 | /// let foo: ❰ _ ❱ = 42_u32; | ||
679 | /// ``` | ||
680 | /// | ||
681 | /// [Reference](https://doc.rust-lang.org/reference/types/inferred.html) | ||
682 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 414 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
683 | pub struct PlaceholderType { | 415 | pub struct PlaceholderType { |
684 | pub(crate) syntax: SyntaxNode, | 416 | pub(crate) syntax: SyntaxNode, |
@@ -686,15 +418,6 @@ pub struct PlaceholderType { | |||
686 | impl PlaceholderType { | 418 | impl PlaceholderType { |
687 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | 419 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
688 | } | 420 | } |
689 | /// Function pointer type (not to be confused with `Fn*` family of traits). | ||
690 | /// | ||
691 | /// ``` | ||
692 | /// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱; | ||
693 | /// | ||
694 | /// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱; | ||
695 | /// ``` | ||
696 | /// | ||
697 | /// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html) | ||
698 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 421 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
699 | pub struct FnPointerType { | 422 | pub struct FnPointerType { |
700 | pub(crate) syntax: SyntaxNode, | 423 | pub(crate) syntax: SyntaxNode, |
@@ -706,13 +429,6 @@ impl FnPointerType { | |||
706 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | 429 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } |
707 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 430 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
708 | } | 431 | } |
709 | /// Higher order type. | ||
710 | /// | ||
711 | /// ``` | ||
712 | /// type Foo = ❰ for<'a> fn(&'a str) ❱; | ||
713 | /// ``` | ||
714 | /// | ||
715 | /// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html) | ||
716 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 432 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
717 | pub struct ForType { | 433 | pub struct ForType { |
718 | pub(crate) syntax: SyntaxNode, | 434 | pub(crate) syntax: SyntaxNode, |
@@ -722,43 +438,22 @@ impl ForType { | |||
722 | pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } | 438 | pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } |
723 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 439 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
724 | } | 440 | } |
725 | /// Opaque `impl Trait` type. | ||
726 | /// | ||
727 | /// ``` | ||
728 | /// fn foo(bar: ❰ impl Debug + Eq ❱) {} | ||
729 | /// ``` | ||
730 | /// | ||
731 | /// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html) | ||
732 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 441 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
733 | pub struct ImplTraitType { | 442 | pub struct ImplTraitType { |
734 | pub(crate) syntax: SyntaxNode, | 443 | pub(crate) syntax: SyntaxNode, |
735 | } | 444 | } |
736 | impl ast::TypeBoundsOwner for ImplTraitType {} | ||
737 | impl ImplTraitType { | 445 | impl ImplTraitType { |
738 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | 446 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } |
447 | pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) } | ||
739 | } | 448 | } |
740 | /// Trait object type. | ||
741 | /// | ||
742 | /// ``` | ||
743 | /// type Foo = ❰ dyn Debug ❱; | ||
744 | /// ``` | ||
745 | /// | ||
746 | /// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html) | ||
747 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 449 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
748 | pub struct DynTraitType { | 450 | pub struct DynTraitType { |
749 | pub(crate) syntax: SyntaxNode, | 451 | pub(crate) syntax: SyntaxNode, |
750 | } | 452 | } |
751 | impl ast::TypeBoundsOwner for DynTraitType {} | ||
752 | impl DynTraitType { | 453 | impl DynTraitType { |
753 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } | 454 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } |
455 | pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) } | ||
754 | } | 456 | } |
755 | /// Tuple literal. | ||
756 | /// | ||
757 | /// ``` | ||
758 | /// ❰ (42, true) ❱; | ||
759 | /// ``` | ||
760 | /// | ||
761 | /// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html) | ||
762 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 457 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
763 | pub struct TupleExpr { | 458 | pub struct TupleExpr { |
764 | pub(crate) syntax: SyntaxNode, | 459 | pub(crate) syntax: SyntaxNode, |
@@ -769,15 +464,6 @@ impl TupleExpr { | |||
769 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | 464 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
770 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 465 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
771 | } | 466 | } |
772 | /// Array literal. | ||
773 | /// | ||
774 | /// ``` | ||
775 | /// ❰ [#![inner_attr] true, false, true] ❱; | ||
776 | /// | ||
777 | /// ❰ ["baz"; 24] ❱; | ||
778 | /// ``` | ||
779 | /// | ||
780 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
781 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 467 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
782 | pub struct ArrayExpr { | 468 | pub struct ArrayExpr { |
783 | pub(crate) syntax: SyntaxNode, | 469 | pub(crate) syntax: SyntaxNode, |
@@ -786,17 +472,10 @@ impl ast::AttrsOwner for ArrayExpr {} | |||
786 | impl ArrayExpr { | 472 | impl ArrayExpr { |
787 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 473 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
788 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | 474 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
475 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
789 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 476 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
790 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 477 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
791 | } | 478 | } |
792 | /// Parenthesized expression. | ||
793 | /// Note: parens are only used for grouping, this is not a tuple literal. | ||
794 | /// | ||
795 | /// ``` | ||
796 | /// ❰ (#![inner_attr] 2 + 2) ❱ * 2; | ||
797 | /// ``` | ||
798 | /// | ||
799 | /// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html) | ||
800 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 479 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
801 | pub struct ParenExpr { | 480 | pub struct ParenExpr { |
802 | pub(crate) syntax: SyntaxNode, | 481 | pub(crate) syntax: SyntaxNode, |
@@ -807,19 +486,6 @@ impl ParenExpr { | |||
807 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 486 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
808 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 487 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
809 | } | 488 | } |
810 | /// Path to a symbol in expression context. | ||
811 | /// Includes single identifier variable names and elaborate paths with | ||
812 | /// generic parameters. | ||
813 | /// | ||
814 | /// ``` | ||
815 | /// ❰ Some::<i32> ❱; | ||
816 | /// ❰ foo ❱ + 42; | ||
817 | /// ❰ Vec::<i32>::push ❱; | ||
818 | /// ❰ <[i32]>::reverse ❱; | ||
819 | /// ❰ <String as std::borrow::Borrow<str>>::borrow ❱; | ||
820 | /// ``` | ||
821 | /// | ||
822 | /// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html) | ||
823 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 489 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
824 | pub struct PathExpr { | 490 | pub struct PathExpr { |
825 | pub(crate) syntax: SyntaxNode, | 491 | pub(crate) syntax: SyntaxNode, |
@@ -827,17 +493,6 @@ pub struct PathExpr { | |||
827 | impl PathExpr { | 493 | impl PathExpr { |
828 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 494 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
829 | } | 495 | } |
830 | /// Anonymous callable object literal a.k.a. closure, lambda or functor. | ||
831 | /// | ||
832 | /// ``` | ||
833 | /// ❰ || 42 ❱; | ||
834 | /// ❰ |a: u32| val + 1 ❱; | ||
835 | /// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱; | ||
836 | /// ❰ move || baz ❱; | ||
837 | /// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱ | ||
838 | /// ``` | ||
839 | /// | ||
840 | /// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html) | ||
841 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 496 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
842 | pub struct LambdaExpr { | 497 | pub struct LambdaExpr { |
843 | pub(crate) syntax: SyntaxNode, | 498 | pub(crate) syntax: SyntaxNode, |
@@ -851,25 +506,6 @@ impl LambdaExpr { | |||
851 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 506 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
852 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 507 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
853 | } | 508 | } |
854 | /// If expression. Includes both regular `if` and `if let` forms. | ||
855 | /// Beware that `else if` is a special case syntax sugar, because in general | ||
856 | /// there has to be block expression after `else`. | ||
857 | /// | ||
858 | /// ``` | ||
859 | /// ❰ if bool_cond { 42 } ❱ | ||
860 | /// ❰ if bool_cond { 42 } else { 24 } ❱ | ||
861 | /// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱ | ||
862 | /// | ||
863 | /// ❰ | ||
864 | /// if let Pattern(foo) = bar { | ||
865 | /// foo | ||
866 | /// } else { | ||
867 | /// panic!(); | ||
868 | /// } | ||
869 | /// ❱ | ||
870 | /// ``` | ||
871 | /// | ||
872 | /// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
873 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 509 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
874 | pub struct IfExpr { | 510 | pub struct IfExpr { |
875 | pub(crate) syntax: SyntaxNode, | 511 | pub(crate) syntax: SyntaxNode, |
@@ -879,40 +515,16 @@ impl IfExpr { | |||
879 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | 515 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } |
880 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | 516 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } |
881 | } | 517 | } |
882 | /// Unconditional loop expression. | ||
883 | /// | ||
884 | /// ``` | ||
885 | /// ❰ | ||
886 | /// loop { | ||
887 | /// // yeah, it's that simple... | ||
888 | /// } | ||
889 | /// ❱ | ||
890 | /// ``` | ||
891 | /// | ||
892 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html) | ||
893 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 518 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
894 | pub struct LoopExpr { | 519 | pub struct Condition { |
895 | pub(crate) syntax: SyntaxNode, | 520 | pub(crate) syntax: SyntaxNode, |
896 | } | 521 | } |
897 | impl ast::AttrsOwner for LoopExpr {} | 522 | impl Condition { |
898 | impl ast::LoopBodyOwner for LoopExpr {} | 523 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } |
899 | impl LoopExpr { | 524 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
900 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } | 525 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
526 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
901 | } | 527 | } |
902 | /// Block expression with an optional prefix (label, try ketword, | ||
903 | /// unsafe keyword, async keyword...). | ||
904 | /// | ||
905 | /// ``` | ||
906 | /// ❰ | ||
907 | /// 'label: try { | ||
908 | /// None? | ||
909 | /// } | ||
910 | /// ❱ | ||
911 | /// ``` | ||
912 | /// | ||
913 | /// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html) | ||
914 | /// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks) | ||
915 | /// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks) | ||
916 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 528 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
917 | pub struct EffectExpr { | 529 | pub struct EffectExpr { |
918 | pub(crate) syntax: SyntaxNode, | 530 | pub(crate) syntax: SyntaxNode, |
@@ -925,19 +537,24 @@ impl EffectExpr { | |||
925 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | 537 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } |
926 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 538 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
927 | } | 539 | } |
928 | /// For loop expression. | 540 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
929 | /// Note: record struct literals are not valid as iterable expression | 541 | pub struct Label { |
930 | /// due to ambiguity. | 542 | pub(crate) syntax: SyntaxNode, |
931 | /// | 543 | } |
932 | /// ``` | 544 | impl Label { |
933 | /// ❰ | 545 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { |
934 | /// for i in (0..4) { | 546 | support::token(&self.syntax, T![lifetime]) |
935 | /// dbg!(i); | 547 | } |
936 | /// } | 548 | } |
937 | /// ❱ | 549 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
938 | /// ``` | 550 | pub struct LoopExpr { |
939 | /// | 551 | pub(crate) syntax: SyntaxNode, |
940 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops) | 552 | } |
553 | impl ast::AttrsOwner for LoopExpr {} | ||
554 | impl ast::LoopBodyOwner for LoopExpr {} | ||
555 | impl LoopExpr { | ||
556 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } | ||
557 | } | ||
941 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 558 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
942 | pub struct ForExpr { | 559 | pub struct ForExpr { |
943 | pub(crate) syntax: SyntaxNode, | 560 | pub(crate) syntax: SyntaxNode, |
@@ -950,22 +567,6 @@ impl ForExpr { | |||
950 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } | 567 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } |
951 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } | 568 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } |
952 | } | 569 | } |
953 | /// While loop expression. Includes both regular `while` and `while let` forms. | ||
954 | /// | ||
955 | /// ``` | ||
956 | /// ❰ | ||
957 | /// while bool_cond { | ||
958 | /// 42; | ||
959 | /// } | ||
960 | /// ❱ | ||
961 | /// ❰ | ||
962 | /// while let Pattern(foo) = bar { | ||
963 | /// bar += 1; | ||
964 | /// } | ||
965 | /// ❱ | ||
966 | /// ``` | ||
967 | /// | ||
968 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
969 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 570 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
970 | pub struct WhileExpr { | 571 | pub struct WhileExpr { |
971 | pub(crate) syntax: SyntaxNode, | 572 | pub(crate) syntax: SyntaxNode, |
@@ -976,22 +577,6 @@ impl WhileExpr { | |||
976 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } | 577 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } |
977 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | 578 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } |
978 | } | 579 | } |
979 | /// Continue expression. | ||
980 | /// | ||
981 | /// ``` | ||
982 | /// while bool_cond { | ||
983 | /// ❰ continue ❱; | ||
984 | /// } | ||
985 | /// | ||
986 | /// 'outer: loop { | ||
987 | /// loop { | ||
988 | /// ❰ continue 'outer ❱; | ||
989 | /// } | ||
990 | /// } | ||
991 | /// | ||
992 | /// ``` | ||
993 | /// | ||
994 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions) | ||
995 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 580 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
996 | pub struct ContinueExpr { | 581 | pub struct ContinueExpr { |
997 | pub(crate) syntax: SyntaxNode, | 582 | pub(crate) syntax: SyntaxNode, |
@@ -1005,25 +590,6 @@ impl ContinueExpr { | |||
1005 | support::token(&self.syntax, T![lifetime]) | 590 | support::token(&self.syntax, T![lifetime]) |
1006 | } | 591 | } |
1007 | } | 592 | } |
1008 | /// Break expression. | ||
1009 | /// | ||
1010 | /// ``` | ||
1011 | /// while bool_cond { | ||
1012 | /// ❰ break ❱; | ||
1013 | /// } | ||
1014 | /// 'outer: loop { | ||
1015 | /// for foo in bar { | ||
1016 | /// ❰ break 'outer ❱; | ||
1017 | /// } | ||
1018 | /// } | ||
1019 | /// 'outer: loop { | ||
1020 | /// loop { | ||
1021 | /// ❰ break 'outer 42 ❱; | ||
1022 | /// } | ||
1023 | /// } | ||
1024 | /// ``` | ||
1025 | /// | ||
1026 | /// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions) | ||
1027 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 593 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1028 | pub struct BreakExpr { | 594 | pub struct BreakExpr { |
1029 | pub(crate) syntax: SyntaxNode, | 595 | pub(crate) syntax: SyntaxNode, |
@@ -1036,104 +602,33 @@ impl BreakExpr { | |||
1036 | } | 602 | } |
1037 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 603 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1038 | } | 604 | } |
1039 | /// Label. | ||
1040 | /// | ||
1041 | /// ``` | ||
1042 | /// ❰ 'outer: ❱ loop {} | ||
1043 | /// | ||
1044 | /// let foo = ❰ 'bar: ❱ loop {} | ||
1045 | /// | ||
1046 | /// ❰ 'baz: ❱ { | ||
1047 | /// break 'baz; | ||
1048 | /// } | ||
1049 | /// ``` | ||
1050 | /// | ||
1051 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels) | ||
1052 | /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) | ||
1053 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1054 | pub struct Label { | ||
1055 | pub(crate) syntax: SyntaxNode, | ||
1056 | } | ||
1057 | impl Label { | ||
1058 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
1059 | support::token(&self.syntax, T![lifetime]) | ||
1060 | } | ||
1061 | } | ||
1062 | /// Block expression. Includes unsafe blocks and block labels. | ||
1063 | /// | ||
1064 | /// ``` | ||
1065 | /// let foo = ❰ | ||
1066 | /// { | ||
1067 | /// #![inner_attr] | ||
1068 | /// ❰ { } ❱ | ||
1069 | /// | ||
1070 | /// ❰ 'label: { break 'label } ❱ | ||
1071 | /// } | ||
1072 | /// ❱; | ||
1073 | /// ``` | ||
1074 | /// | ||
1075 | /// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html) | ||
1076 | /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) | ||
1077 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1078 | pub struct BlockExpr { | ||
1079 | pub(crate) syntax: SyntaxNode, | ||
1080 | } | ||
1081 | impl ast::AttrsOwner for BlockExpr {} | ||
1082 | impl ast::ModuleItemOwner for BlockExpr {} | ||
1083 | impl BlockExpr { | ||
1084 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } | ||
1085 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
1086 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } | ||
1087 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
1088 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
1089 | } | ||
1090 | /// Return expression. | ||
1091 | /// | ||
1092 | /// ``` | ||
1093 | /// || ❰ return 42 ❱; | ||
1094 | /// | ||
1095 | /// fn bar() { | ||
1096 | /// ❰ return ❱; | ||
1097 | /// } | ||
1098 | /// ``` | ||
1099 | /// | ||
1100 | /// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html) | ||
1101 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 605 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1102 | pub struct ReturnExpr { | 606 | pub struct ReturnExpr { |
1103 | pub(crate) syntax: SyntaxNode, | 607 | pub(crate) syntax: SyntaxNode, |
1104 | } | 608 | } |
1105 | impl ast::AttrsOwner for ReturnExpr {} | 609 | impl ast::AttrsOwner for ReturnExpr {} |
1106 | impl ReturnExpr { | 610 | impl ReturnExpr { |
611 | pub fn return_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![return]) } | ||
1107 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 612 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1108 | } | 613 | } |
1109 | /// Call expression (not to be confused with method call expression, it is | ||
1110 | /// a separate ast node). | ||
1111 | /// | ||
1112 | /// ``` | ||
1113 | /// ❰ foo() ❱; | ||
1114 | /// ❰ &str::len("bar") ❱; | ||
1115 | /// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱; | ||
1116 | /// ``` | ||
1117 | /// | ||
1118 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
1119 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 614 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1120 | pub struct CallExpr { | 615 | pub struct CallExpr { |
1121 | pub(crate) syntax: SyntaxNode, | 616 | pub(crate) syntax: SyntaxNode, |
1122 | } | 617 | } |
618 | impl ast::AttrsOwner for CallExpr {} | ||
1123 | impl ast::ArgListOwner for CallExpr {} | 619 | impl ast::ArgListOwner for CallExpr {} |
1124 | impl CallExpr { | 620 | impl CallExpr { |
1125 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 621 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1126 | } | 622 | } |
1127 | /// Method call expression. | 623 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1128 | /// | 624 | pub struct ArgList { |
1129 | /// ``` | 625 | pub(crate) syntax: SyntaxNode, |
1130 | /// ❰ receiver_expr.method() ❱; | 626 | } |
1131 | /// ❰ receiver_expr.method::<T>(42, true) ❱; | 627 | impl ArgList { |
1132 | /// | 628 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } |
1133 | /// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱; | 629 | pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
1134 | /// ``` | 630 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1135 | /// | 631 | } |
1136 | /// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html) | ||
1137 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 632 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1138 | pub struct MethodCallExpr { | 633 | pub struct MethodCallExpr { |
1139 | pub(crate) syntax: SyntaxNode, | 634 | pub(crate) syntax: SyntaxNode, |
@@ -1146,31 +641,26 @@ impl MethodCallExpr { | |||
1146 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 641 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1147 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } | 642 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } |
1148 | } | 643 | } |
1149 | /// Index expression a.k.a. subscript operator call. | ||
1150 | /// | ||
1151 | /// ``` | ||
1152 | /// ❰ foo[42] ❱; | ||
1153 | /// ``` | ||
1154 | /// | ||
1155 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
1156 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 644 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1157 | pub struct IndexExpr { | 645 | pub struct NameRef { |
1158 | pub(crate) syntax: SyntaxNode, | 646 | pub(crate) syntax: SyntaxNode, |
1159 | } | 647 | } |
1160 | impl ast::AttrsOwner for IndexExpr {} | 648 | impl NameRef { |
1161 | impl IndexExpr { | 649 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } |
1162 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 650 | } |
1163 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 651 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
652 | pub struct TypeArgList { | ||
653 | pub(crate) syntax: SyntaxNode, | ||
654 | } | ||
655 | impl TypeArgList { | ||
656 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
657 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | ||
658 | pub fn type_args(&self) -> AstChildren<TypeArg> { support::children(&self.syntax) } | ||
659 | pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { support::children(&self.syntax) } | ||
660 | pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { support::children(&self.syntax) } | ||
661 | pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } | ||
662 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | ||
1164 | } | 663 | } |
1165 | /// Field access expression. | ||
1166 | /// | ||
1167 | /// ``` | ||
1168 | /// ❰ expr.bar ❱; | ||
1169 | /// | ||
1170 | /// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱; | ||
1171 | /// ``` | ||
1172 | /// | ||
1173 | /// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html) | ||
1174 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 664 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1175 | pub struct FieldExpr { | 665 | pub struct FieldExpr { |
1176 | pub(crate) syntax: SyntaxNode, | 666 | pub(crate) syntax: SyntaxNode, |
@@ -1181,13 +671,15 @@ impl FieldExpr { | |||
1181 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | 671 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } |
1182 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 672 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1183 | } | 673 | } |
1184 | /// Await operator call expression. | 674 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1185 | /// | 675 | pub struct IndexExpr { |
1186 | /// ``` | 676 | pub(crate) syntax: SyntaxNode, |
1187 | /// ❰ expr.await ❱; | 677 | } |
1188 | /// ``` | 678 | impl ast::AttrsOwner for IndexExpr {} |
1189 | /// | 679 | impl IndexExpr { |
1190 | /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html) | 680 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
681 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
682 | } | ||
1191 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 683 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1192 | pub struct AwaitExpr { | 684 | pub struct AwaitExpr { |
1193 | pub(crate) syntax: SyntaxNode, | 685 | pub(crate) syntax: SyntaxNode, |
@@ -1198,13 +690,6 @@ impl AwaitExpr { | |||
1198 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | 690 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } |
1199 | pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } | 691 | pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } |
1200 | } | 692 | } |
1201 | /// The question mark operator call. | ||
1202 | /// | ||
1203 | /// ``` | ||
1204 | /// ❰ expr? ❱; | ||
1205 | /// ``` | ||
1206 | /// | ||
1207 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator) | ||
1208 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 693 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1209 | pub struct TryExpr { | 694 | pub struct TryExpr { |
1210 | pub(crate) syntax: SyntaxNode, | 695 | pub(crate) syntax: SyntaxNode, |
@@ -1214,13 +699,6 @@ impl TryExpr { | |||
1214 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 699 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1215 | pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } | 700 | pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } |
1216 | } | 701 | } |
1217 | /// Type cast expression. | ||
1218 | /// | ||
1219 | /// ``` | ||
1220 | /// ❰ expr as T ❱; | ||
1221 | /// ``` | ||
1222 | /// | ||
1223 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions) | ||
1224 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 702 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1225 | pub struct CastExpr { | 703 | pub struct CastExpr { |
1226 | pub(crate) syntax: SyntaxNode, | 704 | pub(crate) syntax: SyntaxNode, |
@@ -1231,16 +709,6 @@ impl CastExpr { | |||
1231 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | 709 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } |
1232 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 710 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1233 | } | 711 | } |
1234 | /// Borrow operator call. | ||
1235 | /// | ||
1236 | /// ``` | ||
1237 | /// ❰ &foo ❱; | ||
1238 | /// ❰ &mut bar ❱; | ||
1239 | /// ❰ &raw const bar ❱; | ||
1240 | /// ❰ &raw mut bar ❱; | ||
1241 | /// ``` | ||
1242 | /// | ||
1243 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators) | ||
1244 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 712 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1245 | pub struct RefExpr { | 713 | pub struct RefExpr { |
1246 | pub(crate) syntax: SyntaxNode, | 714 | pub(crate) syntax: SyntaxNode, |
@@ -1253,15 +721,6 @@ impl RefExpr { | |||
1253 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 721 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
1254 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 722 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1255 | } | 723 | } |
1256 | /// Prefix operator call. This is either `!` or `*` or `-`. | ||
1257 | /// | ||
1258 | /// ``` | ||
1259 | /// ❰ !foo ❱; | ||
1260 | /// ❰ *bar ❱; | ||
1261 | /// ❰ -42 ❱; | ||
1262 | /// ``` | ||
1263 | /// | ||
1264 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html) | ||
1265 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 724 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1266 | pub struct PrefixExpr { | 725 | pub struct PrefixExpr { |
1267 | pub(crate) syntax: SyntaxNode, | 726 | pub(crate) syntax: SyntaxNode, |
@@ -1270,13 +729,6 @@ impl ast::AttrsOwner for PrefixExpr {} | |||
1270 | impl PrefixExpr { | 729 | impl PrefixExpr { |
1271 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 730 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1272 | } | 731 | } |
1273 | /// Box operator call. | ||
1274 | /// | ||
1275 | /// ``` | ||
1276 | /// ❰ box 42 ❱; | ||
1277 | /// ``` | ||
1278 | /// | ||
1279 | /// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md) | ||
1280 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 732 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1281 | pub struct BoxExpr { | 733 | pub struct BoxExpr { |
1282 | pub(crate) syntax: SyntaxNode, | 734 | pub(crate) syntax: SyntaxNode, |
@@ -1286,69 +738,23 @@ impl BoxExpr { | |||
1286 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | 738 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } |
1287 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 739 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1288 | } | 740 | } |
1289 | /// Range operator call. | ||
1290 | /// | ||
1291 | /// ``` | ||
1292 | /// ❰ 0..42 ❱; | ||
1293 | /// ❰ ..42 ❱; | ||
1294 | /// ❰ 0.. ❱; | ||
1295 | /// ❰ .. ❱; | ||
1296 | /// ❰ 0..=42 ❱; | ||
1297 | /// ❰ ..=42 ❱; | ||
1298 | /// ``` | ||
1299 | /// | ||
1300 | /// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html) | ||
1301 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 741 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1302 | pub struct RangeExpr { | 742 | pub struct RangeExpr { |
1303 | pub(crate) syntax: SyntaxNode, | 743 | pub(crate) syntax: SyntaxNode, |
1304 | } | 744 | } |
1305 | impl ast::AttrsOwner for RangeExpr {} | 745 | impl ast::AttrsOwner for RangeExpr {} |
1306 | impl RangeExpr {} | 746 | impl RangeExpr {} |
1307 | /// Binary operator call. | ||
1308 | /// Includes all arithmetic, logic, bitwise and assignment operators. | ||
1309 | /// | ||
1310 | /// ``` | ||
1311 | /// ❰ 2 + ❰ 2 * 2 ❱ ❱; | ||
1312 | /// ❰ ❰ true && false ❱ || true ❱; | ||
1313 | /// ``` | ||
1314 | /// | ||
1315 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators) | ||
1316 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 747 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1317 | pub struct BinExpr { | 748 | pub struct BinExpr { |
1318 | pub(crate) syntax: SyntaxNode, | 749 | pub(crate) syntax: SyntaxNode, |
1319 | } | 750 | } |
1320 | impl ast::AttrsOwner for BinExpr {} | 751 | impl ast::AttrsOwner for BinExpr {} |
1321 | impl BinExpr {} | 752 | impl BinExpr {} |
1322 | /// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal. | ||
1323 | /// | ||
1324 | /// ``` | ||
1325 | /// ❰ "str" ❱; | ||
1326 | /// ❰ br##"raw byte str"## ❱; | ||
1327 | /// ❰ 'c' ❱; | ||
1328 | /// ❰ b'c' ❱; | ||
1329 | /// ❰ 42 ❱; | ||
1330 | /// ❰ 1e9 ❱; | ||
1331 | /// ❰ true ❱; | ||
1332 | /// ``` | ||
1333 | /// | ||
1334 | /// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html) | ||
1335 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 753 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1336 | pub struct Literal { | 754 | pub struct Literal { |
1337 | pub(crate) syntax: SyntaxNode, | 755 | pub(crate) syntax: SyntaxNode, |
1338 | } | 756 | } |
1339 | impl Literal {} | 757 | impl Literal {} |
1340 | /// Match expression. | ||
1341 | /// | ||
1342 | /// ``` | ||
1343 | /// ❰ | ||
1344 | /// match expr { | ||
1345 | /// Pat1 => {} | ||
1346 | /// Pat2(_) => 42, | ||
1347 | /// } | ||
1348 | /// ❱ | ||
1349 | /// ``` | ||
1350 | /// | ||
1351 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
1352 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 758 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1353 | pub struct MatchExpr { | 759 | pub struct MatchExpr { |
1354 | pub(crate) syntax: SyntaxNode, | 760 | pub(crate) syntax: SyntaxNode, |
@@ -1359,40 +765,15 @@ impl MatchExpr { | |||
1359 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 765 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1360 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } | 766 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } |
1361 | } | 767 | } |
1362 | /// Match arm list part of match expression. Includes its inner attributes. | ||
1363 | /// | ||
1364 | /// ``` | ||
1365 | /// match expr | ||
1366 | /// ❰ | ||
1367 | /// { | ||
1368 | /// #![inner_attr] | ||
1369 | /// Pat1 => {} | ||
1370 | /// Pat2(_) => 42, | ||
1371 | /// } | ||
1372 | /// ❱ | ||
1373 | /// ``` | ||
1374 | /// | ||
1375 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
1376 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 768 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1377 | pub struct MatchArmList { | 769 | pub struct MatchArmList { |
1378 | pub(crate) syntax: SyntaxNode, | 770 | pub(crate) syntax: SyntaxNode, |
1379 | } | 771 | } |
1380 | impl ast::AttrsOwner for MatchArmList {} | ||
1381 | impl MatchArmList { | 772 | impl MatchArmList { |
1382 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 773 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
1383 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } | 774 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } |
1384 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 775 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1385 | } | 776 | } |
1386 | /// Match arm. | ||
1387 | /// Note: record struct literals are not valid as target match expression | ||
1388 | /// due to ambiguity. | ||
1389 | /// ``` | ||
1390 | /// match expr { | ||
1391 | /// ❰ #[attr] Pattern(it) if bool_cond => it ❱, | ||
1392 | /// } | ||
1393 | /// ``` | ||
1394 | /// | ||
1395 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
1396 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 777 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1397 | pub struct MatchArm { | 778 | pub struct MatchArm { |
1398 | pub(crate) syntax: SyntaxNode, | 779 | pub(crate) syntax: SyntaxNode, |
@@ -1404,15 +785,6 @@ impl MatchArm { | |||
1404 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } | 785 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } |
1405 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 786 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1406 | } | 787 | } |
1407 | /// Match guard. | ||
1408 | /// | ||
1409 | /// ``` | ||
1410 | /// match expr { | ||
1411 | /// Pattern(it) ❰ if bool_cond ❱ => it, | ||
1412 | /// } | ||
1413 | /// ``` | ||
1414 | /// | ||
1415 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards) | ||
1416 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 788 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1417 | pub struct MatchGuard { | 789 | pub struct MatchGuard { |
1418 | pub(crate) syntax: SyntaxNode, | 790 | pub(crate) syntax: SyntaxNode, |
@@ -1421,21 +793,6 @@ impl MatchGuard { | |||
1421 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | 793 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } |
1422 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 794 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1423 | } | 795 | } |
1424 | /// Record literal expression. The same syntax is used for structs, | ||
1425 | /// unions and record enum variants. | ||
1426 | /// | ||
1427 | /// ``` | ||
1428 | /// ❰ | ||
1429 | /// foo::Bar { | ||
1430 | /// #![inner_attr] | ||
1431 | /// baz: 42, | ||
1432 | /// bruh: true, | ||
1433 | /// ..spread | ||
1434 | /// } | ||
1435 | /// ❱ | ||
1436 | /// ``` | ||
1437 | /// | ||
1438 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
1439 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 796 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1440 | pub struct RecordLit { | 797 | pub struct RecordLit { |
1441 | pub(crate) syntax: SyntaxNode, | 798 | pub(crate) syntax: SyntaxNode, |
@@ -1444,16 +801,6 @@ impl RecordLit { | |||
1444 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 801 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
1445 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } | 802 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } |
1446 | } | 803 | } |
1447 | /// Record field list including enclosing curly braces. | ||
1448 | /// | ||
1449 | /// foo::Bar ❰ | ||
1450 | /// { | ||
1451 | /// baz: 42, | ||
1452 | /// ..spread | ||
1453 | /// } | ||
1454 | /// ❱ | ||
1455 | /// | ||
1456 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
1457 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 804 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1458 | pub struct RecordFieldList { | 805 | pub struct RecordFieldList { |
1459 | pub(crate) syntax: SyntaxNode, | 806 | pub(crate) syntax: SyntaxNode, |
@@ -1465,15 +812,6 @@ impl RecordFieldList { | |||
1465 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } | 812 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } |
1466 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 813 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1467 | } | 814 | } |
1468 | /// Record field. | ||
1469 | /// | ||
1470 | /// ``` | ||
1471 | /// foo::Bar { | ||
1472 | /// ❰ #[attr] baz: 42 ❱ | ||
1473 | /// } | ||
1474 | /// ``` | ||
1475 | /// | ||
1476 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
1477 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 815 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1478 | pub struct RecordField { | 816 | pub struct RecordField { |
1479 | pub(crate) syntax: SyntaxNode, | 817 | pub(crate) syntax: SyntaxNode, |
@@ -1484,13 +822,6 @@ impl RecordField { | |||
1484 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | 822 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
1485 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 823 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1486 | } | 824 | } |
1487 | /// Disjunction of patterns. | ||
1488 | /// | ||
1489 | /// ``` | ||
1490 | /// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh; | ||
1491 | /// ``` | ||
1492 | /// | ||
1493 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html) | ||
1494 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 825 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1495 | pub struct OrPat { | 826 | pub struct OrPat { |
1496 | pub(crate) syntax: SyntaxNode, | 827 | pub(crate) syntax: SyntaxNode, |
@@ -1498,14 +829,6 @@ pub struct OrPat { | |||
1498 | impl OrPat { | 829 | impl OrPat { |
1499 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 830 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
1500 | } | 831 | } |
1501 | /// Parenthesized pattern. | ||
1502 | /// Note: parens are only used for grouping, this is not a tuple pattern. | ||
1503 | /// | ||
1504 | /// ``` | ||
1505 | /// if let ❰ &(0..=42) ❱ = foo {} | ||
1506 | /// ``` | ||
1507 | /// | ||
1508 | /// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns | ||
1509 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 832 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1510 | pub struct ParenPat { | 833 | pub struct ParenPat { |
1511 | pub(crate) syntax: SyntaxNode, | 834 | pub(crate) syntax: SyntaxNode, |
@@ -1515,16 +838,6 @@ impl ParenPat { | |||
1515 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 838 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1516 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 839 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1517 | } | 840 | } |
1518 | /// Reference pattern. | ||
1519 | /// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns. | ||
1520 | /// | ||
1521 | /// ``` | ||
1522 | /// let ❰ &mut foo ❱ = bar; | ||
1523 | /// | ||
1524 | /// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz; | ||
1525 | /// ``` | ||
1526 | /// | ||
1527 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns) | ||
1528 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 841 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1529 | pub struct RefPat { | 842 | pub struct RefPat { |
1530 | pub(crate) syntax: SyntaxNode, | 843 | pub(crate) syntax: SyntaxNode, |
@@ -1534,31 +847,14 @@ impl RefPat { | |||
1534 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 847 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
1535 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 848 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1536 | } | 849 | } |
1537 | /// Box pattern. | ||
1538 | /// | ||
1539 | /// ``` | ||
1540 | /// let ❰ box foo ❱ = box 42; | ||
1541 | /// ``` | ||
1542 | /// | ||
1543 | /// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html) | ||
1544 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 850 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1545 | pub struct BoxPat { | 851 | pub struct BoxPat { |
1546 | pub(crate) syntax: SyntaxNode, | 852 | pub(crate) syntax: SyntaxNode, |
1547 | } | 853 | } |
1548 | impl BoxPat { | 854 | impl BoxPat { |
1549 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | 855 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } |
1550 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 856 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
1551 | } | 857 | } |
1552 | /// Bind pattern. | ||
1553 | /// | ||
1554 | /// ``` | ||
1555 | /// match foo { | ||
1556 | /// Some(❰ ref mut bar ❱) => {} | ||
1557 | /// ❰ baz @ None ❱ => {} | ||
1558 | /// } | ||
1559 | /// ``` | ||
1560 | /// | ||
1561 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns) | ||
1562 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 858 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1563 | pub struct BindPat { | 859 | pub struct BindPat { |
1564 | pub(crate) syntax: SyntaxNode, | 860 | pub(crate) syntax: SyntaxNode, |
@@ -1571,13 +867,6 @@ impl BindPat { | |||
1571 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } | 867 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } |
1572 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 868 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1573 | } | 869 | } |
1574 | /// Placeholder pattern a.k.a. the wildcard pattern or the underscore. | ||
1575 | /// | ||
1576 | /// ``` | ||
1577 | /// let ❰ _ ❱ = foo; | ||
1578 | /// ``` | ||
1579 | /// | ||
1580 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern) | ||
1581 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 870 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1582 | pub struct PlaceholderPat { | 871 | pub struct PlaceholderPat { |
1583 | pub(crate) syntax: SyntaxNode, | 872 | pub(crate) syntax: SyntaxNode, |
@@ -1585,16 +874,6 @@ pub struct PlaceholderPat { | |||
1585 | impl PlaceholderPat { | 874 | impl PlaceholderPat { |
1586 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | 875 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
1587 | } | 876 | } |
1588 | /// Rest-of-the record/tuple pattern. | ||
1589 | /// Note: this is not the unbonded range pattern (even more: it doesn't exist). | ||
1590 | /// | ||
1591 | /// ``` | ||
1592 | /// let Foo { bar, ❰ .. ❱ } = baz; | ||
1593 | /// let (❰ .. ❱, bruh) = (42, 24, 42); | ||
1594 | /// let Bruuh(❰ .. ❱) = bruuuh; | ||
1595 | /// ``` | ||
1596 | /// | ||
1597 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
1598 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 877 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1599 | pub struct DotDotPat { | 878 | pub struct DotDotPat { |
1600 | pub(crate) syntax: SyntaxNode, | 879 | pub(crate) syntax: SyntaxNode, |
@@ -1602,15 +881,6 @@ pub struct DotDotPat { | |||
1602 | impl DotDotPat { | 881 | impl DotDotPat { |
1603 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 882 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
1604 | } | 883 | } |
1605 | /// Path pattern. | ||
1606 | /// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`). | ||
1607 | /// | ||
1608 | /// ``` | ||
1609 | /// let ❰ foo::bar::Baz ❱ { .. } = bruh; | ||
1610 | /// if let ❰ CONST ❱ = 42 {} | ||
1611 | /// ``` | ||
1612 | /// | ||
1613 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns) | ||
1614 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 884 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1615 | pub struct PathPat { | 885 | pub struct PathPat { |
1616 | pub(crate) syntax: SyntaxNode, | 886 | pub(crate) syntax: SyntaxNode, |
@@ -1618,13 +888,6 @@ pub struct PathPat { | |||
1618 | impl PathPat { | 888 | impl PathPat { |
1619 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 889 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
1620 | } | 890 | } |
1621 | /// Slice pattern. | ||
1622 | /// | ||
1623 | /// ``` | ||
1624 | /// let ❰ [foo, bar, baz] ❱ = [1, 2, 3]; | ||
1625 | /// ``` | ||
1626 | /// | ||
1627 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns) | ||
1628 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 891 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1629 | pub struct SlicePat { | 892 | pub struct SlicePat { |
1630 | pub(crate) syntax: SyntaxNode, | 893 | pub(crate) syntax: SyntaxNode, |
@@ -1634,33 +897,14 @@ impl SlicePat { | |||
1634 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 897 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
1635 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 898 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
1636 | } | 899 | } |
1637 | /// Range pattern. | ||
1638 | /// | ||
1639 | /// ``` | ||
1640 | /// match foo { | ||
1641 | /// ❰ 0..42 ❱ => {} | ||
1642 | /// ❰ 0..=42 ❱ => {} | ||
1643 | /// } | ||
1644 | /// ``` | ||
1645 | /// | ||
1646 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns) | ||
1647 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 900 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1648 | pub struct RangePat { | 901 | pub struct RangePat { |
1649 | pub(crate) syntax: SyntaxNode, | 902 | pub(crate) syntax: SyntaxNode, |
1650 | } | 903 | } |
1651 | impl RangePat {} | 904 | impl RangePat { |
1652 | /// Literal pattern. | 905 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
1653 | /// Includes only bool, number, char, and string literals. | 906 | pub fn dotdoteq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..=]) } |
1654 | /// | 907 | } |
1655 | /// ``` | ||
1656 | /// match foo { | ||
1657 | /// Number(❰ 42 ❱) => {} | ||
1658 | /// String(❰ "42" ❱) => {} | ||
1659 | /// Bool(❰ true ❱) => {} | ||
1660 | /// } | ||
1661 | /// ``` | ||
1662 | /// | ||
1663 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns) | ||
1664 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 908 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1665 | pub struct LiteralPat { | 909 | pub struct LiteralPat { |
1666 | pub(crate) syntax: SyntaxNode, | 910 | pub(crate) syntax: SyntaxNode, |
@@ -1668,13 +912,6 @@ pub struct LiteralPat { | |||
1668 | impl LiteralPat { | 912 | impl LiteralPat { |
1669 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 913 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
1670 | } | 914 | } |
1671 | /// Macro invocation in pattern position. | ||
1672 | /// | ||
1673 | /// ``` | ||
1674 | /// let ❰ foo!(my custom syntax) ❱ = baz; | ||
1675 | /// | ||
1676 | /// ``` | ||
1677 | /// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation) | ||
1678 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 915 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1679 | pub struct MacroPat { | 916 | pub struct MacroPat { |
1680 | pub(crate) syntax: SyntaxNode, | 917 | pub(crate) syntax: SyntaxNode, |
@@ -1682,37 +919,34 @@ pub struct MacroPat { | |||
1682 | impl MacroPat { | 919 | impl MacroPat { |
1683 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } | 920 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } |
1684 | } | 921 | } |
1685 | /// Record literal pattern. | 922 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1686 | /// | 923 | pub struct MacroCall { |
1687 | /// ``` | 924 | pub(crate) syntax: SyntaxNode, |
1688 | /// let ❰ foo::Bar { baz, .. } ❱ = bruh; | 925 | } |
1689 | /// ``` | 926 | impl ast::AttrsOwner for MacroCall {} |
1690 | /// | 927 | impl ast::NameOwner for MacroCall {} |
1691 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | 928 | impl MacroCall { |
929 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
930 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
931 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
932 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
933 | } | ||
1692 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 934 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1693 | pub struct RecordPat { | 935 | pub struct RecordPat { |
1694 | pub(crate) syntax: SyntaxNode, | 936 | pub(crate) syntax: SyntaxNode, |
1695 | } | 937 | } |
1696 | impl RecordPat { | 938 | impl RecordPat { |
939 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1697 | pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> { | 940 | pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> { |
1698 | support::child(&self.syntax) | 941 | support::child(&self.syntax) |
1699 | } | 942 | } |
1700 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1701 | } | 943 | } |
1702 | /// Record literal's field patterns list including enclosing curly braces. | ||
1703 | /// | ||
1704 | /// ``` | ||
1705 | /// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh; | ||
1706 | /// `` | ||
1707 | /// | ||
1708 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
1709 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 944 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1710 | pub struct RecordFieldPatList { | 945 | pub struct RecordFieldPatList { |
1711 | pub(crate) syntax: SyntaxNode, | 946 | pub(crate) syntax: SyntaxNode, |
1712 | } | 947 | } |
1713 | impl RecordFieldPatList { | 948 | impl RecordFieldPatList { |
1714 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 949 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
1715 | pub fn pats(&self) -> AstChildren<RecordInnerPat> { support::children(&self.syntax) } | ||
1716 | pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> { | 950 | pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> { |
1717 | support::children(&self.syntax) | 951 | support::children(&self.syntax) |
1718 | } | 952 | } |
@@ -1720,15 +954,6 @@ impl RecordFieldPatList { | |||
1720 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 954 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
1721 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 955 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1722 | } | 956 | } |
1723 | /// Record literal's field pattern. | ||
1724 | /// Note: record literal can also match tuple structs. | ||
1725 | /// | ||
1726 | /// ``` | ||
1727 | /// let Foo { ❰ bar: _ ❱ } = baz; | ||
1728 | /// let TupleStruct { ❰ 0: _ ❱ } = bruh; | ||
1729 | /// ``` | ||
1730 | /// | ||
1731 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
1732 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 957 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1733 | pub struct RecordFieldPat { | 958 | pub struct RecordFieldPat { |
1734 | pub(crate) syntax: SyntaxNode, | 959 | pub(crate) syntax: SyntaxNode, |
@@ -1739,13 +964,6 @@ impl RecordFieldPat { | |||
1739 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | 964 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
1740 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 965 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1741 | } | 966 | } |
1742 | /// Tuple struct literal pattern. | ||
1743 | /// | ||
1744 | /// ``` | ||
1745 | /// let ❰ foo::Bar(baz, bruh) ❱ = bruuh; | ||
1746 | /// ``` | ||
1747 | /// | ||
1748 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns) | ||
1749 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 967 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1750 | pub struct TupleStructPat { | 968 | pub struct TupleStructPat { |
1751 | pub(crate) syntax: SyntaxNode, | 969 | pub(crate) syntax: SyntaxNode, |
@@ -1756,14 +974,6 @@ impl TupleStructPat { | |||
1756 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 974 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
1757 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 975 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1758 | } | 976 | } |
1759 | /// Tuple pattern. | ||
1760 | /// Note: this doesn't include tuple structs (see `TupleStructPat`) | ||
1761 | /// | ||
1762 | /// ``` | ||
1763 | /// let ❰ (foo, bar, .., baz) ❱ = bruh; | ||
1764 | /// ``` | ||
1765 | /// | ||
1766 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns) | ||
1767 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 977 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1768 | pub struct TuplePat { | 978 | pub struct TuplePat { |
1769 | pub(crate) syntax: SyntaxNode, | 979 | pub(crate) syntax: SyntaxNode, |
@@ -1773,210 +983,51 @@ impl TuplePat { | |||
1773 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 983 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
1774 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 984 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1775 | } | 985 | } |
1776 | /// Visibility. | ||
1777 | /// | ||
1778 | /// ``` | ||
1779 | /// ❰ pub mod ❱ foo; | ||
1780 | /// ❰ pub(crate) ❱ struct Bar; | ||
1781 | /// ❰ pub(self) ❱ enum Baz {} | ||
1782 | /// ❰ pub(super) ❱ fn bruh() {} | ||
1783 | /// ❰ pub(in bruuh::bruuuh) ❱ type T = u64; | ||
1784 | /// ``` | ||
1785 | /// | ||
1786 | /// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html) | ||
1787 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1788 | pub struct Visibility { | ||
1789 | pub(crate) syntax: SyntaxNode, | ||
1790 | } | ||
1791 | impl Visibility { | ||
1792 | pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) } | ||
1793 | pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) } | ||
1794 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
1795 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | ||
1796 | } | ||
1797 | /// Single identifier. | ||
1798 | /// Note(@matklad): `Name` is for things that install a new name into the scope, | ||
1799 | /// `NameRef` is a usage of a name. Most of the time, this definition/reference | ||
1800 | /// distinction can be determined purely syntactically, ie in | ||
1801 | /// ``` | ||
1802 | /// fn foo() { foo() } | ||
1803 | /// ``` | ||
1804 | /// the first foo is `Name`, the second one is `NameRef`. | ||
1805 | /// The notable exception are patterns, where in | ||
1806 | /// `` | ||
1807 | /// let x = 92 | ||
1808 | /// ``` | ||
1809 | /// `x` can be semantically either a name or a name ref, depeding on | ||
1810 | /// wether there's an `x` constant in scope. | ||
1811 | /// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db). | ||
1812 | /// | ||
1813 | /// ``` | ||
1814 | /// let ❰ foo ❱ = bar; | ||
1815 | /// struct ❰ Baz ❱; | ||
1816 | /// fn ❰ bruh ❱() {} | ||
1817 | /// ``` | ||
1818 | /// | ||
1819 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
1820 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 986 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1821 | pub struct Name { | 987 | pub struct TokenTree { |
1822 | pub(crate) syntax: SyntaxNode, | 988 | pub(crate) syntax: SyntaxNode, |
1823 | } | 989 | } |
1824 | impl Name { | 990 | impl TokenTree { |
1825 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | 991 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } |
1826 | } | 992 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1827 | /// Reference to a name. | 993 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
1828 | /// See the explanation on the difference between `Name` and `NameRef` | 994 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1829 | /// in `Name` ast node docs. | 995 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
1830 | /// | 996 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
1831 | /// ``` | ||
1832 | /// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱; | ||
1833 | /// ``` | ||
1834 | /// | ||
1835 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
1836 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1837 | pub struct NameRef { | ||
1838 | pub(crate) syntax: SyntaxNode, | ||
1839 | } | 997 | } |
1840 | impl NameRef {} | ||
1841 | /// Macro call. | ||
1842 | /// Includes all of its attributes and doc comments. | ||
1843 | /// | ||
1844 | /// ``` | ||
1845 | /// ❰ | ||
1846 | /// /// Docs | ||
1847 | /// #[attr] | ||
1848 | /// macro_rules! foo { // macro rules is also a macro call | ||
1849 | /// ($bar: tt) => {} | ||
1850 | /// } | ||
1851 | /// ❱ | ||
1852 | /// | ||
1853 | /// // semicolon is a part of `MacroCall` when it is used in item positions | ||
1854 | /// ❰ foo!(); ❱ | ||
1855 | /// | ||
1856 | /// fn main() { | ||
1857 | /// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi | ||
1858 | /// } | ||
1859 | /// ``` | ||
1860 | /// | ||
1861 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1862 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 998 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1863 | pub struct MacroCall { | 999 | pub struct MacroDef { |
1864 | pub(crate) syntax: SyntaxNode, | 1000 | pub(crate) syntax: SyntaxNode, |
1865 | } | 1001 | } |
1866 | impl ast::NameOwner for MacroCall {} | 1002 | impl ast::NameOwner for MacroDef {} |
1867 | impl ast::AttrsOwner for MacroCall {} | 1003 | impl MacroDef { |
1868 | impl ast::DocCommentsOwner for MacroCall {} | ||
1869 | impl MacroCall { | ||
1870 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1871 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
1872 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | 1004 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } |
1873 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
1874 | } | ||
1875 | /// Attribute. | ||
1876 | /// | ||
1877 | /// ``` | ||
1878 | /// ❰ #![inner_attr] ❱ | ||
1879 | /// | ||
1880 | /// ❰ #[attr] ❱ | ||
1881 | /// ❰ #[foo = "bar"] ❱ | ||
1882 | /// ❰ #[baz(bruh::bruuh = "42")] ❱ | ||
1883 | /// struct Foo; | ||
1884 | /// ``` | ||
1885 | /// | ||
1886 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html) | ||
1887 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1888 | pub struct Attr { | ||
1889 | pub(crate) syntax: SyntaxNode, | ||
1890 | } | ||
1891 | impl Attr { | ||
1892 | pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) } | ||
1893 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
1894 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
1895 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1896 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
1897 | pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) } | ||
1898 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
1899 | } | 1005 | } |
1900 | /// Stores a list of lexer tokens and other `TokenTree`s. | ||
1901 | /// It appears in attributes, macro_rules and macro call (foo!) | ||
1902 | /// | ||
1903 | /// ``` | ||
1904 | /// macro_call! ❰ { my syntax here } ❱; | ||
1905 | /// ``` | ||
1906 | /// | ||
1907 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1908 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1006 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1909 | pub struct TokenTree { | 1007 | pub struct MacroItems { |
1910 | pub(crate) syntax: SyntaxNode, | 1008 | pub(crate) syntax: SyntaxNode, |
1911 | } | 1009 | } |
1912 | impl TokenTree {} | 1010 | impl ast::ModuleItemOwner for MacroItems {} |
1913 | /// Generic lifetime, type and constants parameters list **declaration**. | 1011 | impl MacroItems {} |
1914 | /// | ||
1915 | /// ``` | ||
1916 | /// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {} | ||
1917 | /// | ||
1918 | /// struct Baz❰ <T> ❱(T); | ||
1919 | /// | ||
1920 | /// impl❰ <T> ❱ Bruh<T> {} | ||
1921 | /// | ||
1922 | /// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str; | ||
1923 | /// ``` | ||
1924 | /// | ||
1925 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1926 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1012 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1927 | pub struct TypeParamList { | 1013 | pub struct MacroStmts { |
1928 | pub(crate) syntax: SyntaxNode, | 1014 | pub(crate) syntax: SyntaxNode, |
1929 | } | 1015 | } |
1930 | impl TypeParamList { | 1016 | impl MacroStmts { |
1931 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | 1017 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } |
1932 | pub fn generic_params(&self) -> AstChildren<GenericParam> { support::children(&self.syntax) } | 1018 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1933 | pub fn type_params(&self) -> AstChildren<TypeParam> { support::children(&self.syntax) } | ||
1934 | pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> { support::children(&self.syntax) } | ||
1935 | pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) } | ||
1936 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | ||
1937 | } | 1019 | } |
1938 | /// Single type parameter **declaration**. | ||
1939 | /// | ||
1940 | /// ``` | ||
1941 | /// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {} | ||
1942 | /// ``` | ||
1943 | /// | ||
1944 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1945 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1020 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1946 | pub struct TypeParam { | 1021 | pub struct TypeParam { |
1947 | pub(crate) syntax: SyntaxNode, | 1022 | pub(crate) syntax: SyntaxNode, |
1948 | } | 1023 | } |
1949 | impl ast::NameOwner for TypeParam {} | ||
1950 | impl ast::AttrsOwner for TypeParam {} | 1024 | impl ast::AttrsOwner for TypeParam {} |
1025 | impl ast::NameOwner for TypeParam {} | ||
1951 | impl ast::TypeBoundsOwner for TypeParam {} | 1026 | impl ast::TypeBoundsOwner for TypeParam {} |
1952 | impl TypeParam { | 1027 | impl TypeParam { |
1953 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1028 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1954 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1029 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1955 | } | 1030 | } |
1956 | /// Const generic parameter **declaration**. | ||
1957 | /// ``` | ||
1958 | /// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {} | ||
1959 | /// ``` | ||
1960 | /// | ||
1961 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
1962 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1963 | pub struct ConstParam { | ||
1964 | pub(crate) syntax: SyntaxNode, | ||
1965 | } | ||
1966 | impl ast::NameOwner for ConstParam {} | ||
1967 | impl ast::AttrsOwner for ConstParam {} | ||
1968 | impl ast::TypeAscriptionOwner for ConstParam {} | ||
1969 | impl ConstParam { | ||
1970 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
1971 | pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
1972 | } | ||
1973 | /// Lifetime parameter **declaration**. | ||
1974 | /// | ||
1975 | /// ``` | ||
1976 | /// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {} | ||
1977 | /// ``` | ||
1978 | /// | ||
1979 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1980 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1031 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1981 | pub struct LifetimeParam { | 1032 | pub struct LifetimeParam { |
1982 | pub(crate) syntax: SyntaxNode, | 1033 | pub(crate) syntax: SyntaxNode, |
@@ -1987,20 +1038,19 @@ impl LifetimeParam { | |||
1987 | support::token(&self.syntax, T![lifetime]) | 1038 | support::token(&self.syntax, T![lifetime]) |
1988 | } | 1039 | } |
1989 | } | 1040 | } |
1990 | /// Type bound declaration clause. | 1041 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1991 | /// | 1042 | pub struct ConstParam { |
1992 | /// ``` | 1043 | pub(crate) syntax: SyntaxNode, |
1993 | /// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {} | 1044 | } |
1994 | /// | 1045 | impl ast::AttrsOwner for ConstParam {} |
1995 | /// trait Bar<T> | 1046 | impl ast::NameOwner for ConstParam {} |
1996 | /// where | 1047 | impl ast::TypeAscriptionOwner for ConstParam {} |
1997 | /// T: ❰ Send ❱ + ❰ Sync ❱ | 1048 | impl ConstParam { |
1998 | /// { | 1049 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
1999 | /// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱; | 1050 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
2000 | /// } | 1051 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
2001 | /// ``` | 1052 | pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } |
2002 | /// | 1053 | } |
2003 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
2004 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1054 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2005 | pub struct TypeBound { | 1055 | pub struct TypeBound { |
2006 | pub(crate) syntax: SyntaxNode, | 1056 | pub(crate) syntax: SyntaxNode, |
@@ -2012,40 +1062,6 @@ impl TypeBound { | |||
2012 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 1062 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
2013 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1063 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
2014 | } | 1064 | } |
2015 | /// Type bounds list. | ||
2016 | /// | ||
2017 | /// ``` | ||
2018 | /// | ||
2019 | /// fn foo<T: ❰ ?Sized + Debug ❱>() {} | ||
2020 | /// | ||
2021 | /// trait Bar<T> | ||
2022 | /// where | ||
2023 | /// T: ❰ Send + Sync ❱ | ||
2024 | /// { | ||
2025 | /// type Baz: ❰ !Sync + Debug ❱; | ||
2026 | /// } | ||
2027 | /// ``` | ||
2028 | /// | ||
2029 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
2030 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2031 | pub struct TypeBoundList { | ||
2032 | pub(crate) syntax: SyntaxNode, | ||
2033 | } | ||
2034 | impl TypeBoundList { | ||
2035 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } | ||
2036 | } | ||
2037 | /// Single where predicate. | ||
2038 | /// | ||
2039 | /// ``` | ||
2040 | /// trait Foo<'a, 'b, T> | ||
2041 | /// where | ||
2042 | /// ❰ 'a: 'b ❱, | ||
2043 | /// ❰ T: IntoIterator ❱, | ||
2044 | /// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱ | ||
2045 | /// {} | ||
2046 | /// ``` | ||
2047 | /// | ||
2048 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
2049 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1065 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2050 | pub struct WherePred { | 1066 | pub struct WherePred { |
2051 | pub(crate) syntax: SyntaxNode, | 1067 | pub(crate) syntax: SyntaxNode, |
@@ -2059,58 +1075,6 @@ impl WherePred { | |||
2059 | } | 1075 | } |
2060 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1076 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
2061 | } | 1077 | } |
2062 | /// Where clause. | ||
2063 | /// | ||
2064 | /// ``` | ||
2065 | /// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {} | ||
2066 | /// | ||
2067 | /// ``` | ||
2068 | /// | ||
2069 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
2070 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2071 | pub struct WhereClause { | ||
2072 | pub(crate) syntax: SyntaxNode, | ||
2073 | } | ||
2074 | impl WhereClause { | ||
2075 | pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } | ||
2076 | pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } | ||
2077 | } | ||
2078 | /// Abi declaration. | ||
2079 | /// Note: the abi string is optional. | ||
2080 | /// | ||
2081 | /// ``` | ||
2082 | /// ❰ extern "C" ❱ { | ||
2083 | /// fn foo() {} | ||
2084 | /// } | ||
2085 | /// | ||
2086 | /// type Bar = ❰ extern ❱ fn() -> u32; | ||
2087 | /// | ||
2088 | /// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool; | ||
2089 | /// ``` | ||
2090 | /// | ||
2091 | /// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
2092 | /// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions) | ||
2093 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2094 | pub struct Abi { | ||
2095 | pub(crate) syntax: SyntaxNode, | ||
2096 | } | ||
2097 | impl Abi {} | ||
2098 | /// Expression statement. | ||
2099 | /// | ||
2100 | /// ``` | ||
2101 | /// ❰ 42; ❱ | ||
2102 | /// ❰ foo(); ❱ | ||
2103 | /// ❰ (); ❱ | ||
2104 | /// ❰ {}; ❱ | ||
2105 | /// | ||
2106 | /// // constructions with trailing curly brace can omit the semicolon | ||
2107 | /// // but only when there are satements immediately after them (this is important!) | ||
2108 | /// ❰ if bool_cond { } ❱ | ||
2109 | /// ❰ loop {} ❱ | ||
2110 | /// ❰ somestatment; ❱ | ||
2111 | /// ``` | ||
2112 | /// | ||
2113 | /// [Reference](https://doc.rust-lang.org/reference/statements.html) | ||
2114 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1078 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2115 | pub struct ExprStmt { | 1079 | pub struct ExprStmt { |
2116 | pub(crate) syntax: SyntaxNode, | 1080 | pub(crate) syntax: SyntaxNode, |
@@ -2120,16 +1084,6 @@ impl ExprStmt { | |||
2120 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1084 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
2121 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 1085 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
2122 | } | 1086 | } |
2123 | /// Let statement. | ||
2124 | /// | ||
2125 | /// ``` | ||
2126 | /// ❰ #[attr] let foo; ❱ | ||
2127 | /// ❰ let bar: u64; ❱ | ||
2128 | /// ❰ let baz = 42; ❱ | ||
2129 | /// ❰ let bruh: bool = true; ❱ | ||
2130 | /// ``` | ||
2131 | /// | ||
2132 | /// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements) | ||
2133 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1087 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2134 | pub struct LetStmt { | 1088 | pub struct LetStmt { |
2135 | pub(crate) syntax: SyntaxNode, | 1089 | pub(crate) syntax: SyntaxNode, |
@@ -2139,112 +1093,37 @@ impl ast::TypeAscriptionOwner for LetStmt {} | |||
2139 | impl LetStmt { | 1093 | impl LetStmt { |
2140 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } | 1094 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } |
2141 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1095 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1096 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
2142 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1097 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
2143 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } | 1098 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } |
2144 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 1099 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
2145 | } | 1100 | } |
2146 | /// Condition of `if` or `while` expression. | ||
2147 | /// | ||
2148 | /// ``` | ||
2149 | /// if ❰ true ❱ {} | ||
2150 | /// if ❰ let Pat(foo) = bar ❱ {} | ||
2151 | /// | ||
2152 | /// while ❰ true ❱ {} | ||
2153 | /// while ❰ let Pat(baz) = bruh ❱ {} | ||
2154 | /// ``` | ||
2155 | /// | ||
2156 | /// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
2157 | /// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
2158 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2159 | pub struct Condition { | ||
2160 | pub(crate) syntax: SyntaxNode, | ||
2161 | } | ||
2162 | impl Condition { | ||
2163 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } | ||
2164 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
2165 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
2166 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
2167 | } | ||
2168 | /// Parameter list **declaration**. | ||
2169 | /// | ||
2170 | /// ``` | ||
2171 | /// fn foo❰ (a: u32, b: bool) ❱ -> u32 {} | ||
2172 | /// let bar = ❰ |a, b| ❱ {}; | ||
2173 | /// | ||
2174 | /// impl Baz { | ||
2175 | /// fn bruh❰ (&self, a: u32) ❱ {} | ||
2176 | /// } | ||
2177 | /// ``` | ||
2178 | /// | ||
2179 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script | ||
2180 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2181 | pub struct ParamList { | ||
2182 | pub(crate) syntax: SyntaxNode, | ||
2183 | } | ||
2184 | impl ParamList { | ||
2185 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
2186 | pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) } | ||
2187 | pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } | ||
2188 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
2189 | } | ||
2190 | /// Self parameter **declaration**. | ||
2191 | /// | ||
2192 | /// ``` | ||
2193 | /// impl Bruh { | ||
2194 | /// fn foo(❰ self ❱) {} | ||
2195 | /// fn bar(❰ &self ❱) {} | ||
2196 | /// fn baz(❰ &mut self ❱) {} | ||
2197 | /// fn blah<'a>(❰ &'a self ❱) {} | ||
2198 | /// fn blin(❰ self: Box<Self> ❱) {} | ||
2199 | /// } | ||
2200 | /// ``` | ||
2201 | /// | ||
2202 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
2203 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1101 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2204 | pub struct SelfParam { | 1102 | pub struct SelfParam { |
2205 | pub(crate) syntax: SyntaxNode, | 1103 | pub(crate) syntax: SyntaxNode, |
2206 | } | 1104 | } |
2207 | impl ast::TypeAscriptionOwner for SelfParam {} | ||
2208 | impl ast::AttrsOwner for SelfParam {} | 1105 | impl ast::AttrsOwner for SelfParam {} |
1106 | impl ast::TypeAscriptionOwner for SelfParam {} | ||
2209 | impl SelfParam { | 1107 | impl SelfParam { |
2210 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } | 1108 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } |
2211 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
2212 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | 1109 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { |
2213 | support::token(&self.syntax, T![lifetime]) | 1110 | support::token(&self.syntax, T![lifetime]) |
2214 | } | 1111 | } |
1112 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
2215 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | 1113 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } |
1114 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
2216 | } | 1115 | } |
2217 | /// Parameter **declaration**. | ||
2218 | /// | ||
2219 | /// ``` | ||
2220 | /// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {} | ||
2221 | /// | ||
2222 | /// extern "C" { | ||
2223 | /// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32; | ||
2224 | /// } | ||
2225 | /// ``` | ||
2226 | /// | ||
2227 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
2228 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1116 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2229 | pub struct Param { | 1117 | pub struct Param { |
2230 | pub(crate) syntax: SyntaxNode, | 1118 | pub(crate) syntax: SyntaxNode, |
2231 | } | 1119 | } |
2232 | impl ast::TypeAscriptionOwner for Param {} | ||
2233 | impl ast::AttrsOwner for Param {} | 1120 | impl ast::AttrsOwner for Param {} |
1121 | impl ast::TypeAscriptionOwner for Param {} | ||
2234 | impl Param { | 1122 | impl Param { |
2235 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1123 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1124 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
2236 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } | 1125 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } |
2237 | } | 1126 | } |
2238 | /// Use declaration. | ||
2239 | /// | ||
2240 | /// ``` | ||
2241 | /// ❰ #[attr] pub use foo; ❱ | ||
2242 | /// ❰ use bar as baz; ❱ | ||
2243 | /// ❰ use bruh::{self, bruuh}; ❱ | ||
2244 | /// ❰ use { blin::blen, blah::* }; | ||
2245 | /// ``` | ||
2246 | /// | ||
2247 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
2248 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1127 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2249 | pub struct UseItem { | 1128 | pub struct UseItem { |
2250 | pub(crate) syntax: SyntaxNode, | 1129 | pub(crate) syntax: SyntaxNode, |
@@ -2254,53 +1133,19 @@ impl ast::VisibilityOwner for UseItem {} | |||
2254 | impl UseItem { | 1133 | impl UseItem { |
2255 | pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } | 1134 | pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } |
2256 | pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } | 1135 | pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } |
1136 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
2257 | } | 1137 | } |
2258 | /// Use tree. | ||
2259 | /// | ||
2260 | /// ``` | ||
2261 | /// pub use ❰ foo::❰ * ❱ ❱; | ||
2262 | /// use ❰ bar as baz ❱; | ||
2263 | /// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱; | ||
2264 | /// use ❰ { ❰ blin::blen ❱ } ❱ | ||
2265 | /// ``` | ||
2266 | /// | ||
2267 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
2268 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1138 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2269 | pub struct UseTree { | 1139 | pub struct UseTree { |
2270 | pub(crate) syntax: SyntaxNode, | 1140 | pub(crate) syntax: SyntaxNode, |
2271 | } | 1141 | } |
2272 | impl UseTree { | 1142 | impl UseTree { |
2273 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 1143 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
1144 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
2274 | pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } | 1145 | pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } |
2275 | pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } | 1146 | pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } |
2276 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } | 1147 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } |
2277 | } | 1148 | } |
2278 | /// Item alias. | ||
2279 | /// Note: this is not the type alias. | ||
2280 | /// | ||
2281 | /// ``` | ||
2282 | /// use foo ❰ as bar ❱; | ||
2283 | /// use baz::{bruh ❰ as _ ❱}; | ||
2284 | /// extern crate bruuh ❰ as blin ❱; | ||
2285 | /// ``` | ||
2286 | /// | ||
2287 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
2288 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2289 | pub struct Alias { | ||
2290 | pub(crate) syntax: SyntaxNode, | ||
2291 | } | ||
2292 | impl ast::NameOwner for Alias {} | ||
2293 | impl Alias { | ||
2294 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | ||
2295 | } | ||
2296 | /// Sublist of use trees. | ||
2297 | /// | ||
2298 | /// ``` | ||
2299 | /// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱; | ||
2300 | /// use ❰ { blin::blen::❰ {} ❱ } ❱ | ||
2301 | /// ``` | ||
2302 | /// | ||
2303 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
2304 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1149 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2305 | pub struct UseTreeList { | 1150 | pub struct UseTreeList { |
2306 | pub(crate) syntax: SyntaxNode, | 1151 | pub(crate) syntax: SyntaxNode, |
@@ -2310,14 +1155,14 @@ impl UseTreeList { | |||
2310 | pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } | 1155 | pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } |
2311 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1156 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
2312 | } | 1157 | } |
2313 | /// Extern crate item. | 1158 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2314 | /// | 1159 | pub struct Alias { |
2315 | /// ``` | 1160 | pub(crate) syntax: SyntaxNode, |
2316 | /// ❰ #[attr] pub extern crate foo; ❱ | 1161 | } |
2317 | /// ❰ extern crate self as bar; ❱ | 1162 | impl ast::NameOwner for Alias {} |
2318 | /// ``` | 1163 | impl Alias { |
2319 | /// | 1164 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } |
2320 | /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) | 1165 | } |
2321 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1166 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2322 | pub struct ExternCrateItem { | 1167 | pub struct ExternCrateItem { |
2323 | pub(crate) syntax: SyntaxNode, | 1168 | pub(crate) syntax: SyntaxNode, |
@@ -2328,59 +1173,10 @@ impl ExternCrateItem { | |||
2328 | pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) } | 1173 | pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) } |
2329 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | 1174 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } |
2330 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 1175 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1176 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
2331 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } | 1177 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } |
1178 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
2332 | } | 1179 | } |
2333 | /// Call site arguments list. | ||
2334 | /// | ||
2335 | /// ``` | ||
2336 | /// foo::<T, U>❰ (42, true) ❱; | ||
2337 | /// ``` | ||
2338 | /// | ||
2339 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
2340 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2341 | pub struct ArgList { | ||
2342 | pub(crate) syntax: SyntaxNode, | ||
2343 | } | ||
2344 | impl ArgList { | ||
2345 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
2346 | pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | ||
2347 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
2348 | } | ||
2349 | /// Path to a symbol. Includes single identifier names and elaborate paths with | ||
2350 | /// generic parameters. | ||
2351 | /// | ||
2352 | /// ``` | ||
2353 | /// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱(); | ||
2354 | /// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024); | ||
2355 | /// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱(); | ||
2356 | /// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱(); | ||
2357 | /// ``` | ||
2358 | /// | ||
2359 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
2360 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2361 | pub struct Path { | ||
2362 | pub(crate) syntax: SyntaxNode, | ||
2363 | } | ||
2364 | impl Path { | ||
2365 | pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } | ||
2366 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
2367 | pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } | ||
2368 | } | ||
2369 | /// Segment of the path to a symbol. | ||
2370 | /// Only path segment of an absolute path holds the `::` token, | ||
2371 | /// all other `::` tokens that connect path segments reside under `Path` itself.` | ||
2372 | /// | ||
2373 | /// ``` | ||
2374 | /// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱(); | ||
2375 | /// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024); | ||
2376 | /// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱(); | ||
2377 | /// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱(); | ||
2378 | /// | ||
2379 | /// // Note that only in this case `::` token is inlcuded: | ||
2380 | /// ❰ ::foo ❱; | ||
2381 | /// ``` | ||
2382 | /// | ||
2383 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
2384 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1180 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2385 | pub struct PathSegment { | 1181 | pub struct PathSegment { |
2386 | pub(crate) syntax: SyntaxNode, | 1182 | pub(crate) syntax: SyntaxNode, |
@@ -2398,50 +1194,22 @@ impl PathSegment { | |||
2398 | pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } | 1194 | pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } |
2399 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | 1195 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
2400 | } | 1196 | } |
2401 | /// List of type arguments that are passed at generic instantiation site. | ||
2402 | /// | ||
2403 | /// ``` | ||
2404 | /// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar; | ||
2405 | /// | ||
2406 | /// Vec❰ ::<bool> ❱::(); | ||
2407 | /// ``` | ||
2408 | /// | ||
2409 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
2410 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1197 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2411 | pub struct TypeArgList { | 1198 | pub struct TypeArg { |
2412 | pub(crate) syntax: SyntaxNode, | 1199 | pub(crate) syntax: SyntaxNode, |
2413 | } | 1200 | } |
2414 | impl TypeArgList { | 1201 | impl TypeArg { |
2415 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | 1202 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
2416 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | ||
2417 | pub fn generic_args(&self) -> AstChildren<GenericArg> { support::children(&self.syntax) } | ||
2418 | pub fn type_args(&self) -> AstChildren<TypeArg> { support::children(&self.syntax) } | ||
2419 | pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { support::children(&self.syntax) } | ||
2420 | pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { support::children(&self.syntax) } | ||
2421 | pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } | ||
2422 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | ||
2423 | } | 1203 | } |
2424 | /// Type argument that is passed at generic instantiation site. | ||
2425 | /// | ||
2426 | /// ``` | ||
2427 | /// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz; | ||
2428 | /// ``` | ||
2429 | /// | ||
2430 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
2431 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1204 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2432 | pub struct TypeArg { | 1205 | pub struct LifetimeArg { |
2433 | pub(crate) syntax: SyntaxNode, | 1206 | pub(crate) syntax: SyntaxNode, |
2434 | } | 1207 | } |
2435 | impl TypeArg { | 1208 | impl LifetimeArg { |
2436 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1209 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { |
1210 | support::token(&self.syntax, T![lifetime]) | ||
1211 | } | ||
2437 | } | 1212 | } |
2438 | /// Associated type argument that is passed at generic instantiation site. | ||
2439 | /// ``` | ||
2440 | /// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh; | ||
2441 | /// | ||
2442 | /// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {} | ||
2443 | /// ``` | ||
2444 | /// | ||
2445 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1213 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2446 | pub struct AssocTypeArg { | 1214 | pub struct AssocTypeArg { |
2447 | pub(crate) syntax: SyntaxNode, | 1215 | pub(crate) syntax: SyntaxNode, |
@@ -2452,33 +1220,6 @@ impl AssocTypeArg { | |||
2452 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1220 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
2453 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1221 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
2454 | } | 1222 | } |
2455 | /// Lifetime argument that is passed at generic instantiation site. | ||
2456 | /// | ||
2457 | /// ``` | ||
2458 | /// fn foo<'a>(s: &'a str) { | ||
2459 | /// bar::<❰ 'a ❱>(s); | ||
2460 | /// } | ||
2461 | /// ``` | ||
2462 | /// | ||
2463 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
2464 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2465 | pub struct LifetimeArg { | ||
2466 | pub(crate) syntax: SyntaxNode, | ||
2467 | } | ||
2468 | impl LifetimeArg { | ||
2469 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
2470 | support::token(&self.syntax, T![lifetime]) | ||
2471 | } | ||
2472 | } | ||
2473 | /// Constant value argument that is passed at generic instantiation site. | ||
2474 | /// | ||
2475 | /// ``` | ||
2476 | /// foo::<u32, ❰ { true } ❱>(); | ||
2477 | /// | ||
2478 | /// bar::<❰ { 2 + 2} ❱>(); | ||
2479 | /// ``` | ||
2480 | /// | ||
2481 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
2482 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1223 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2483 | pub struct ConstArg { | 1224 | pub struct ConstArg { |
2484 | pub(crate) syntax: SyntaxNode, | 1225 | pub(crate) syntax: SyntaxNode, |
@@ -2487,83 +1228,24 @@ impl ConstArg { | |||
2487 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 1228 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
2488 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 1229 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
2489 | } | 1230 | } |
2490 | /// FIXME: (@edwin0cheng) Remove it to use ItemList instead | ||
2491 | /// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243 | ||
2492 | /// | ||
2493 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
2494 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2495 | pub struct MacroItems { | ||
2496 | pub(crate) syntax: SyntaxNode, | ||
2497 | } | ||
2498 | impl ast::ModuleItemOwner for MacroItems {} | ||
2499 | impl MacroItems {} | ||
2500 | /// FIXME: (@edwin0cheng) add some documentation here. As per the writing | ||
2501 | /// of this comment this ast node is not used. | ||
2502 | /// | ||
2503 | /// ``` | ||
2504 | /// // FIXME: example here | ||
2505 | /// ``` | ||
2506 | /// | ||
2507 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
2508 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1231 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2509 | pub struct MacroStmts { | 1232 | pub struct ExternBlock { |
2510 | pub(crate) syntax: SyntaxNode, | 1233 | pub(crate) syntax: SyntaxNode, |
2511 | } | 1234 | } |
2512 | impl MacroStmts { | 1235 | impl ast::AttrsOwner for ExternBlock {} |
2513 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } | 1236 | impl ExternBlock { |
2514 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1237 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } |
1238 | pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } | ||
2515 | } | 1239 | } |
2516 | /// List of items in an extern block. | ||
2517 | /// | ||
2518 | /// ``` | ||
2519 | /// extern "C" ❰ | ||
2520 | /// { | ||
2521 | /// fn foo(); | ||
2522 | /// static var: u32; | ||
2523 | /// } | ||
2524 | /// ❱ | ||
2525 | /// ``` | ||
2526 | /// | ||
2527 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
2528 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1240 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2529 | pub struct ExternItemList { | 1241 | pub struct ExternItemList { |
2530 | pub(crate) syntax: SyntaxNode, | 1242 | pub(crate) syntax: SyntaxNode, |
2531 | } | 1243 | } |
2532 | impl ast::ModuleItemOwner for ExternItemList {} | ||
2533 | impl ExternItemList { | 1244 | impl ExternItemList { |
2534 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 1245 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
2535 | pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } | 1246 | pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } |
2536 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1247 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
2537 | } | 1248 | } |
2538 | /// Extern block. | ||
2539 | /// | ||
2540 | /// ``` | ||
2541 | /// ❰ | ||
2542 | /// extern "C" { | ||
2543 | /// fn foo(); | ||
2544 | /// } | ||
2545 | /// ❱ | ||
2546 | /// | ||
2547 | /// ``` | ||
2548 | /// | ||
2549 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
2550 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2551 | pub struct ExternBlock { | ||
2552 | pub(crate) syntax: SyntaxNode, | ||
2553 | } | ||
2554 | impl ExternBlock { | ||
2555 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | ||
2556 | pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } | ||
2557 | } | ||
2558 | /// Meta item in an attribute. | ||
2559 | /// | ||
2560 | /// ``` | ||
2561 | /// #[❰ bar::baz = "42" ❱] | ||
2562 | /// #[❰ bruh(bruuh("true")) ❱] | ||
2563 | /// struct Foo; | ||
2564 | /// ``` | ||
2565 | /// | ||
2566 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax) | ||
2567 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1249 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2568 | pub struct MetaItem { | 1250 | pub struct MetaItem { |
2569 | pub(crate) syntax: SyntaxNode, | 1251 | pub(crate) syntax: SyntaxNode, |
@@ -2574,66 +1256,6 @@ impl MetaItem { | |||
2574 | pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } | 1256 | pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } |
2575 | pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } | 1257 | pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } |
2576 | } | 1258 | } |
2577 | /// Macro 2.0 definition. | ||
2578 | /// Their syntax is still WIP by rustc team... | ||
2579 | /// ``` | ||
2580 | /// ❰ | ||
2581 | /// macro foo { } | ||
2582 | /// ❱ | ||
2583 | /// ``` | ||
2584 | /// | ||
2585 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md) | ||
2586 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2587 | pub struct MacroDef { | ||
2588 | pub(crate) syntax: SyntaxNode, | ||
2589 | } | ||
2590 | impl MacroDef { | ||
2591 | pub fn name(&self) -> Option<Name> { support::child(&self.syntax) } | ||
2592 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
2593 | } | ||
2594 | /// Any kind of nominal type definition. | ||
2595 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2596 | pub enum NominalDef { | ||
2597 | StructDef(StructDef), | ||
2598 | EnumDef(EnumDef), | ||
2599 | UnionDef(UnionDef), | ||
2600 | } | ||
2601 | impl ast::NameOwner for NominalDef {} | ||
2602 | impl ast::TypeParamsOwner for NominalDef {} | ||
2603 | impl ast::AttrsOwner for NominalDef {} | ||
2604 | /// Any kind of **declared** generic parameter | ||
2605 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2606 | pub enum GenericParam { | ||
2607 | LifetimeParam(LifetimeParam), | ||
2608 | TypeParam(TypeParam), | ||
2609 | ConstParam(ConstParam), | ||
2610 | } | ||
2611 | /// Any kind of generic argument passed at instantiation site | ||
2612 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2613 | pub enum GenericArg { | ||
2614 | LifetimeArg(LifetimeArg), | ||
2615 | TypeArg(TypeArg), | ||
2616 | ConstArg(ConstArg), | ||
2617 | AssocTypeArg(AssocTypeArg), | ||
2618 | } | ||
2619 | /// Any kind of construct valid in type context | ||
2620 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2621 | pub enum TypeRef { | ||
2622 | ParenType(ParenType), | ||
2623 | TupleType(TupleType), | ||
2624 | NeverType(NeverType), | ||
2625 | PathType(PathType), | ||
2626 | PointerType(PointerType), | ||
2627 | ArrayType(ArrayType), | ||
2628 | SliceType(SliceType), | ||
2629 | ReferenceType(ReferenceType), | ||
2630 | PlaceholderType(PlaceholderType), | ||
2631 | FnPointerType(FnPointerType), | ||
2632 | ForType(ForType), | ||
2633 | ImplTraitType(ImplTraitType), | ||
2634 | DynTraitType(DynTraitType), | ||
2635 | } | ||
2636 | /// Any kind of top-level item that may appear in a module | ||
2637 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1259 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2638 | pub enum ModuleItem { | 1260 | pub enum ModuleItem { |
2639 | StructDef(StructDef), | 1261 | StructDef(StructDef), |
@@ -2651,32 +1273,28 @@ pub enum ModuleItem { | |||
2651 | MacroCall(MacroCall), | 1273 | MacroCall(MacroCall), |
2652 | ExternBlock(ExternBlock), | 1274 | ExternBlock(ExternBlock), |
2653 | } | 1275 | } |
2654 | impl ast::NameOwner for ModuleItem {} | ||
2655 | impl ast::AttrsOwner for ModuleItem {} | 1276 | impl ast::AttrsOwner for ModuleItem {} |
2656 | impl ast::VisibilityOwner for ModuleItem {} | ||
2657 | /// Any kind of item that may appear in an impl block | ||
2658 | /// | ||
2659 | /// // FIXME: impl blocks can also contain MacroCall | ||
2660 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1277 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2661 | pub enum AssocItem { | 1278 | pub enum TypeRef { |
2662 | FnDef(FnDef), | 1279 | ParenType(ParenType), |
2663 | TypeAliasDef(TypeAliasDef), | 1280 | TupleType(TupleType), |
2664 | ConstDef(ConstDef), | 1281 | NeverType(NeverType), |
1282 | PathType(PathType), | ||
1283 | PointerType(PointerType), | ||
1284 | ArrayType(ArrayType), | ||
1285 | SliceType(SliceType), | ||
1286 | ReferenceType(ReferenceType), | ||
1287 | PlaceholderType(PlaceholderType), | ||
1288 | FnPointerType(FnPointerType), | ||
1289 | ForType(ForType), | ||
1290 | ImplTraitType(ImplTraitType), | ||
1291 | DynTraitType(DynTraitType), | ||
2665 | } | 1292 | } |
2666 | impl ast::NameOwner for AssocItem {} | ||
2667 | impl ast::AttrsOwner for AssocItem {} | ||
2668 | /// Any kind of item that may appear in an extern block | ||
2669 | /// | ||
2670 | /// // FIXME: extern blocks can also contain MacroCall | ||
2671 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1293 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2672 | pub enum ExternItem { | 1294 | pub enum FieldDefList { |
2673 | FnDef(FnDef), | 1295 | RecordFieldDefList(RecordFieldDefList), |
2674 | StaticDef(StaticDef), | 1296 | TupleFieldDefList(TupleFieldDefList), |
2675 | } | 1297 | } |
2676 | impl ast::NameOwner for ExternItem {} | ||
2677 | impl ast::AttrsOwner for ExternItem {} | ||
2678 | impl ast::VisibilityOwner for ExternItem {} | ||
2679 | /// Any kind of expression | ||
2680 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1298 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2681 | pub enum Expr { | 1299 | pub enum Expr { |
2682 | TupleExpr(TupleExpr), | 1300 | TupleExpr(TupleExpr), |
@@ -2711,8 +1329,15 @@ pub enum Expr { | |||
2711 | MacroCall(MacroCall), | 1329 | MacroCall(MacroCall), |
2712 | BoxExpr(BoxExpr), | 1330 | BoxExpr(BoxExpr), |
2713 | } | 1331 | } |
2714 | impl ast::AttrsOwner for Expr {} | 1332 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2715 | /// Any kind of pattern | 1333 | pub enum AssocItem { |
1334 | FnDef(FnDef), | ||
1335 | TypeAliasDef(TypeAliasDef), | ||
1336 | ConstDef(ConstDef), | ||
1337 | } | ||
1338 | impl ast::AttrsOwner for AssocItem {} | ||
1339 | impl ast::NameOwner for AssocItem {} | ||
1340 | impl ast::VisibilityOwner for AssocItem {} | ||
2716 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1341 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2717 | pub enum Pat { | 1342 | pub enum Pat { |
2718 | OrPat(OrPat), | 1343 | OrPat(OrPat), |
@@ -2731,33 +1356,35 @@ pub enum Pat { | |||
2731 | LiteralPat(LiteralPat), | 1356 | LiteralPat(LiteralPat), |
2732 | MacroPat(MacroPat), | 1357 | MacroPat(MacroPat), |
2733 | } | 1358 | } |
2734 | /// Any kind of pattern that appears directly inside of the curly | ||
2735 | /// braces of a record pattern | ||
2736 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1359 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2737 | pub enum RecordInnerPat { | 1360 | pub enum Stmt { |
2738 | RecordFieldPat(RecordFieldPat), | 1361 | LetStmt(LetStmt), |
2739 | BindPat(BindPat), | 1362 | ExprStmt(ExprStmt), |
2740 | } | 1363 | } |
2741 | /// Any kind of input to an attribute | 1364 | impl ast::AttrsOwner for Stmt {} |
2742 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1365 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2743 | pub enum AttrInput { | 1366 | pub enum AttrInput { |
2744 | Literal(Literal), | 1367 | Literal(Literal), |
2745 | TokenTree(TokenTree), | 1368 | TokenTree(TokenTree), |
2746 | } | 1369 | } |
2747 | /// Any kind of statement | ||
2748 | /// Note: there are no empty statements, these are just represented as | ||
2749 | /// bare semicolons without a dedicated statement ast node. | ||
2750 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1370 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2751 | pub enum Stmt { | 1371 | pub enum ExternItem { |
2752 | LetStmt(LetStmt), | 1372 | FnDef(FnDef), |
2753 | ExprStmt(ExprStmt), | 1373 | StaticDef(StaticDef), |
2754 | } | 1374 | } |
2755 | /// Any kind of fields list (record or tuple field lists) | 1375 | impl ast::AttrsOwner for ExternItem {} |
1376 | impl ast::NameOwner for ExternItem {} | ||
1377 | impl ast::VisibilityOwner for ExternItem {} | ||
2756 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1378 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2757 | pub enum FieldDefList { | 1379 | pub enum AdtDef { |
2758 | RecordFieldDefList(RecordFieldDefList), | 1380 | StructDef(StructDef), |
2759 | TupleFieldDefList(TupleFieldDefList), | 1381 | EnumDef(EnumDef), |
1382 | UnionDef(UnionDef), | ||
2760 | } | 1383 | } |
1384 | impl ast::AttrsOwner for AdtDef {} | ||
1385 | impl ast::NameOwner for AdtDef {} | ||
1386 | impl ast::TypeParamsOwner for AdtDef {} | ||
1387 | impl ast::VisibilityOwner for AdtDef {} | ||
2761 | impl AstNode for SourceFile { | 1388 | impl AstNode for SourceFile { |
2762 | fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } | 1389 | fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } |
2763 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1390 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -2769,6 +1396,17 @@ impl AstNode for SourceFile { | |||
2769 | } | 1396 | } |
2770 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1397 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2771 | } | 1398 | } |
1399 | impl AstNode for Attr { | ||
1400 | fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR } | ||
1401 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1402 | if Self::can_cast(syntax.kind()) { | ||
1403 | Some(Self { syntax }) | ||
1404 | } else { | ||
1405 | None | ||
1406 | } | ||
1407 | } | ||
1408 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1409 | } | ||
2772 | impl AstNode for FnDef { | 1410 | impl AstNode for FnDef { |
2773 | fn can_cast(kind: SyntaxKind) -> bool { kind == FN_DEF } | 1411 | fn can_cast(kind: SyntaxKind) -> bool { kind == FN_DEF } |
2774 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1412 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -2780,6 +1418,61 @@ impl AstNode for FnDef { | |||
2780 | } | 1418 | } |
2781 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1419 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2782 | } | 1420 | } |
1421 | impl AstNode for Visibility { | ||
1422 | fn can_cast(kind: SyntaxKind) -> bool { kind == VISIBILITY } | ||
1423 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1424 | if Self::can_cast(syntax.kind()) { | ||
1425 | Some(Self { syntax }) | ||
1426 | } else { | ||
1427 | None | ||
1428 | } | ||
1429 | } | ||
1430 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1431 | } | ||
1432 | impl AstNode for Abi { | ||
1433 | fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } | ||
1434 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1435 | if Self::can_cast(syntax.kind()) { | ||
1436 | Some(Self { syntax }) | ||
1437 | } else { | ||
1438 | None | ||
1439 | } | ||
1440 | } | ||
1441 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1442 | } | ||
1443 | impl AstNode for Name { | ||
1444 | fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } | ||
1445 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1446 | if Self::can_cast(syntax.kind()) { | ||
1447 | Some(Self { syntax }) | ||
1448 | } else { | ||
1449 | None | ||
1450 | } | ||
1451 | } | ||
1452 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1453 | } | ||
1454 | impl AstNode for TypeParamList { | ||
1455 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_PARAM_LIST } | ||
1456 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1457 | if Self::can_cast(syntax.kind()) { | ||
1458 | Some(Self { syntax }) | ||
1459 | } else { | ||
1460 | None | ||
1461 | } | ||
1462 | } | ||
1463 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1464 | } | ||
1465 | impl AstNode for ParamList { | ||
1466 | fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } | ||
1467 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1468 | if Self::can_cast(syntax.kind()) { | ||
1469 | Some(Self { syntax }) | ||
1470 | } else { | ||
1471 | None | ||
1472 | } | ||
1473 | } | ||
1474 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1475 | } | ||
2783 | impl AstNode for RetType { | 1476 | impl AstNode for RetType { |
2784 | fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE } | 1477 | fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE } |
2785 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1478 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -2791,8 +1484,8 @@ impl AstNode for RetType { | |||
2791 | } | 1484 | } |
2792 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1485 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2793 | } | 1486 | } |
2794 | impl AstNode for StructDef { | 1487 | impl AstNode for WhereClause { |
2795 | fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT_DEF } | 1488 | fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE } |
2796 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1489 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2797 | if Self::can_cast(syntax.kind()) { | 1490 | if Self::can_cast(syntax.kind()) { |
2798 | Some(Self { syntax }) | 1491 | Some(Self { syntax }) |
@@ -2802,8 +1495,8 @@ impl AstNode for StructDef { | |||
2802 | } | 1495 | } |
2803 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1496 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2804 | } | 1497 | } |
2805 | impl AstNode for UnionDef { | 1498 | impl AstNode for BlockExpr { |
2806 | fn can_cast(kind: SyntaxKind) -> bool { kind == UNION_DEF } | 1499 | fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } |
2807 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1500 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2808 | if Self::can_cast(syntax.kind()) { | 1501 | if Self::can_cast(syntax.kind()) { |
2809 | Some(Self { syntax }) | 1502 | Some(Self { syntax }) |
@@ -2813,8 +1506,8 @@ impl AstNode for UnionDef { | |||
2813 | } | 1506 | } |
2814 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1507 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2815 | } | 1508 | } |
2816 | impl AstNode for RecordFieldDefList { | 1509 | impl AstNode for StructDef { |
2817 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } | 1510 | fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT_DEF } |
2818 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1511 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2819 | if Self::can_cast(syntax.kind()) { | 1512 | if Self::can_cast(syntax.kind()) { |
2820 | Some(Self { syntax }) | 1513 | Some(Self { syntax }) |
@@ -2824,8 +1517,8 @@ impl AstNode for RecordFieldDefList { | |||
2824 | } | 1517 | } |
2825 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1518 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2826 | } | 1519 | } |
2827 | impl AstNode for RecordFieldDef { | 1520 | impl AstNode for RecordFieldDefList { |
2828 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF } | 1521 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } |
2829 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1522 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2830 | if Self::can_cast(syntax.kind()) { | 1523 | if Self::can_cast(syntax.kind()) { |
2831 | Some(Self { syntax }) | 1524 | Some(Self { syntax }) |
@@ -2846,6 +1539,28 @@ impl AstNode for TupleFieldDefList { | |||
2846 | } | 1539 | } |
2847 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1540 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2848 | } | 1541 | } |
1542 | impl AstNode for UnionDef { | ||
1543 | fn can_cast(kind: SyntaxKind) -> bool { kind == UNION_DEF } | ||
1544 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1545 | if Self::can_cast(syntax.kind()) { | ||
1546 | Some(Self { syntax }) | ||
1547 | } else { | ||
1548 | None | ||
1549 | } | ||
1550 | } | ||
1551 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1552 | } | ||
1553 | impl AstNode for RecordFieldDef { | ||
1554 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF } | ||
1555 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1556 | if Self::can_cast(syntax.kind()) { | ||
1557 | Some(Self { syntax }) | ||
1558 | } else { | ||
1559 | None | ||
1560 | } | ||
1561 | } | ||
1562 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1563 | } | ||
2849 | impl AstNode for TupleFieldDef { | 1564 | impl AstNode for TupleFieldDef { |
2850 | fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF } | 1565 | fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF } |
2851 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1566 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -2901,8 +1616,8 @@ impl AstNode for TraitDef { | |||
2901 | } | 1616 | } |
2902 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1617 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2903 | } | 1618 | } |
2904 | impl AstNode for Module { | 1619 | impl AstNode for TypeBoundList { |
2905 | fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } | 1620 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST } |
2906 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1621 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2907 | if Self::can_cast(syntax.kind()) { | 1622 | if Self::can_cast(syntax.kind()) { |
2908 | Some(Self { syntax }) | 1623 | Some(Self { syntax }) |
@@ -2923,6 +1638,17 @@ impl AstNode for ItemList { | |||
2923 | } | 1638 | } |
2924 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1639 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2925 | } | 1640 | } |
1641 | impl AstNode for Module { | ||
1642 | fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } | ||
1643 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1644 | if Self::can_cast(syntax.kind()) { | ||
1645 | Some(Self { syntax }) | ||
1646 | } else { | ||
1647 | None | ||
1648 | } | ||
1649 | } | ||
1650 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1651 | } | ||
2926 | impl AstNode for ConstDef { | 1652 | impl AstNode for ConstDef { |
2927 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF } | 1653 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF } |
2928 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1654 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3011,6 +1737,17 @@ impl AstNode for PathType { | |||
3011 | } | 1737 | } |
3012 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1738 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3013 | } | 1739 | } |
1740 | impl AstNode for Path { | ||
1741 | fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } | ||
1742 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1743 | if Self::can_cast(syntax.kind()) { | ||
1744 | Some(Self { syntax }) | ||
1745 | } else { | ||
1746 | None | ||
1747 | } | ||
1748 | } | ||
1749 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1750 | } | ||
3014 | impl AstNode for PointerType { | 1751 | impl AstNode for PointerType { |
3015 | fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE } | 1752 | fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE } |
3016 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1753 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3176,8 +1913,8 @@ impl AstNode for IfExpr { | |||
3176 | } | 1913 | } |
3177 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1914 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3178 | } | 1915 | } |
3179 | impl AstNode for LoopExpr { | 1916 | impl AstNode for Condition { |
3180 | fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } | 1917 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONDITION } |
3181 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1918 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3182 | if Self::can_cast(syntax.kind()) { | 1919 | if Self::can_cast(syntax.kind()) { |
3183 | Some(Self { syntax }) | 1920 | Some(Self { syntax }) |
@@ -3198,6 +1935,28 @@ impl AstNode for EffectExpr { | |||
3198 | } | 1935 | } |
3199 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 1936 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3200 | } | 1937 | } |
1938 | impl AstNode for Label { | ||
1939 | fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL } | ||
1940 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1941 | if Self::can_cast(syntax.kind()) { | ||
1942 | Some(Self { syntax }) | ||
1943 | } else { | ||
1944 | None | ||
1945 | } | ||
1946 | } | ||
1947 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1948 | } | ||
1949 | impl AstNode for LoopExpr { | ||
1950 | fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } | ||
1951 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1952 | if Self::can_cast(syntax.kind()) { | ||
1953 | Some(Self { syntax }) | ||
1954 | } else { | ||
1955 | None | ||
1956 | } | ||
1957 | } | ||
1958 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1959 | } | ||
3201 | impl AstNode for ForExpr { | 1960 | impl AstNode for ForExpr { |
3202 | fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } | 1961 | fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } |
3203 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1962 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3242,8 +2001,8 @@ impl AstNode for BreakExpr { | |||
3242 | } | 2001 | } |
3243 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2002 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3244 | } | 2003 | } |
3245 | impl AstNode for Label { | 2004 | impl AstNode for ReturnExpr { |
3246 | fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL } | 2005 | fn can_cast(kind: SyntaxKind) -> bool { kind == RETURN_EXPR } |
3247 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2006 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3248 | if Self::can_cast(syntax.kind()) { | 2007 | if Self::can_cast(syntax.kind()) { |
3249 | Some(Self { syntax }) | 2008 | Some(Self { syntax }) |
@@ -3253,8 +2012,8 @@ impl AstNode for Label { | |||
3253 | } | 2012 | } |
3254 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2013 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3255 | } | 2014 | } |
3256 | impl AstNode for BlockExpr { | 2015 | impl AstNode for CallExpr { |
3257 | fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } | 2016 | fn can_cast(kind: SyntaxKind) -> bool { kind == CALL_EXPR } |
3258 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2017 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3259 | if Self::can_cast(syntax.kind()) { | 2018 | if Self::can_cast(syntax.kind()) { |
3260 | Some(Self { syntax }) | 2019 | Some(Self { syntax }) |
@@ -3264,8 +2023,8 @@ impl AstNode for BlockExpr { | |||
3264 | } | 2023 | } |
3265 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2024 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3266 | } | 2025 | } |
3267 | impl AstNode for ReturnExpr { | 2026 | impl AstNode for ArgList { |
3268 | fn can_cast(kind: SyntaxKind) -> bool { kind == RETURN_EXPR } | 2027 | fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST } |
3269 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2028 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3270 | if Self::can_cast(syntax.kind()) { | 2029 | if Self::can_cast(syntax.kind()) { |
3271 | Some(Self { syntax }) | 2030 | Some(Self { syntax }) |
@@ -3275,8 +2034,8 @@ impl AstNode for ReturnExpr { | |||
3275 | } | 2034 | } |
3276 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2035 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3277 | } | 2036 | } |
3278 | impl AstNode for CallExpr { | 2037 | impl AstNode for MethodCallExpr { |
3279 | fn can_cast(kind: SyntaxKind) -> bool { kind == CALL_EXPR } | 2038 | fn can_cast(kind: SyntaxKind) -> bool { kind == METHOD_CALL_EXPR } |
3280 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2039 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3281 | if Self::can_cast(syntax.kind()) { | 2040 | if Self::can_cast(syntax.kind()) { |
3282 | Some(Self { syntax }) | 2041 | Some(Self { syntax }) |
@@ -3286,8 +2045,8 @@ impl AstNode for CallExpr { | |||
3286 | } | 2045 | } |
3287 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2046 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3288 | } | 2047 | } |
3289 | impl AstNode for MethodCallExpr { | 2048 | impl AstNode for NameRef { |
3290 | fn can_cast(kind: SyntaxKind) -> bool { kind == METHOD_CALL_EXPR } | 2049 | fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF } |
3291 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2050 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3292 | if Self::can_cast(syntax.kind()) { | 2051 | if Self::can_cast(syntax.kind()) { |
3293 | Some(Self { syntax }) | 2052 | Some(Self { syntax }) |
@@ -3297,8 +2056,8 @@ impl AstNode for MethodCallExpr { | |||
3297 | } | 2056 | } |
3298 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2057 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3299 | } | 2058 | } |
3300 | impl AstNode for IndexExpr { | 2059 | impl AstNode for TypeArgList { |
3301 | fn can_cast(kind: SyntaxKind) -> bool { kind == INDEX_EXPR } | 2060 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG_LIST } |
3302 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2061 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3303 | if Self::can_cast(syntax.kind()) { | 2062 | if Self::can_cast(syntax.kind()) { |
3304 | Some(Self { syntax }) | 2063 | Some(Self { syntax }) |
@@ -3319,6 +2078,17 @@ impl AstNode for FieldExpr { | |||
3319 | } | 2078 | } |
3320 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2079 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3321 | } | 2080 | } |
2081 | impl AstNode for IndexExpr { | ||
2082 | fn can_cast(kind: SyntaxKind) -> bool { kind == INDEX_EXPR } | ||
2083 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2084 | if Self::can_cast(syntax.kind()) { | ||
2085 | Some(Self { syntax }) | ||
2086 | } else { | ||
2087 | None | ||
2088 | } | ||
2089 | } | ||
2090 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2091 | } | ||
3322 | impl AstNode for AwaitExpr { | 2092 | impl AstNode for AwaitExpr { |
3323 | fn can_cast(kind: SyntaxKind) -> bool { kind == AWAIT_EXPR } | 2093 | fn can_cast(kind: SyntaxKind) -> bool { kind == AWAIT_EXPR } |
3324 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2094 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3627,6 +2397,17 @@ impl AstNode for MacroPat { | |||
3627 | } | 2397 | } |
3628 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2398 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3629 | } | 2399 | } |
2400 | impl AstNode for MacroCall { | ||
2401 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } | ||
2402 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2403 | if Self::can_cast(syntax.kind()) { | ||
2404 | Some(Self { syntax }) | ||
2405 | } else { | ||
2406 | None | ||
2407 | } | ||
2408 | } | ||
2409 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2410 | } | ||
3630 | impl AstNode for RecordPat { | 2411 | impl AstNode for RecordPat { |
3631 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT } | 2412 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT } |
3632 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2413 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3682,41 +2463,8 @@ impl AstNode for TuplePat { | |||
3682 | } | 2463 | } |
3683 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2464 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3684 | } | 2465 | } |
3685 | impl AstNode for Visibility { | 2466 | impl AstNode for TokenTree { |
3686 | fn can_cast(kind: SyntaxKind) -> bool { kind == VISIBILITY } | 2467 | fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } |
3687 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3688 | if Self::can_cast(syntax.kind()) { | ||
3689 | Some(Self { syntax }) | ||
3690 | } else { | ||
3691 | None | ||
3692 | } | ||
3693 | } | ||
3694 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3695 | } | ||
3696 | impl AstNode for Name { | ||
3697 | fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } | ||
3698 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3699 | if Self::can_cast(syntax.kind()) { | ||
3700 | Some(Self { syntax }) | ||
3701 | } else { | ||
3702 | None | ||
3703 | } | ||
3704 | } | ||
3705 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3706 | } | ||
3707 | impl AstNode for NameRef { | ||
3708 | fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF } | ||
3709 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3710 | if Self::can_cast(syntax.kind()) { | ||
3711 | Some(Self { syntax }) | ||
3712 | } else { | ||
3713 | None | ||
3714 | } | ||
3715 | } | ||
3716 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3717 | } | ||
3718 | impl AstNode for MacroCall { | ||
3719 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } | ||
3720 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2468 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3721 | if Self::can_cast(syntax.kind()) { | 2469 | if Self::can_cast(syntax.kind()) { |
3722 | Some(Self { syntax }) | 2470 | Some(Self { syntax }) |
@@ -3726,8 +2474,8 @@ impl AstNode for MacroCall { | |||
3726 | } | 2474 | } |
3727 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2475 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3728 | } | 2476 | } |
3729 | impl AstNode for Attr { | 2477 | impl AstNode for MacroDef { |
3730 | fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR } | 2478 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF } |
3731 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2479 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3732 | if Self::can_cast(syntax.kind()) { | 2480 | if Self::can_cast(syntax.kind()) { |
3733 | Some(Self { syntax }) | 2481 | Some(Self { syntax }) |
@@ -3737,8 +2485,8 @@ impl AstNode for Attr { | |||
3737 | } | 2485 | } |
3738 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2486 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3739 | } | 2487 | } |
3740 | impl AstNode for TokenTree { | 2488 | impl AstNode for MacroItems { |
3741 | fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } | 2489 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } |
3742 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2490 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3743 | if Self::can_cast(syntax.kind()) { | 2491 | if Self::can_cast(syntax.kind()) { |
3744 | Some(Self { syntax }) | 2492 | Some(Self { syntax }) |
@@ -3748,8 +2496,8 @@ impl AstNode for TokenTree { | |||
3748 | } | 2496 | } |
3749 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2497 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3750 | } | 2498 | } |
3751 | impl AstNode for TypeParamList { | 2499 | impl AstNode for MacroStmts { |
3752 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_PARAM_LIST } | 2500 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } |
3753 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2501 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3754 | if Self::can_cast(syntax.kind()) { | 2502 | if Self::can_cast(syntax.kind()) { |
3755 | Some(Self { syntax }) | 2503 | Some(Self { syntax }) |
@@ -3770,17 +2518,6 @@ impl AstNode for TypeParam { | |||
3770 | } | 2518 | } |
3771 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2519 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3772 | } | 2520 | } |
3773 | impl AstNode for ConstParam { | ||
3774 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_PARAM } | ||
3775 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3776 | if Self::can_cast(syntax.kind()) { | ||
3777 | Some(Self { syntax }) | ||
3778 | } else { | ||
3779 | None | ||
3780 | } | ||
3781 | } | ||
3782 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3783 | } | ||
3784 | impl AstNode for LifetimeParam { | 2521 | impl AstNode for LifetimeParam { |
3785 | fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_PARAM } | 2522 | fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_PARAM } |
3786 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2523 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3792,8 +2529,8 @@ impl AstNode for LifetimeParam { | |||
3792 | } | 2529 | } |
3793 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2530 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3794 | } | 2531 | } |
3795 | impl AstNode for TypeBound { | 2532 | impl AstNode for ConstParam { |
3796 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } | 2533 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_PARAM } |
3797 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2534 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3798 | if Self::can_cast(syntax.kind()) { | 2535 | if Self::can_cast(syntax.kind()) { |
3799 | Some(Self { syntax }) | 2536 | Some(Self { syntax }) |
@@ -3803,8 +2540,8 @@ impl AstNode for TypeBound { | |||
3803 | } | 2540 | } |
3804 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2541 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3805 | } | 2542 | } |
3806 | impl AstNode for TypeBoundList { | 2543 | impl AstNode for TypeBound { |
3807 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST } | 2544 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } |
3808 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2545 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3809 | if Self::can_cast(syntax.kind()) { | 2546 | if Self::can_cast(syntax.kind()) { |
3810 | Some(Self { syntax }) | 2547 | Some(Self { syntax }) |
@@ -3825,28 +2562,6 @@ impl AstNode for WherePred { | |||
3825 | } | 2562 | } |
3826 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2563 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3827 | } | 2564 | } |
3828 | impl AstNode for WhereClause { | ||
3829 | fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE } | ||
3830 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3831 | if Self::can_cast(syntax.kind()) { | ||
3832 | Some(Self { syntax }) | ||
3833 | } else { | ||
3834 | None | ||
3835 | } | ||
3836 | } | ||
3837 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3838 | } | ||
3839 | impl AstNode for Abi { | ||
3840 | fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } | ||
3841 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3842 | if Self::can_cast(syntax.kind()) { | ||
3843 | Some(Self { syntax }) | ||
3844 | } else { | ||
3845 | None | ||
3846 | } | ||
3847 | } | ||
3848 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3849 | } | ||
3850 | impl AstNode for ExprStmt { | 2565 | impl AstNode for ExprStmt { |
3851 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } | 2566 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } |
3852 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2567 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3869,28 +2584,6 @@ impl AstNode for LetStmt { | |||
3869 | } | 2584 | } |
3870 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2585 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3871 | } | 2586 | } |
3872 | impl AstNode for Condition { | ||
3873 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONDITION } | ||
3874 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3875 | if Self::can_cast(syntax.kind()) { | ||
3876 | Some(Self { syntax }) | ||
3877 | } else { | ||
3878 | None | ||
3879 | } | ||
3880 | } | ||
3881 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3882 | } | ||
3883 | impl AstNode for ParamList { | ||
3884 | fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } | ||
3885 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3886 | if Self::can_cast(syntax.kind()) { | ||
3887 | Some(Self { syntax }) | ||
3888 | } else { | ||
3889 | None | ||
3890 | } | ||
3891 | } | ||
3892 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3893 | } | ||
3894 | impl AstNode for SelfParam { | 2587 | impl AstNode for SelfParam { |
3895 | fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM } | 2588 | fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM } |
3896 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2589 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3935,17 +2628,6 @@ impl AstNode for UseTree { | |||
3935 | } | 2628 | } |
3936 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2629 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3937 | } | 2630 | } |
3938 | impl AstNode for Alias { | ||
3939 | fn can_cast(kind: SyntaxKind) -> bool { kind == ALIAS } | ||
3940 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3941 | if Self::can_cast(syntax.kind()) { | ||
3942 | Some(Self { syntax }) | ||
3943 | } else { | ||
3944 | None | ||
3945 | } | ||
3946 | } | ||
3947 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3948 | } | ||
3949 | impl AstNode for UseTreeList { | 2631 | impl AstNode for UseTreeList { |
3950 | fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST } | 2632 | fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST } |
3951 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2633 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3957,19 +2639,8 @@ impl AstNode for UseTreeList { | |||
3957 | } | 2639 | } |
3958 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2640 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3959 | } | 2641 | } |
3960 | impl AstNode for ExternCrateItem { | 2642 | impl AstNode for Alias { |
3961 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE_ITEM } | 2643 | fn can_cast(kind: SyntaxKind) -> bool { kind == ALIAS } |
3962 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3963 | if Self::can_cast(syntax.kind()) { | ||
3964 | Some(Self { syntax }) | ||
3965 | } else { | ||
3966 | None | ||
3967 | } | ||
3968 | } | ||
3969 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3970 | } | ||
3971 | impl AstNode for ArgList { | ||
3972 | fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST } | ||
3973 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2644 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3974 | if Self::can_cast(syntax.kind()) { | 2645 | if Self::can_cast(syntax.kind()) { |
3975 | Some(Self { syntax }) | 2646 | Some(Self { syntax }) |
@@ -3979,8 +2650,8 @@ impl AstNode for ArgList { | |||
3979 | } | 2650 | } |
3980 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2651 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3981 | } | 2652 | } |
3982 | impl AstNode for Path { | 2653 | impl AstNode for ExternCrateItem { |
3983 | fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } | 2654 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE_ITEM } |
3984 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2655 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3985 | if Self::can_cast(syntax.kind()) { | 2656 | if Self::can_cast(syntax.kind()) { |
3986 | Some(Self { syntax }) | 2657 | Some(Self { syntax }) |
@@ -4001,17 +2672,6 @@ impl AstNode for PathSegment { | |||
4001 | } | 2672 | } |
4002 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2673 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4003 | } | 2674 | } |
4004 | impl AstNode for TypeArgList { | ||
4005 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG_LIST } | ||
4006 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
4007 | if Self::can_cast(syntax.kind()) { | ||
4008 | Some(Self { syntax }) | ||
4009 | } else { | ||
4010 | None | ||
4011 | } | ||
4012 | } | ||
4013 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
4014 | } | ||
4015 | impl AstNode for TypeArg { | 2675 | impl AstNode for TypeArg { |
4016 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG } | 2676 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG } |
4017 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2677 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -4023,17 +2683,6 @@ impl AstNode for TypeArg { | |||
4023 | } | 2683 | } |
4024 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2684 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4025 | } | 2685 | } |
4026 | impl AstNode for AssocTypeArg { | ||
4027 | fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG } | ||
4028 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
4029 | if Self::can_cast(syntax.kind()) { | ||
4030 | Some(Self { syntax }) | ||
4031 | } else { | ||
4032 | None | ||
4033 | } | ||
4034 | } | ||
4035 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
4036 | } | ||
4037 | impl AstNode for LifetimeArg { | 2686 | impl AstNode for LifetimeArg { |
4038 | fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG } | 2687 | fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG } |
4039 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2688 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -4045,8 +2694,8 @@ impl AstNode for LifetimeArg { | |||
4045 | } | 2694 | } |
4046 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2695 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4047 | } | 2696 | } |
4048 | impl AstNode for ConstArg { | 2697 | impl AstNode for AssocTypeArg { |
4049 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG } | 2698 | fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG } |
4050 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2699 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
4051 | if Self::can_cast(syntax.kind()) { | 2700 | if Self::can_cast(syntax.kind()) { |
4052 | Some(Self { syntax }) | 2701 | Some(Self { syntax }) |
@@ -4056,8 +2705,8 @@ impl AstNode for ConstArg { | |||
4056 | } | 2705 | } |
4057 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2706 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4058 | } | 2707 | } |
4059 | impl AstNode for MacroItems { | 2708 | impl AstNode for ConstArg { |
4060 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } | 2709 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG } |
4061 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2710 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
4062 | if Self::can_cast(syntax.kind()) { | 2711 | if Self::can_cast(syntax.kind()) { |
4063 | Some(Self { syntax }) | 2712 | Some(Self { syntax }) |
@@ -4067,8 +2716,8 @@ impl AstNode for MacroItems { | |||
4067 | } | 2716 | } |
4068 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2717 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4069 | } | 2718 | } |
4070 | impl AstNode for MacroStmts { | 2719 | impl AstNode for ExternBlock { |
4071 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } | 2720 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK } |
4072 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2721 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
4073 | if Self::can_cast(syntax.kind()) { | 2722 | if Self::can_cast(syntax.kind()) { |
4074 | Some(Self { syntax }) | 2723 | Some(Self { syntax }) |
@@ -4089,17 +2738,6 @@ impl AstNode for ExternItemList { | |||
4089 | } | 2738 | } |
4090 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2739 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4091 | } | 2740 | } |
4092 | impl AstNode for ExternBlock { | ||
4093 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK } | ||
4094 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
4095 | if Self::can_cast(syntax.kind()) { | ||
4096 | Some(Self { syntax }) | ||
4097 | } else { | ||
4098 | None | ||
4099 | } | ||
4100 | } | ||
4101 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
4102 | } | ||
4103 | impl AstNode for MetaItem { | 2741 | impl AstNode for MetaItem { |
4104 | fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM } | 2742 | fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM } |
4105 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2743 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -4111,118 +2749,93 @@ impl AstNode for MetaItem { | |||
4111 | } | 2749 | } |
4112 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 2750 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4113 | } | 2751 | } |
4114 | impl AstNode for MacroDef { | 2752 | impl From<StructDef> for ModuleItem { |
4115 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF } | 2753 | fn from(node: StructDef) -> ModuleItem { ModuleItem::StructDef(node) } |
4116 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
4117 | if Self::can_cast(syntax.kind()) { | ||
4118 | Some(Self { syntax }) | ||
4119 | } else { | ||
4120 | None | ||
4121 | } | ||
4122 | } | ||
4123 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
4124 | } | 2754 | } |
4125 | impl From<StructDef> for NominalDef { | 2755 | impl From<UnionDef> for ModuleItem { |
4126 | fn from(node: StructDef) -> NominalDef { NominalDef::StructDef(node) } | 2756 | fn from(node: UnionDef) -> ModuleItem { ModuleItem::UnionDef(node) } |
4127 | } | 2757 | } |
4128 | impl From<EnumDef> for NominalDef { | 2758 | impl From<EnumDef> for ModuleItem { |
4129 | fn from(node: EnumDef) -> NominalDef { NominalDef::EnumDef(node) } | 2759 | fn from(node: EnumDef) -> ModuleItem { ModuleItem::EnumDef(node) } |
4130 | } | 2760 | } |
4131 | impl From<UnionDef> for NominalDef { | 2761 | impl From<FnDef> for ModuleItem { |
4132 | fn from(node: UnionDef) -> NominalDef { NominalDef::UnionDef(node) } | 2762 | fn from(node: FnDef) -> ModuleItem { ModuleItem::FnDef(node) } |
4133 | } | 2763 | } |
4134 | impl AstNode for NominalDef { | 2764 | impl From<TraitDef> for ModuleItem { |
4135 | fn can_cast(kind: SyntaxKind) -> bool { | 2765 | fn from(node: TraitDef) -> ModuleItem { ModuleItem::TraitDef(node) } |
4136 | match kind { | ||
4137 | STRUCT_DEF | ENUM_DEF | UNION_DEF => true, | ||
4138 | _ => false, | ||
4139 | } | ||
4140 | } | ||
4141 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
4142 | let res = match syntax.kind() { | ||
4143 | STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }), | ||
4144 | ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }), | ||
4145 | UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }), | ||
4146 | _ => return None, | ||
4147 | }; | ||
4148 | Some(res) | ||
4149 | } | ||
4150 | fn syntax(&self) -> &SyntaxNode { | ||
4151 | match self { | ||
4152 | NominalDef::StructDef(it) => &it.syntax, | ||
4153 | NominalDef::EnumDef(it) => &it.syntax, | ||
4154 | NominalDef::UnionDef(it) => &it.syntax, | ||
4155 | } | ||
4156 | } | ||
4157 | } | 2766 | } |
4158 | impl From<LifetimeParam> for GenericParam { | 2767 | impl From<TypeAliasDef> for ModuleItem { |
4159 | fn from(node: LifetimeParam) -> GenericParam { GenericParam::LifetimeParam(node) } | 2768 | fn from(node: TypeAliasDef) -> ModuleItem { ModuleItem::TypeAliasDef(node) } |
4160 | } | 2769 | } |
4161 | impl From<TypeParam> for GenericParam { | 2770 | impl From<ImplDef> for ModuleItem { |
4162 | fn from(node: TypeParam) -> GenericParam { GenericParam::TypeParam(node) } | 2771 | fn from(node: ImplDef) -> ModuleItem { ModuleItem::ImplDef(node) } |
4163 | } | 2772 | } |
4164 | impl From<ConstParam> for GenericParam { | 2773 | impl From<UseItem> for ModuleItem { |
4165 | fn from(node: ConstParam) -> GenericParam { GenericParam::ConstParam(node) } | 2774 | fn from(node: UseItem) -> ModuleItem { ModuleItem::UseItem(node) } |
4166 | } | 2775 | } |
4167 | impl AstNode for GenericParam { | 2776 | impl From<ExternCrateItem> for ModuleItem { |
4168 | fn can_cast(kind: SyntaxKind) -> bool { | 2777 | fn from(node: ExternCrateItem) -> ModuleItem { ModuleItem::ExternCrateItem(node) } |
4169 | match kind { | ||
4170 | LIFETIME_PARAM | TYPE_PARAM | CONST_PARAM => true, | ||
4171 | _ => false, | ||
4172 | } | ||
4173 | } | ||
4174 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
4175 | let res = match syntax.kind() { | ||
4176 | LIFETIME_PARAM => GenericParam::LifetimeParam(LifetimeParam { syntax }), | ||
4177 | TYPE_PARAM => GenericParam::TypeParam(TypeParam { syntax }), | ||
4178 | CONST_PARAM => GenericParam::ConstParam(ConstParam { syntax }), | ||
4179 | _ => return None, | ||
4180 | }; | ||
4181 | Some(res) | ||
4182 | } | ||
4183 | fn syntax(&self) -> &SyntaxNode { | ||
4184 | match self { | ||
4185 | GenericParam::LifetimeParam(it) => &it.syntax, | ||
4186 | GenericParam::TypeParam(it) => &it.syntax, | ||
4187 | GenericParam::ConstParam(it) => &it.syntax, | ||
4188 | } | ||
4189 | } | ||
4190 | } | 2778 | } |
4191 | impl From<LifetimeArg> for GenericArg { | 2779 | impl From<ConstDef> for ModuleItem { |
4192 | fn from(node: LifetimeArg) -> GenericArg { GenericArg::LifetimeArg(node) } | 2780 | fn from(node: ConstDef) -> ModuleItem { ModuleItem::ConstDef(node) } |
2781 | } | ||
2782 | impl From<StaticDef> for ModuleItem { | ||
2783 | fn from(node: StaticDef) -> ModuleItem { ModuleItem::StaticDef(node) } | ||
4193 | } | 2784 | } |
4194 | impl From<TypeArg> for GenericArg { | 2785 | impl From<Module> for ModuleItem { |
4195 | fn from(node: TypeArg) -> GenericArg { GenericArg::TypeArg(node) } | 2786 | fn from(node: Module) -> ModuleItem { ModuleItem::Module(node) } |
4196 | } | 2787 | } |
4197 | impl From<ConstArg> for GenericArg { | 2788 | impl From<MacroCall> for ModuleItem { |
4198 | fn from(node: ConstArg) -> GenericArg { GenericArg::ConstArg(node) } | 2789 | fn from(node: MacroCall) -> ModuleItem { ModuleItem::MacroCall(node) } |
4199 | } | 2790 | } |
4200 | impl From<AssocTypeArg> for GenericArg { | 2791 | impl From<ExternBlock> for ModuleItem { |
4201 | fn from(node: AssocTypeArg) -> GenericArg { GenericArg::AssocTypeArg(node) } | 2792 | fn from(node: ExternBlock) -> ModuleItem { ModuleItem::ExternBlock(node) } |
4202 | } | 2793 | } |
4203 | impl AstNode for GenericArg { | 2794 | impl AstNode for ModuleItem { |
4204 | fn can_cast(kind: SyntaxKind) -> bool { | 2795 | fn can_cast(kind: SyntaxKind) -> bool { |
4205 | match kind { | 2796 | match kind { |
4206 | LIFETIME_ARG | TYPE_ARG | CONST_ARG | ASSOC_TYPE_ARG => true, | 2797 | STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF |
2798 | | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL | ||
2799 | | EXTERN_BLOCK => true, | ||
4207 | _ => false, | 2800 | _ => false, |
4208 | } | 2801 | } |
4209 | } | 2802 | } |
4210 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2803 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
4211 | let res = match syntax.kind() { | 2804 | let res = match syntax.kind() { |
4212 | LIFETIME_ARG => GenericArg::LifetimeArg(LifetimeArg { syntax }), | 2805 | STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }), |
4213 | TYPE_ARG => GenericArg::TypeArg(TypeArg { syntax }), | 2806 | UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }), |
4214 | CONST_ARG => GenericArg::ConstArg(ConstArg { syntax }), | 2807 | ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }), |
4215 | ASSOC_TYPE_ARG => GenericArg::AssocTypeArg(AssocTypeArg { syntax }), | 2808 | FN_DEF => ModuleItem::FnDef(FnDef { syntax }), |
2809 | TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }), | ||
2810 | TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }), | ||
2811 | IMPL_DEF => ModuleItem::ImplDef(ImplDef { syntax }), | ||
2812 | USE_ITEM => ModuleItem::UseItem(UseItem { syntax }), | ||
2813 | EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }), | ||
2814 | CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), | ||
2815 | STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), | ||
2816 | MODULE => ModuleItem::Module(Module { syntax }), | ||
2817 | MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }), | ||
2818 | EXTERN_BLOCK => ModuleItem::ExternBlock(ExternBlock { syntax }), | ||
4216 | _ => return None, | 2819 | _ => return None, |
4217 | }; | 2820 | }; |
4218 | Some(res) | 2821 | Some(res) |
4219 | } | 2822 | } |
4220 | fn syntax(&self) -> &SyntaxNode { | 2823 | fn syntax(&self) -> &SyntaxNode { |
4221 | match self { | 2824 | match self { |
4222 | GenericArg::LifetimeArg(it) => &it.syntax, | 2825 | ModuleItem::StructDef(it) => &it.syntax, |
4223 | GenericArg::TypeArg(it) => &it.syntax, | 2826 | ModuleItem::UnionDef(it) => &it.syntax, |
4224 | GenericArg::ConstArg(it) => &it.syntax, | 2827 | ModuleItem::EnumDef(it) => &it.syntax, |
4225 | GenericArg::AssocTypeArg(it) => &it.syntax, | 2828 | ModuleItem::FnDef(it) => &it.syntax, |
2829 | ModuleItem::TraitDef(it) => &it.syntax, | ||
2830 | ModuleItem::TypeAliasDef(it) => &it.syntax, | ||
2831 | ModuleItem::ImplDef(it) => &it.syntax, | ||
2832 | ModuleItem::UseItem(it) => &it.syntax, | ||
2833 | ModuleItem::ExternCrateItem(it) => &it.syntax, | ||
2834 | ModuleItem::ConstDef(it) => &it.syntax, | ||
2835 | ModuleItem::StaticDef(it) => &it.syntax, | ||
2836 | ModuleItem::Module(it) => &it.syntax, | ||
2837 | ModuleItem::MacroCall(it) => &it.syntax, | ||
2838 | ModuleItem::ExternBlock(it) => &it.syntax, | ||
4226 | } | 2839 | } |
4227 | } | 2840 | } |
4228 | } | 2841 | } |
@@ -4311,154 +2924,33 @@ impl AstNode for TypeRef { | |||
4311 | } | 2924 | } |
4312 | } | 2925 | } |
4313 | } | 2926 | } |
4314 | impl From<StructDef> for ModuleItem { | 2927 | impl From<RecordFieldDefList> for FieldDefList { |
4315 | fn from(node: StructDef) -> ModuleItem { ModuleItem::StructDef(node) } | 2928 | fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) } |
4316 | } | ||
4317 | impl From<UnionDef> for ModuleItem { | ||
4318 | fn from(node: UnionDef) -> ModuleItem { ModuleItem::UnionDef(node) } | ||
4319 | } | ||
4320 | impl From<EnumDef> for ModuleItem { | ||
4321 | fn from(node: EnumDef) -> ModuleItem { ModuleItem::EnumDef(node) } | ||
4322 | } | ||
4323 | impl From<FnDef> for ModuleItem { | ||
4324 | fn from(node: FnDef) -> ModuleItem { ModuleItem::FnDef(node) } | ||
4325 | } | ||
4326 | impl From<TraitDef> for ModuleItem { | ||
4327 | fn from(node: TraitDef) -> ModuleItem { ModuleItem::TraitDef(node) } | ||
4328 | } | ||
4329 | impl From<TypeAliasDef> for ModuleItem { | ||
4330 | fn from(node: TypeAliasDef) -> ModuleItem { ModuleItem::TypeAliasDef(node) } | ||
4331 | } | ||
4332 | impl From<ImplDef> for ModuleItem { | ||
4333 | fn from(node: ImplDef) -> ModuleItem { ModuleItem::ImplDef(node) } | ||
4334 | } | ||
4335 | impl From<UseItem> for ModuleItem { | ||
4336 | fn from(node: UseItem) -> ModuleItem { ModuleItem::UseItem(node) } | ||
4337 | } | ||
4338 | impl From<ExternCrateItem> for ModuleItem { | ||
4339 | fn from(node: ExternCrateItem) -> ModuleItem { ModuleItem::ExternCrateItem(node) } | ||
4340 | } | ||
4341 | impl From<ConstDef> for ModuleItem { | ||
4342 | fn from(node: ConstDef) -> ModuleItem { ModuleItem::ConstDef(node) } | ||
4343 | } | ||
4344 | impl From<StaticDef> for ModuleItem { | ||
4345 | fn from(node: StaticDef) -> ModuleItem { ModuleItem::StaticDef(node) } | ||
4346 | } | ||
4347 | impl From<Module> for ModuleItem { | ||
4348 | fn from(node: Module) -> ModuleItem { ModuleItem::Module(node) } | ||
4349 | } | ||
4350 | impl From<MacroCall> for ModuleItem { | ||
4351 | fn from(node: MacroCall) -> ModuleItem { ModuleItem::MacroCall(node) } | ||
4352 | } | ||
4353 | impl From<ExternBlock> for ModuleItem { | ||
4354 | fn from(node: ExternBlock) -> ModuleItem { ModuleItem::ExternBlock(node) } | ||
4355 | } | ||
4356 | impl AstNode for ModuleItem { | ||
4357 | fn can_cast(kind: SyntaxKind) -> bool { | ||
4358 | match kind { | ||
4359 | STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF | ||
4360 | | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL | ||
4361 | | EXTERN_BLOCK => true, | ||
4362 | _ => false, | ||
4363 | } | ||
4364 | } | ||
4365 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
4366 | let res = match syntax.kind() { | ||
4367 | STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }), | ||
4368 | UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }), | ||
4369 | ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }), | ||
4370 | FN_DEF => ModuleItem::FnDef(FnDef { syntax }), | ||
4371 | TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }), | ||
4372 | TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }), | ||
4373 | IMPL_DEF => ModuleItem::ImplDef(ImplDef { syntax }), | ||
4374 | USE_ITEM => ModuleItem::UseItem(UseItem { syntax }), | ||
4375 | EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }), | ||
4376 | CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), | ||
4377 | STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), | ||
4378 | MODULE => ModuleItem::Module(Module { syntax }), | ||
4379 | MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }), | ||
4380 | EXTERN_BLOCK => ModuleItem::ExternBlock(ExternBlock { syntax }), | ||
4381 | _ => return None, | ||
4382 | }; | ||
4383 | Some(res) | ||
4384 | } | ||
4385 | fn syntax(&self) -> &SyntaxNode { | ||
4386 | match self { | ||
4387 | ModuleItem::StructDef(it) => &it.syntax, | ||
4388 | ModuleItem::UnionDef(it) => &it.syntax, | ||
4389 | ModuleItem::EnumDef(it) => &it.syntax, | ||
4390 | ModuleItem::FnDef(it) => &it.syntax, | ||
4391 | ModuleItem::TraitDef(it) => &it.syntax, | ||
4392 | ModuleItem::TypeAliasDef(it) => &it.syntax, | ||
4393 | ModuleItem::ImplDef(it) => &it.syntax, | ||
4394 | ModuleItem::UseItem(it) => &it.syntax, | ||
4395 | ModuleItem::ExternCrateItem(it) => &it.syntax, | ||
4396 | ModuleItem::ConstDef(it) => &it.syntax, | ||
4397 | ModuleItem::StaticDef(it) => &it.syntax, | ||
4398 | ModuleItem::Module(it) => &it.syntax, | ||
4399 | ModuleItem::MacroCall(it) => &it.syntax, | ||
4400 | ModuleItem::ExternBlock(it) => &it.syntax, | ||
4401 | } | ||
4402 | } | ||
4403 | } | ||
4404 | impl From<FnDef> for AssocItem { | ||
4405 | fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) } | ||
4406 | } | ||
4407 | impl From<TypeAliasDef> for AssocItem { | ||
4408 | fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) } | ||
4409 | } | ||
4410 | impl From<ConstDef> for AssocItem { | ||
4411 | fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } | ||
4412 | } | ||
4413 | impl AstNode for AssocItem { | ||
4414 | fn can_cast(kind: SyntaxKind) -> bool { | ||
4415 | match kind { | ||
4416 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, | ||
4417 | _ => false, | ||
4418 | } | ||
4419 | } | ||
4420 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
4421 | let res = match syntax.kind() { | ||
4422 | FN_DEF => AssocItem::FnDef(FnDef { syntax }), | ||
4423 | TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), | ||
4424 | CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), | ||
4425 | _ => return None, | ||
4426 | }; | ||
4427 | Some(res) | ||
4428 | } | ||
4429 | fn syntax(&self) -> &SyntaxNode { | ||
4430 | match self { | ||
4431 | AssocItem::FnDef(it) => &it.syntax, | ||
4432 | AssocItem::TypeAliasDef(it) => &it.syntax, | ||
4433 | AssocItem::ConstDef(it) => &it.syntax, | ||
4434 | } | ||
4435 | } | ||
4436 | } | ||
4437 | impl From<FnDef> for ExternItem { | ||
4438 | fn from(node: FnDef) -> ExternItem { ExternItem::FnDef(node) } | ||
4439 | } | 2929 | } |
4440 | impl From<StaticDef> for ExternItem { | 2930 | impl From<TupleFieldDefList> for FieldDefList { |
4441 | fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) } | 2931 | fn from(node: TupleFieldDefList) -> FieldDefList { FieldDefList::TupleFieldDefList(node) } |
4442 | } | 2932 | } |
4443 | impl AstNode for ExternItem { | 2933 | impl AstNode for FieldDefList { |
4444 | fn can_cast(kind: SyntaxKind) -> bool { | 2934 | fn can_cast(kind: SyntaxKind) -> bool { |
4445 | match kind { | 2935 | match kind { |
4446 | FN_DEF | STATIC_DEF => true, | 2936 | RECORD_FIELD_DEF_LIST | TUPLE_FIELD_DEF_LIST => true, |
4447 | _ => false, | 2937 | _ => false, |
4448 | } | 2938 | } |
4449 | } | 2939 | } |
4450 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2940 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
4451 | let res = match syntax.kind() { | 2941 | let res = match syntax.kind() { |
4452 | FN_DEF => ExternItem::FnDef(FnDef { syntax }), | 2942 | RECORD_FIELD_DEF_LIST => { |
4453 | STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }), | 2943 | FieldDefList::RecordFieldDefList(RecordFieldDefList { syntax }) |
2944 | } | ||
2945 | TUPLE_FIELD_DEF_LIST => FieldDefList::TupleFieldDefList(TupleFieldDefList { syntax }), | ||
4454 | _ => return None, | 2946 | _ => return None, |
4455 | }; | 2947 | }; |
4456 | Some(res) | 2948 | Some(res) |
4457 | } | 2949 | } |
4458 | fn syntax(&self) -> &SyntaxNode { | 2950 | fn syntax(&self) -> &SyntaxNode { |
4459 | match self { | 2951 | match self { |
4460 | ExternItem::FnDef(it) => &it.syntax, | 2952 | FieldDefList::RecordFieldDefList(it) => &it.syntax, |
4461 | ExternItem::StaticDef(it) => &it.syntax, | 2953 | FieldDefList::TupleFieldDefList(it) => &it.syntax, |
4462 | } | 2954 | } |
4463 | } | 2955 | } |
4464 | } | 2956 | } |
@@ -4641,6 +3133,39 @@ impl AstNode for Expr { | |||
4641 | } | 3133 | } |
4642 | } | 3134 | } |
4643 | } | 3135 | } |
3136 | impl From<FnDef> for AssocItem { | ||
3137 | fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) } | ||
3138 | } | ||
3139 | impl From<TypeAliasDef> for AssocItem { | ||
3140 | fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) } | ||
3141 | } | ||
3142 | impl From<ConstDef> for AssocItem { | ||
3143 | fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } | ||
3144 | } | ||
3145 | impl AstNode for AssocItem { | ||
3146 | fn can_cast(kind: SyntaxKind) -> bool { | ||
3147 | match kind { | ||
3148 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, | ||
3149 | _ => false, | ||
3150 | } | ||
3151 | } | ||
3152 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3153 | let res = match syntax.kind() { | ||
3154 | FN_DEF => AssocItem::FnDef(FnDef { syntax }), | ||
3155 | TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), | ||
3156 | CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), | ||
3157 | _ => return None, | ||
3158 | }; | ||
3159 | Some(res) | ||
3160 | } | ||
3161 | fn syntax(&self) -> &SyntaxNode { | ||
3162 | match self { | ||
3163 | AssocItem::FnDef(it) => &it.syntax, | ||
3164 | AssocItem::TypeAliasDef(it) => &it.syntax, | ||
3165 | AssocItem::ConstDef(it) => &it.syntax, | ||
3166 | } | ||
3167 | } | ||
3168 | } | ||
4644 | impl From<OrPat> for Pat { | 3169 | impl From<OrPat> for Pat { |
4645 | fn from(node: OrPat) -> Pat { Pat::OrPat(node) } | 3170 | fn from(node: OrPat) -> Pat { Pat::OrPat(node) } |
4646 | } | 3171 | } |
@@ -4736,31 +3261,31 @@ impl AstNode for Pat { | |||
4736 | } | 3261 | } |
4737 | } | 3262 | } |
4738 | } | 3263 | } |
4739 | impl From<RecordFieldPat> for RecordInnerPat { | 3264 | impl From<LetStmt> for Stmt { |
4740 | fn from(node: RecordFieldPat) -> RecordInnerPat { RecordInnerPat::RecordFieldPat(node) } | 3265 | fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } |
4741 | } | 3266 | } |
4742 | impl From<BindPat> for RecordInnerPat { | 3267 | impl From<ExprStmt> for Stmt { |
4743 | fn from(node: BindPat) -> RecordInnerPat { RecordInnerPat::BindPat(node) } | 3268 | fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } |
4744 | } | 3269 | } |
4745 | impl AstNode for RecordInnerPat { | 3270 | impl AstNode for Stmt { |
4746 | fn can_cast(kind: SyntaxKind) -> bool { | 3271 | fn can_cast(kind: SyntaxKind) -> bool { |
4747 | match kind { | 3272 | match kind { |
4748 | RECORD_FIELD_PAT | BIND_PAT => true, | 3273 | LET_STMT | EXPR_STMT => true, |
4749 | _ => false, | 3274 | _ => false, |
4750 | } | 3275 | } |
4751 | } | 3276 | } |
4752 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3277 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
4753 | let res = match syntax.kind() { | 3278 | let res = match syntax.kind() { |
4754 | RECORD_FIELD_PAT => RecordInnerPat::RecordFieldPat(RecordFieldPat { syntax }), | 3279 | LET_STMT => Stmt::LetStmt(LetStmt { syntax }), |
4755 | BIND_PAT => RecordInnerPat::BindPat(BindPat { syntax }), | 3280 | EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }), |
4756 | _ => return None, | 3281 | _ => return None, |
4757 | }; | 3282 | }; |
4758 | Some(res) | 3283 | Some(res) |
4759 | } | 3284 | } |
4760 | fn syntax(&self) -> &SyntaxNode { | 3285 | fn syntax(&self) -> &SyntaxNode { |
4761 | match self { | 3286 | match self { |
4762 | RecordInnerPat::RecordFieldPat(it) => &it.syntax, | 3287 | Stmt::LetStmt(it) => &it.syntax, |
4763 | RecordInnerPat::BindPat(it) => &it.syntax, | 3288 | Stmt::ExprStmt(it) => &it.syntax, |
4764 | } | 3289 | } |
4765 | } | 3290 | } |
4766 | } | 3291 | } |
@@ -4792,90 +3317,103 @@ impl AstNode for AttrInput { | |||
4792 | } | 3317 | } |
4793 | } | 3318 | } |
4794 | } | 3319 | } |
4795 | impl From<LetStmt> for Stmt { | 3320 | impl From<FnDef> for ExternItem { |
4796 | fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } | 3321 | fn from(node: FnDef) -> ExternItem { ExternItem::FnDef(node) } |
4797 | } | 3322 | } |
4798 | impl From<ExprStmt> for Stmt { | 3323 | impl From<StaticDef> for ExternItem { |
4799 | fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } | 3324 | fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) } |
4800 | } | 3325 | } |
4801 | impl AstNode for Stmt { | 3326 | impl AstNode for ExternItem { |
4802 | fn can_cast(kind: SyntaxKind) -> bool { | 3327 | fn can_cast(kind: SyntaxKind) -> bool { |
4803 | match kind { | 3328 | match kind { |
4804 | LET_STMT | EXPR_STMT => true, | 3329 | FN_DEF | STATIC_DEF => true, |
4805 | _ => false, | 3330 | _ => false, |
4806 | } | 3331 | } |
4807 | } | 3332 | } |
4808 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3333 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
4809 | let res = match syntax.kind() { | 3334 | let res = match syntax.kind() { |
4810 | LET_STMT => Stmt::LetStmt(LetStmt { syntax }), | 3335 | FN_DEF => ExternItem::FnDef(FnDef { syntax }), |
4811 | EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }), | 3336 | STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }), |
4812 | _ => return None, | 3337 | _ => return None, |
4813 | }; | 3338 | }; |
4814 | Some(res) | 3339 | Some(res) |
4815 | } | 3340 | } |
4816 | fn syntax(&self) -> &SyntaxNode { | 3341 | fn syntax(&self) -> &SyntaxNode { |
4817 | match self { | 3342 | match self { |
4818 | Stmt::LetStmt(it) => &it.syntax, | 3343 | ExternItem::FnDef(it) => &it.syntax, |
4819 | Stmt::ExprStmt(it) => &it.syntax, | 3344 | ExternItem::StaticDef(it) => &it.syntax, |
4820 | } | 3345 | } |
4821 | } | 3346 | } |
4822 | } | 3347 | } |
4823 | impl From<RecordFieldDefList> for FieldDefList { | 3348 | impl From<StructDef> for AdtDef { |
4824 | fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) } | 3349 | fn from(node: StructDef) -> AdtDef { AdtDef::StructDef(node) } |
4825 | } | 3350 | } |
4826 | impl From<TupleFieldDefList> for FieldDefList { | 3351 | impl From<EnumDef> for AdtDef { |
4827 | fn from(node: TupleFieldDefList) -> FieldDefList { FieldDefList::TupleFieldDefList(node) } | 3352 | fn from(node: EnumDef) -> AdtDef { AdtDef::EnumDef(node) } |
4828 | } | 3353 | } |
4829 | impl AstNode for FieldDefList { | 3354 | impl From<UnionDef> for AdtDef { |
3355 | fn from(node: UnionDef) -> AdtDef { AdtDef::UnionDef(node) } | ||
3356 | } | ||
3357 | impl AstNode for AdtDef { | ||
4830 | fn can_cast(kind: SyntaxKind) -> bool { | 3358 | fn can_cast(kind: SyntaxKind) -> bool { |
4831 | match kind { | 3359 | match kind { |
4832 | RECORD_FIELD_DEF_LIST | TUPLE_FIELD_DEF_LIST => true, | 3360 | STRUCT_DEF | ENUM_DEF | UNION_DEF => true, |
4833 | _ => false, | 3361 | _ => false, |
4834 | } | 3362 | } |
4835 | } | 3363 | } |
4836 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3364 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
4837 | let res = match syntax.kind() { | 3365 | let res = match syntax.kind() { |
4838 | RECORD_FIELD_DEF_LIST => { | 3366 | STRUCT_DEF => AdtDef::StructDef(StructDef { syntax }), |
4839 | FieldDefList::RecordFieldDefList(RecordFieldDefList { syntax }) | 3367 | ENUM_DEF => AdtDef::EnumDef(EnumDef { syntax }), |
4840 | } | 3368 | UNION_DEF => AdtDef::UnionDef(UnionDef { syntax }), |
4841 | TUPLE_FIELD_DEF_LIST => FieldDefList::TupleFieldDefList(TupleFieldDefList { syntax }), | ||
4842 | _ => return None, | 3369 | _ => return None, |
4843 | }; | 3370 | }; |
4844 | Some(res) | 3371 | Some(res) |
4845 | } | 3372 | } |
4846 | fn syntax(&self) -> &SyntaxNode { | 3373 | fn syntax(&self) -> &SyntaxNode { |
4847 | match self { | 3374 | match self { |
4848 | FieldDefList::RecordFieldDefList(it) => &it.syntax, | 3375 | AdtDef::StructDef(it) => &it.syntax, |
4849 | FieldDefList::TupleFieldDefList(it) => &it.syntax, | 3376 | AdtDef::EnumDef(it) => &it.syntax, |
3377 | AdtDef::UnionDef(it) => &it.syntax, | ||
4850 | } | 3378 | } |
4851 | } | 3379 | } |
4852 | } | 3380 | } |
4853 | impl std::fmt::Display for NominalDef { | 3381 | impl std::fmt::Display for ModuleItem { |
3382 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3383 | std::fmt::Display::fmt(self.syntax(), f) | ||
3384 | } | ||
3385 | } | ||
3386 | impl std::fmt::Display for TypeRef { | ||
4854 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3387 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4855 | std::fmt::Display::fmt(self.syntax(), f) | 3388 | std::fmt::Display::fmt(self.syntax(), f) |
4856 | } | 3389 | } |
4857 | } | 3390 | } |
4858 | impl std::fmt::Display for GenericParam { | 3391 | impl std::fmt::Display for FieldDefList { |
4859 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3392 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4860 | std::fmt::Display::fmt(self.syntax(), f) | 3393 | std::fmt::Display::fmt(self.syntax(), f) |
4861 | } | 3394 | } |
4862 | } | 3395 | } |
4863 | impl std::fmt::Display for GenericArg { | 3396 | impl std::fmt::Display for Expr { |
4864 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3397 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4865 | std::fmt::Display::fmt(self.syntax(), f) | 3398 | std::fmt::Display::fmt(self.syntax(), f) |
4866 | } | 3399 | } |
4867 | } | 3400 | } |
4868 | impl std::fmt::Display for TypeRef { | 3401 | impl std::fmt::Display for AssocItem { |
4869 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3402 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4870 | std::fmt::Display::fmt(self.syntax(), f) | 3403 | std::fmt::Display::fmt(self.syntax(), f) |
4871 | } | 3404 | } |
4872 | } | 3405 | } |
4873 | impl std::fmt::Display for ModuleItem { | 3406 | impl std::fmt::Display for Pat { |
4874 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3407 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4875 | std::fmt::Display::fmt(self.syntax(), f) | 3408 | std::fmt::Display::fmt(self.syntax(), f) |
4876 | } | 3409 | } |
4877 | } | 3410 | } |
4878 | impl std::fmt::Display for AssocItem { | 3411 | impl std::fmt::Display for Stmt { |
3412 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3413 | std::fmt::Display::fmt(self.syntax(), f) | ||
3414 | } | ||
3415 | } | ||
3416 | impl std::fmt::Display for AttrInput { | ||
4879 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3417 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4880 | std::fmt::Display::fmt(self.syntax(), f) | 3418 | std::fmt::Display::fmt(self.syntax(), f) |
4881 | } | 3419 | } |
@@ -4885,42 +3423,47 @@ impl std::fmt::Display for ExternItem { | |||
4885 | std::fmt::Display::fmt(self.syntax(), f) | 3423 | std::fmt::Display::fmt(self.syntax(), f) |
4886 | } | 3424 | } |
4887 | } | 3425 | } |
4888 | impl std::fmt::Display for Expr { | 3426 | impl std::fmt::Display for AdtDef { |
4889 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3427 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4890 | std::fmt::Display::fmt(self.syntax(), f) | 3428 | std::fmt::Display::fmt(self.syntax(), f) |
4891 | } | 3429 | } |
4892 | } | 3430 | } |
4893 | impl std::fmt::Display for Pat { | 3431 | impl std::fmt::Display for SourceFile { |
4894 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3432 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4895 | std::fmt::Display::fmt(self.syntax(), f) | 3433 | std::fmt::Display::fmt(self.syntax(), f) |
4896 | } | 3434 | } |
4897 | } | 3435 | } |
4898 | impl std::fmt::Display for RecordInnerPat { | 3436 | impl std::fmt::Display for Attr { |
4899 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3437 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4900 | std::fmt::Display::fmt(self.syntax(), f) | 3438 | std::fmt::Display::fmt(self.syntax(), f) |
4901 | } | 3439 | } |
4902 | } | 3440 | } |
4903 | impl std::fmt::Display for AttrInput { | 3441 | impl std::fmt::Display for FnDef { |
4904 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3442 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4905 | std::fmt::Display::fmt(self.syntax(), f) | 3443 | std::fmt::Display::fmt(self.syntax(), f) |
4906 | } | 3444 | } |
4907 | } | 3445 | } |
4908 | impl std::fmt::Display for Stmt { | 3446 | impl std::fmt::Display for Visibility { |
4909 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3447 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4910 | std::fmt::Display::fmt(self.syntax(), f) | 3448 | std::fmt::Display::fmt(self.syntax(), f) |
4911 | } | 3449 | } |
4912 | } | 3450 | } |
4913 | impl std::fmt::Display for FieldDefList { | 3451 | impl std::fmt::Display for Abi { |
4914 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3452 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4915 | std::fmt::Display::fmt(self.syntax(), f) | 3453 | std::fmt::Display::fmt(self.syntax(), f) |
4916 | } | 3454 | } |
4917 | } | 3455 | } |
4918 | impl std::fmt::Display for SourceFile { | 3456 | impl std::fmt::Display for Name { |
4919 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3457 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4920 | std::fmt::Display::fmt(self.syntax(), f) | 3458 | std::fmt::Display::fmt(self.syntax(), f) |
4921 | } | 3459 | } |
4922 | } | 3460 | } |
4923 | impl std::fmt::Display for FnDef { | 3461 | impl std::fmt::Display for TypeParamList { |
3462 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3463 | std::fmt::Display::fmt(self.syntax(), f) | ||
3464 | } | ||
3465 | } | ||
3466 | impl std::fmt::Display for ParamList { | ||
4924 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3467 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4925 | std::fmt::Display::fmt(self.syntax(), f) | 3468 | std::fmt::Display::fmt(self.syntax(), f) |
4926 | } | 3469 | } |
@@ -4930,22 +3473,22 @@ impl std::fmt::Display for RetType { | |||
4930 | std::fmt::Display::fmt(self.syntax(), f) | 3473 | std::fmt::Display::fmt(self.syntax(), f) |
4931 | } | 3474 | } |
4932 | } | 3475 | } |
4933 | impl std::fmt::Display for StructDef { | 3476 | impl std::fmt::Display for WhereClause { |
4934 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3477 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4935 | std::fmt::Display::fmt(self.syntax(), f) | 3478 | std::fmt::Display::fmt(self.syntax(), f) |
4936 | } | 3479 | } |
4937 | } | 3480 | } |
4938 | impl std::fmt::Display for UnionDef { | 3481 | impl std::fmt::Display for BlockExpr { |
4939 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3482 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4940 | std::fmt::Display::fmt(self.syntax(), f) | 3483 | std::fmt::Display::fmt(self.syntax(), f) |
4941 | } | 3484 | } |
4942 | } | 3485 | } |
4943 | impl std::fmt::Display for RecordFieldDefList { | 3486 | impl std::fmt::Display for StructDef { |
4944 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3487 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4945 | std::fmt::Display::fmt(self.syntax(), f) | 3488 | std::fmt::Display::fmt(self.syntax(), f) |
4946 | } | 3489 | } |
4947 | } | 3490 | } |
4948 | impl std::fmt::Display for RecordFieldDef { | 3491 | impl std::fmt::Display for RecordFieldDefList { |
4949 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3492 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4950 | std::fmt::Display::fmt(self.syntax(), f) | 3493 | std::fmt::Display::fmt(self.syntax(), f) |
4951 | } | 3494 | } |
@@ -4955,6 +3498,16 @@ impl std::fmt::Display for TupleFieldDefList { | |||
4955 | std::fmt::Display::fmt(self.syntax(), f) | 3498 | std::fmt::Display::fmt(self.syntax(), f) |
4956 | } | 3499 | } |
4957 | } | 3500 | } |
3501 | impl std::fmt::Display for UnionDef { | ||
3502 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3503 | std::fmt::Display::fmt(self.syntax(), f) | ||
3504 | } | ||
3505 | } | ||
3506 | impl std::fmt::Display for RecordFieldDef { | ||
3507 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3508 | std::fmt::Display::fmt(self.syntax(), f) | ||
3509 | } | ||
3510 | } | ||
4958 | impl std::fmt::Display for TupleFieldDef { | 3511 | impl std::fmt::Display for TupleFieldDef { |
4959 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3512 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4960 | std::fmt::Display::fmt(self.syntax(), f) | 3513 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -4980,7 +3533,7 @@ impl std::fmt::Display for TraitDef { | |||
4980 | std::fmt::Display::fmt(self.syntax(), f) | 3533 | std::fmt::Display::fmt(self.syntax(), f) |
4981 | } | 3534 | } |
4982 | } | 3535 | } |
4983 | impl std::fmt::Display for Module { | 3536 | impl std::fmt::Display for TypeBoundList { |
4984 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3537 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4985 | std::fmt::Display::fmt(self.syntax(), f) | 3538 | std::fmt::Display::fmt(self.syntax(), f) |
4986 | } | 3539 | } |
@@ -4990,6 +3543,11 @@ impl std::fmt::Display for ItemList { | |||
4990 | std::fmt::Display::fmt(self.syntax(), f) | 3543 | std::fmt::Display::fmt(self.syntax(), f) |
4991 | } | 3544 | } |
4992 | } | 3545 | } |
3546 | impl std::fmt::Display for Module { | ||
3547 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3548 | std::fmt::Display::fmt(self.syntax(), f) | ||
3549 | } | ||
3550 | } | ||
4993 | impl std::fmt::Display for ConstDef { | 3551 | impl std::fmt::Display for ConstDef { |
4994 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3552 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
4995 | std::fmt::Display::fmt(self.syntax(), f) | 3553 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -5030,6 +3588,11 @@ impl std::fmt::Display for PathType { | |||
5030 | std::fmt::Display::fmt(self.syntax(), f) | 3588 | std::fmt::Display::fmt(self.syntax(), f) |
5031 | } | 3589 | } |
5032 | } | 3590 | } |
3591 | impl std::fmt::Display for Path { | ||
3592 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3593 | std::fmt::Display::fmt(self.syntax(), f) | ||
3594 | } | ||
3595 | } | ||
5033 | impl std::fmt::Display for PointerType { | 3596 | impl std::fmt::Display for PointerType { |
5034 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3597 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5035 | std::fmt::Display::fmt(self.syntax(), f) | 3598 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -5105,7 +3668,7 @@ impl std::fmt::Display for IfExpr { | |||
5105 | std::fmt::Display::fmt(self.syntax(), f) | 3668 | std::fmt::Display::fmt(self.syntax(), f) |
5106 | } | 3669 | } |
5107 | } | 3670 | } |
5108 | impl std::fmt::Display for LoopExpr { | 3671 | impl std::fmt::Display for Condition { |
5109 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3672 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5110 | std::fmt::Display::fmt(self.syntax(), f) | 3673 | std::fmt::Display::fmt(self.syntax(), f) |
5111 | } | 3674 | } |
@@ -5115,6 +3678,16 @@ impl std::fmt::Display for EffectExpr { | |||
5115 | std::fmt::Display::fmt(self.syntax(), f) | 3678 | std::fmt::Display::fmt(self.syntax(), f) |
5116 | } | 3679 | } |
5117 | } | 3680 | } |
3681 | impl std::fmt::Display for Label { | ||
3682 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3683 | std::fmt::Display::fmt(self.syntax(), f) | ||
3684 | } | ||
3685 | } | ||
3686 | impl std::fmt::Display for LoopExpr { | ||
3687 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3688 | std::fmt::Display::fmt(self.syntax(), f) | ||
3689 | } | ||
3690 | } | ||
5118 | impl std::fmt::Display for ForExpr { | 3691 | impl std::fmt::Display for ForExpr { |
5119 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3692 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5120 | std::fmt::Display::fmt(self.syntax(), f) | 3693 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -5135,32 +3708,32 @@ impl std::fmt::Display for BreakExpr { | |||
5135 | std::fmt::Display::fmt(self.syntax(), f) | 3708 | std::fmt::Display::fmt(self.syntax(), f) |
5136 | } | 3709 | } |
5137 | } | 3710 | } |
5138 | impl std::fmt::Display for Label { | 3711 | impl std::fmt::Display for ReturnExpr { |
5139 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3712 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5140 | std::fmt::Display::fmt(self.syntax(), f) | 3713 | std::fmt::Display::fmt(self.syntax(), f) |
5141 | } | 3714 | } |
5142 | } | 3715 | } |
5143 | impl std::fmt::Display for BlockExpr { | 3716 | impl std::fmt::Display for CallExpr { |
5144 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3717 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5145 | std::fmt::Display::fmt(self.syntax(), f) | 3718 | std::fmt::Display::fmt(self.syntax(), f) |
5146 | } | 3719 | } |
5147 | } | 3720 | } |
5148 | impl std::fmt::Display for ReturnExpr { | 3721 | impl std::fmt::Display for ArgList { |
5149 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3722 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5150 | std::fmt::Display::fmt(self.syntax(), f) | 3723 | std::fmt::Display::fmt(self.syntax(), f) |
5151 | } | 3724 | } |
5152 | } | 3725 | } |
5153 | impl std::fmt::Display for CallExpr { | 3726 | impl std::fmt::Display for MethodCallExpr { |
5154 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3727 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5155 | std::fmt::Display::fmt(self.syntax(), f) | 3728 | std::fmt::Display::fmt(self.syntax(), f) |
5156 | } | 3729 | } |
5157 | } | 3730 | } |
5158 | impl std::fmt::Display for MethodCallExpr { | 3731 | impl std::fmt::Display for NameRef { |
5159 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3732 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5160 | std::fmt::Display::fmt(self.syntax(), f) | 3733 | std::fmt::Display::fmt(self.syntax(), f) |
5161 | } | 3734 | } |
5162 | } | 3735 | } |
5163 | impl std::fmt::Display for IndexExpr { | 3736 | impl std::fmt::Display for TypeArgList { |
5164 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3737 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5165 | std::fmt::Display::fmt(self.syntax(), f) | 3738 | std::fmt::Display::fmt(self.syntax(), f) |
5166 | } | 3739 | } |
@@ -5170,6 +3743,11 @@ impl std::fmt::Display for FieldExpr { | |||
5170 | std::fmt::Display::fmt(self.syntax(), f) | 3743 | std::fmt::Display::fmt(self.syntax(), f) |
5171 | } | 3744 | } |
5172 | } | 3745 | } |
3746 | impl std::fmt::Display for IndexExpr { | ||
3747 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3748 | std::fmt::Display::fmt(self.syntax(), f) | ||
3749 | } | ||
3750 | } | ||
5173 | impl std::fmt::Display for AwaitExpr { | 3751 | impl std::fmt::Display for AwaitExpr { |
5174 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3752 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5175 | std::fmt::Display::fmt(self.syntax(), f) | 3753 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -5310,6 +3888,11 @@ impl std::fmt::Display for MacroPat { | |||
5310 | std::fmt::Display::fmt(self.syntax(), f) | 3888 | std::fmt::Display::fmt(self.syntax(), f) |
5311 | } | 3889 | } |
5312 | } | 3890 | } |
3891 | impl std::fmt::Display for MacroCall { | ||
3892 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
3893 | std::fmt::Display::fmt(self.syntax(), f) | ||
3894 | } | ||
3895 | } | ||
5313 | impl std::fmt::Display for RecordPat { | 3896 | impl std::fmt::Display for RecordPat { |
5314 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3897 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5315 | std::fmt::Display::fmt(self.syntax(), f) | 3898 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -5335,37 +3918,22 @@ impl std::fmt::Display for TuplePat { | |||
5335 | std::fmt::Display::fmt(self.syntax(), f) | 3918 | std::fmt::Display::fmt(self.syntax(), f) |
5336 | } | 3919 | } |
5337 | } | 3920 | } |
5338 | impl std::fmt::Display for Visibility { | 3921 | impl std::fmt::Display for TokenTree { |
5339 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5340 | std::fmt::Display::fmt(self.syntax(), f) | ||
5341 | } | ||
5342 | } | ||
5343 | impl std::fmt::Display for Name { | ||
5344 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5345 | std::fmt::Display::fmt(self.syntax(), f) | ||
5346 | } | ||
5347 | } | ||
5348 | impl std::fmt::Display for NameRef { | ||
5349 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5350 | std::fmt::Display::fmt(self.syntax(), f) | ||
5351 | } | ||
5352 | } | ||
5353 | impl std::fmt::Display for MacroCall { | ||
5354 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3922 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5355 | std::fmt::Display::fmt(self.syntax(), f) | 3923 | std::fmt::Display::fmt(self.syntax(), f) |
5356 | } | 3924 | } |
5357 | } | 3925 | } |
5358 | impl std::fmt::Display for Attr { | 3926 | impl std::fmt::Display for MacroDef { |
5359 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3927 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5360 | std::fmt::Display::fmt(self.syntax(), f) | 3928 | std::fmt::Display::fmt(self.syntax(), f) |
5361 | } | 3929 | } |
5362 | } | 3930 | } |
5363 | impl std::fmt::Display for TokenTree { | 3931 | impl std::fmt::Display for MacroItems { |
5364 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3932 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5365 | std::fmt::Display::fmt(self.syntax(), f) | 3933 | std::fmt::Display::fmt(self.syntax(), f) |
5366 | } | 3934 | } |
5367 | } | 3935 | } |
5368 | impl std::fmt::Display for TypeParamList { | 3936 | impl std::fmt::Display for MacroStmts { |
5369 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3937 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5370 | std::fmt::Display::fmt(self.syntax(), f) | 3938 | std::fmt::Display::fmt(self.syntax(), f) |
5371 | } | 3939 | } |
@@ -5375,22 +3943,17 @@ impl std::fmt::Display for TypeParam { | |||
5375 | std::fmt::Display::fmt(self.syntax(), f) | 3943 | std::fmt::Display::fmt(self.syntax(), f) |
5376 | } | 3944 | } |
5377 | } | 3945 | } |
5378 | impl std::fmt::Display for ConstParam { | ||
5379 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5380 | std::fmt::Display::fmt(self.syntax(), f) | ||
5381 | } | ||
5382 | } | ||
5383 | impl std::fmt::Display for LifetimeParam { | 3946 | impl std::fmt::Display for LifetimeParam { |
5384 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3947 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5385 | std::fmt::Display::fmt(self.syntax(), f) | 3948 | std::fmt::Display::fmt(self.syntax(), f) |
5386 | } | 3949 | } |
5387 | } | 3950 | } |
5388 | impl std::fmt::Display for TypeBound { | 3951 | impl std::fmt::Display for ConstParam { |
5389 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3952 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5390 | std::fmt::Display::fmt(self.syntax(), f) | 3953 | std::fmt::Display::fmt(self.syntax(), f) |
5391 | } | 3954 | } |
5392 | } | 3955 | } |
5393 | impl std::fmt::Display for TypeBoundList { | 3956 | impl std::fmt::Display for TypeBound { |
5394 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3957 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5395 | std::fmt::Display::fmt(self.syntax(), f) | 3958 | std::fmt::Display::fmt(self.syntax(), f) |
5396 | } | 3959 | } |
@@ -5400,16 +3963,6 @@ impl std::fmt::Display for WherePred { | |||
5400 | std::fmt::Display::fmt(self.syntax(), f) | 3963 | std::fmt::Display::fmt(self.syntax(), f) |
5401 | } | 3964 | } |
5402 | } | 3965 | } |
5403 | impl std::fmt::Display for WhereClause { | ||
5404 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5405 | std::fmt::Display::fmt(self.syntax(), f) | ||
5406 | } | ||
5407 | } | ||
5408 | impl std::fmt::Display for Abi { | ||
5409 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5410 | std::fmt::Display::fmt(self.syntax(), f) | ||
5411 | } | ||
5412 | } | ||
5413 | impl std::fmt::Display for ExprStmt { | 3966 | impl std::fmt::Display for ExprStmt { |
5414 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3967 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5415 | std::fmt::Display::fmt(self.syntax(), f) | 3968 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -5420,16 +3973,6 @@ impl std::fmt::Display for LetStmt { | |||
5420 | std::fmt::Display::fmt(self.syntax(), f) | 3973 | std::fmt::Display::fmt(self.syntax(), f) |
5421 | } | 3974 | } |
5422 | } | 3975 | } |
5423 | impl std::fmt::Display for Condition { | ||
5424 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5425 | std::fmt::Display::fmt(self.syntax(), f) | ||
5426 | } | ||
5427 | } | ||
5428 | impl std::fmt::Display for ParamList { | ||
5429 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5430 | std::fmt::Display::fmt(self.syntax(), f) | ||
5431 | } | ||
5432 | } | ||
5433 | impl std::fmt::Display for SelfParam { | 3976 | impl std::fmt::Display for SelfParam { |
5434 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3977 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5435 | std::fmt::Display::fmt(self.syntax(), f) | 3978 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -5450,27 +3993,17 @@ impl std::fmt::Display for UseTree { | |||
5450 | std::fmt::Display::fmt(self.syntax(), f) | 3993 | std::fmt::Display::fmt(self.syntax(), f) |
5451 | } | 3994 | } |
5452 | } | 3995 | } |
5453 | impl std::fmt::Display for Alias { | ||
5454 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5455 | std::fmt::Display::fmt(self.syntax(), f) | ||
5456 | } | ||
5457 | } | ||
5458 | impl std::fmt::Display for UseTreeList { | 3996 | impl std::fmt::Display for UseTreeList { |
5459 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3997 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5460 | std::fmt::Display::fmt(self.syntax(), f) | 3998 | std::fmt::Display::fmt(self.syntax(), f) |
5461 | } | 3999 | } |
5462 | } | 4000 | } |
5463 | impl std::fmt::Display for ExternCrateItem { | 4001 | impl std::fmt::Display for Alias { |
5464 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5465 | std::fmt::Display::fmt(self.syntax(), f) | ||
5466 | } | ||
5467 | } | ||
5468 | impl std::fmt::Display for ArgList { | ||
5469 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 4002 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5470 | std::fmt::Display::fmt(self.syntax(), f) | 4003 | std::fmt::Display::fmt(self.syntax(), f) |
5471 | } | 4004 | } |
5472 | } | 4005 | } |
5473 | impl std::fmt::Display for Path { | 4006 | impl std::fmt::Display for ExternCrateItem { |
5474 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 4007 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5475 | std::fmt::Display::fmt(self.syntax(), f) | 4008 | std::fmt::Display::fmt(self.syntax(), f) |
5476 | } | 4009 | } |
@@ -5480,37 +4013,27 @@ impl std::fmt::Display for PathSegment { | |||
5480 | std::fmt::Display::fmt(self.syntax(), f) | 4013 | std::fmt::Display::fmt(self.syntax(), f) |
5481 | } | 4014 | } |
5482 | } | 4015 | } |
5483 | impl std::fmt::Display for TypeArgList { | ||
5484 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5485 | std::fmt::Display::fmt(self.syntax(), f) | ||
5486 | } | ||
5487 | } | ||
5488 | impl std::fmt::Display for TypeArg { | 4016 | impl std::fmt::Display for TypeArg { |
5489 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 4017 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5490 | std::fmt::Display::fmt(self.syntax(), f) | 4018 | std::fmt::Display::fmt(self.syntax(), f) |
5491 | } | 4019 | } |
5492 | } | 4020 | } |
5493 | impl std::fmt::Display for AssocTypeArg { | ||
5494 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5495 | std::fmt::Display::fmt(self.syntax(), f) | ||
5496 | } | ||
5497 | } | ||
5498 | impl std::fmt::Display for LifetimeArg { | 4021 | impl std::fmt::Display for LifetimeArg { |
5499 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 4022 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5500 | std::fmt::Display::fmt(self.syntax(), f) | 4023 | std::fmt::Display::fmt(self.syntax(), f) |
5501 | } | 4024 | } |
5502 | } | 4025 | } |
5503 | impl std::fmt::Display for ConstArg { | 4026 | impl std::fmt::Display for AssocTypeArg { |
5504 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 4027 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5505 | std::fmt::Display::fmt(self.syntax(), f) | 4028 | std::fmt::Display::fmt(self.syntax(), f) |
5506 | } | 4029 | } |
5507 | } | 4030 | } |
5508 | impl std::fmt::Display for MacroItems { | 4031 | impl std::fmt::Display for ConstArg { |
5509 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 4032 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5510 | std::fmt::Display::fmt(self.syntax(), f) | 4033 | std::fmt::Display::fmt(self.syntax(), f) |
5511 | } | 4034 | } |
5512 | } | 4035 | } |
5513 | impl std::fmt::Display for MacroStmts { | 4036 | impl std::fmt::Display for ExternBlock { |
5514 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 4037 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5515 | std::fmt::Display::fmt(self.syntax(), f) | 4038 | std::fmt::Display::fmt(self.syntax(), f) |
5516 | } | 4039 | } |
@@ -5520,18 +4043,8 @@ impl std::fmt::Display for ExternItemList { | |||
5520 | std::fmt::Display::fmt(self.syntax(), f) | 4043 | std::fmt::Display::fmt(self.syntax(), f) |
5521 | } | 4044 | } |
5522 | } | 4045 | } |
5523 | impl std::fmt::Display for ExternBlock { | ||
5524 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5525 | std::fmt::Display::fmt(self.syntax(), f) | ||
5526 | } | ||
5527 | } | ||
5528 | impl std::fmt::Display for MetaItem { | 4046 | impl std::fmt::Display for MetaItem { |
5529 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 4047 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
5530 | std::fmt::Display::fmt(self.syntax(), f) | 4048 | std::fmt::Display::fmt(self.syntax(), f) |
5531 | } | 4049 | } |
5532 | } | 4050 | } |
5533 | impl std::fmt::Display for MacroDef { | ||
5534 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
5535 | std::fmt::Display::fmt(self.syntax(), f) | ||
5536 | } | ||
5537 | } | ||
diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs index 662c6f73e..242900643 100644 --- a/crates/ra_syntax/src/ast/node_ext.rs +++ b/crates/ra_syntax/src/ast/node_ext.rs | |||
@@ -472,3 +472,19 @@ impl ast::TokenTree { | |||
472 | .filter(|it| matches!(it.kind(), T!['}'] | T![')'] | T![']'])) | 472 | .filter(|it| matches!(it.kind(), T!['}'] | T![')'] | T![']'])) |
473 | } | 473 | } |
474 | } | 474 | } |
475 | |||
476 | impl ast::DocCommentsOwner for ast::SourceFile {} | ||
477 | impl ast::DocCommentsOwner for ast::FnDef {} | ||
478 | impl ast::DocCommentsOwner for ast::StructDef {} | ||
479 | impl ast::DocCommentsOwner for ast::UnionDef {} | ||
480 | impl ast::DocCommentsOwner for ast::RecordFieldDef {} | ||
481 | impl ast::DocCommentsOwner for ast::TupleFieldDef {} | ||
482 | impl ast::DocCommentsOwner for ast::EnumDef {} | ||
483 | impl ast::DocCommentsOwner for ast::EnumVariant {} | ||
484 | impl ast::DocCommentsOwner for ast::TraitDef {} | ||
485 | impl ast::DocCommentsOwner for ast::Module {} | ||
486 | impl ast::DocCommentsOwner for ast::StaticDef {} | ||
487 | impl ast::DocCommentsOwner for ast::ConstDef {} | ||
488 | impl ast::DocCommentsOwner for ast::TypeAliasDef {} | ||
489 | impl ast::DocCommentsOwner for ast::ImplDef {} | ||
490 | impl ast::DocCommentsOwner for ast::MacroCall {} | ||
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 3f9c820c5..931fc61ed 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml | |||
@@ -23,7 +23,7 @@ log = "0.4.8" | |||
23 | lsp-types = { version = "0.78.0", features = ["proposed"] } | 23 | lsp-types = { version = "0.78.0", features = ["proposed"] } |
24 | parking_lot = "0.11.0" | 24 | parking_lot = "0.11.0" |
25 | pico-args = "0.3.1" | 25 | pico-args = "0.3.1" |
26 | rand = { version = "0.7.3", features = ["small_rng"] } | 26 | oorandom = "11.1.2" |
27 | rustc-hash = "1.1.0" | 27 | rustc-hash = "1.1.0" |
28 | serde = { version = "1.0.106", features = ["derive"] } | 28 | serde = { version = "1.0.106", features = ["derive"] } |
29 | serde_json = "1.0.48" | 29 | serde_json = "1.0.48" |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index ccc058682..66d201ba6 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -1,7 +1,10 @@ | |||
1 | //! Fully type-check project and print various stats, like the number of type | 1 | //! Fully type-check project and print various stats, like the number of type |
2 | //! errors. | 2 | //! errors. |
3 | 3 | ||
4 | use std::{path::Path, time::Instant}; | 4 | use std::{ |
5 | path::Path, | ||
6 | time::{Instant, SystemTime, UNIX_EPOCH}, | ||
7 | }; | ||
5 | 8 | ||
6 | use hir::{ | 9 | use hir::{ |
7 | db::{AstDatabase, DefDatabase, HirDatabase}, | 10 | db::{AstDatabase, DefDatabase, HirDatabase}, |
@@ -10,12 +13,12 @@ use hir::{ | |||
10 | use hir_def::FunctionId; | 13 | use hir_def::FunctionId; |
11 | use hir_ty::{Ty, TypeWalk}; | 14 | use hir_ty::{Ty, TypeWalk}; |
12 | use itertools::Itertools; | 15 | use itertools::Itertools; |
16 | use oorandom::Rand32; | ||
13 | use ra_db::{ | 17 | use ra_db::{ |
14 | salsa::{self, ParallelDatabase}, | 18 | salsa::{self, ParallelDatabase}, |
15 | SourceDatabaseExt, | 19 | SourceDatabaseExt, |
16 | }; | 20 | }; |
17 | use ra_syntax::AstNode; | 21 | use ra_syntax::AstNode; |
18 | use rand::{seq::SliceRandom, thread_rng}; | ||
19 | use rayon::prelude::*; | 22 | use rayon::prelude::*; |
20 | use rustc_hash::FxHashSet; | 23 | use rustc_hash::FxHashSet; |
21 | use stdx::format_to; | 24 | use stdx::format_to; |
@@ -46,6 +49,11 @@ pub fn analysis_stats( | |||
46 | load_output_dirs: bool, | 49 | load_output_dirs: bool, |
47 | with_proc_macro: bool, | 50 | with_proc_macro: bool, |
48 | ) -> Result<()> { | 51 | ) -> Result<()> { |
52 | let mut rng = { | ||
53 | let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64; | ||
54 | Rand32::new(seed) | ||
55 | }; | ||
56 | |||
49 | let db_load_time = Instant::now(); | 57 | let db_load_time = Instant::now(); |
50 | let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; | 58 | let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; |
51 | let db = host.raw_database(); | 59 | let db = host.raw_database(); |
@@ -57,7 +65,7 @@ pub fn analysis_stats( | |||
57 | 65 | ||
58 | let mut krates = Crate::all(db); | 66 | let mut krates = Crate::all(db); |
59 | if randomize { | 67 | if randomize { |
60 | krates.shuffle(&mut thread_rng()); | 68 | shuffle(&mut rng, &mut krates); |
61 | } | 69 | } |
62 | for krate in krates { | 70 | for krate in krates { |
63 | let module = krate.root_module(db).expect("crate without root module"); | 71 | let module = krate.root_module(db).expect("crate without root module"); |
@@ -72,7 +80,7 @@ pub fn analysis_stats( | |||
72 | } | 80 | } |
73 | 81 | ||
74 | if randomize { | 82 | if randomize { |
75 | visit_queue.shuffle(&mut thread_rng()); | 83 | shuffle(&mut rng, &mut visit_queue); |
76 | } | 84 | } |
77 | 85 | ||
78 | eprintln!("Crates in this dir: {}", num_crates); | 86 | eprintln!("Crates in this dir: {}", num_crates); |
@@ -110,7 +118,7 @@ pub fn analysis_stats( | |||
110 | ); | 118 | ); |
111 | 119 | ||
112 | if randomize { | 120 | if randomize { |
113 | funcs.shuffle(&mut thread_rng()); | 121 | shuffle(&mut rng, &mut funcs); |
114 | } | 122 | } |
115 | 123 | ||
116 | let mut bar = match verbosity { | 124 | let mut bar = match verbosity { |
@@ -306,3 +314,10 @@ pub fn analysis_stats( | |||
306 | 314 | ||
307 | Ok(()) | 315 | Ok(()) |
308 | } | 316 | } |
317 | |||
318 | fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) { | ||
319 | for i in (1..slice.len()).rev() { | ||
320 | let idx = rng.rand_range(0..i as u32) as usize; | ||
321 | slice.swap(idx, i) | ||
322 | } | ||
323 | } | ||
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index d1cfb5909..8140da87f 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml | |||
@@ -10,9 +10,10 @@ license = "MIT OR Apache-2.0" | |||
10 | doctest = false | 10 | doctest = false |
11 | 11 | ||
12 | [dependencies] | 12 | [dependencies] |
13 | walkdir = "2.3.1" | ||
14 | pico-args = "0.3.1" | ||
15 | quote = "1.0.2" | ||
16 | proc-macro2 = "1.0.8" | ||
17 | anyhow = "1.0.26" | 13 | anyhow = "1.0.26" |
18 | flate2 = "1.0" | 14 | flate2 = "1.0" |
15 | pico-args = "0.3.1" | ||
16 | proc-macro2 = "1.0.8" | ||
17 | quote = "1.0.2" | ||
18 | ungrammar = "0.1.0" | ||
19 | walkdir = "2.3.1" | ||
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 425814d73..83449437b 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs | |||
@@ -223,12 +223,14 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { | |||
223 | ], | 223 | ], |
224 | }; | 224 | }; |
225 | 225 | ||
226 | #[derive(Default, Debug)] | ||
226 | pub(crate) struct AstSrc { | 227 | pub(crate) struct AstSrc { |
227 | pub(crate) tokens: Vec<String>, | 228 | pub(crate) tokens: Vec<String>, |
228 | pub(crate) nodes: Vec<AstNodeSrc>, | 229 | pub(crate) nodes: Vec<AstNodeSrc>, |
229 | pub(crate) enums: Vec<AstEnumSrc>, | 230 | pub(crate) enums: Vec<AstEnumSrc>, |
230 | } | 231 | } |
231 | 232 | ||
233 | #[derive(Debug)] | ||
232 | pub(crate) struct AstNodeSrc { | 234 | pub(crate) struct AstNodeSrc { |
233 | pub(crate) doc: Vec<String>, | 235 | pub(crate) doc: Vec<String>, |
234 | pub(crate) name: String, | 236 | pub(crate) name: String, |
@@ -236,2016 +238,23 @@ pub(crate) struct AstNodeSrc { | |||
236 | pub(crate) fields: Vec<Field>, | 238 | pub(crate) fields: Vec<Field>, |
237 | } | 239 | } |
238 | 240 | ||
241 | #[derive(Debug, Eq, PartialEq)] | ||
239 | pub(crate) enum Field { | 242 | pub(crate) enum Field { |
240 | Token(String), | 243 | Token(String), |
241 | Node { name: String, src: FieldSrc }, | 244 | Node { name: String, src: FieldSrc }, |
242 | } | 245 | } |
243 | 246 | ||
247 | #[derive(Debug, Eq, PartialEq)] | ||
244 | pub(crate) enum FieldSrc { | 248 | pub(crate) enum FieldSrc { |
245 | Shorthand, | 249 | Shorthand, |
246 | Optional(String), | 250 | Optional(String), |
247 | Many(String), | 251 | Many(String), |
248 | } | 252 | } |
249 | 253 | ||
254 | #[derive(Debug)] | ||
250 | pub(crate) struct AstEnumSrc { | 255 | pub(crate) struct AstEnumSrc { |
251 | pub(crate) doc: Vec<String>, | 256 | pub(crate) doc: Vec<String>, |
252 | pub(crate) name: String, | 257 | pub(crate) name: String, |
253 | pub(crate) traits: Vec<String>, | 258 | pub(crate) traits: Vec<String>, |
254 | pub(crate) variants: Vec<String>, | 259 | pub(crate) variants: Vec<String>, |
255 | } | 260 | } |
256 | |||
257 | macro_rules! ast_nodes { | ||
258 | ($( | ||
259 | $(#[doc = $doc:expr])+ | ||
260 | struct $name:ident$(: $($trait:ident),*)? { | ||
261 | $($field_name:ident $(![$token:tt])? $(: $ty:tt)?),*$(,)? | ||
262 | } | ||
263 | )*) => { | ||
264 | vec![$( | ||
265 | AstNodeSrc { | ||
266 | doc: vec![$($doc.to_string()),*], | ||
267 | name: stringify!($name).to_string(), | ||
268 | traits: vec![$($(stringify!($trait).to_string()),*)?], | ||
269 | fields: vec![ | ||
270 | $(field!($(T![$token])? $field_name $($ty)?)),* | ||
271 | ], | ||
272 | |||
273 | } | ||
274 | ),*] | ||
275 | }; | ||
276 | } | ||
277 | |||
278 | macro_rules! field { | ||
279 | (T![$token:tt] T) => { | ||
280 | Field::Token(stringify!($token).to_string()) | ||
281 | }; | ||
282 | ($field_name:ident) => { | ||
283 | Field::Node { name: stringify!($field_name).to_string(), src: FieldSrc::Shorthand } | ||
284 | }; | ||
285 | ($field_name:ident [$ty:ident]) => { | ||
286 | Field::Node { | ||
287 | name: stringify!($field_name).to_string(), | ||
288 | src: FieldSrc::Many(stringify!($ty).to_string()), | ||
289 | } | ||
290 | }; | ||
291 | ($field_name:ident $ty:ident) => { | ||
292 | Field::Node { | ||
293 | name: stringify!($field_name).to_string(), | ||
294 | src: FieldSrc::Optional(stringify!($ty).to_string()), | ||
295 | } | ||
296 | }; | ||
297 | } | ||
298 | |||
299 | macro_rules! ast_enums { | ||
300 | ($( | ||
301 | $(#[doc = $doc:expr])+ | ||
302 | enum $name:ident $(: $($trait:ident),*)? { | ||
303 | $($variant:ident),*$(,)? | ||
304 | } | ||
305 | )*) => { | ||
306 | vec![$( | ||
307 | AstEnumSrc { | ||
308 | doc: vec![$($doc.to_string()),*], | ||
309 | name: stringify!($name).to_string(), | ||
310 | traits: vec![$($(stringify!($trait).to_string()),*)?], | ||
311 | variants: vec![$(stringify!($variant).to_string()),*], | ||
312 | } | ||
313 | ),*] | ||
314 | }; | ||
315 | } | ||
316 | |||
317 | pub(crate) fn rust_ast() -> AstSrc { | ||
318 | AstSrc { | ||
319 | tokens: vec!["Whitespace".into(), "Comment".into(), "String".into(), "RawString".into()], | ||
320 | nodes: ast_nodes! { | ||
321 | /// The entire Rust source file. Includes all top-level inner attributes and module items. | ||
322 | /// | ||
323 | /// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html) | ||
324 | struct SourceFile: ModuleItemOwner, AttrsOwner, DocCommentsOwner { | ||
325 | modules: [Module], | ||
326 | } | ||
327 | |||
328 | /// Function definition either with body or not. | ||
329 | /// Includes all of its attributes and doc comments. | ||
330 | /// | ||
331 | /// ``` | ||
332 | /// ❰ | ||
333 | /// /// Docs | ||
334 | /// #[attr] | ||
335 | /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 | ||
336 | /// where | ||
337 | /// T: Debug | ||
338 | /// { | ||
339 | /// 42 | ||
340 | /// } | ||
341 | /// ❱ | ||
342 | /// | ||
343 | /// extern "C" { | ||
344 | /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱ | ||
345 | /// } | ||
346 | /// ``` | ||
347 | /// | ||
348 | /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
349 | /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions) | ||
350 | struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner { | ||
351 | Abi, | ||
352 | T![const], | ||
353 | T![default], | ||
354 | T![async], | ||
355 | T![unsafe], | ||
356 | T![fn], | ||
357 | ParamList, | ||
358 | RetType, | ||
359 | body: BlockExpr, | ||
360 | T![;] | ||
361 | } | ||
362 | |||
363 | /// Return type annotation. | ||
364 | /// | ||
365 | /// ``` | ||
366 | /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } | ||
367 | /// ``` | ||
368 | /// | ||
369 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
370 | struct RetType { T![->], TypeRef } | ||
371 | |||
372 | /// Struct definition. | ||
373 | /// Includes all of its attributes and doc comments. | ||
374 | /// | ||
375 | /// ``` | ||
376 | /// ❰ | ||
377 | /// /// Docs | ||
378 | /// #[attr] | ||
379 | /// struct Foo<T> where T: Debug { | ||
380 | /// /// Docs | ||
381 | /// #[attr] | ||
382 | /// pub a: u32, | ||
383 | /// b: T, | ||
384 | /// } | ||
385 | /// ❱ | ||
386 | /// | ||
387 | /// ❰ struct Foo; ❱ | ||
388 | /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ | ||
389 | /// ``` | ||
390 | /// | ||
391 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
392 | struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { | ||
393 | T![struct], | ||
394 | FieldDefList, | ||
395 | T![;] | ||
396 | } | ||
397 | |||
398 | /// Union definition. | ||
399 | /// Includes all of its attributes and doc comments. | ||
400 | /// | ||
401 | /// ``` | ||
402 | /// ❰ | ||
403 | /// /// Docs | ||
404 | /// #[attr] | ||
405 | /// pub union Foo<T> where T: Debug { | ||
406 | /// /// Docs | ||
407 | /// #[attr] | ||
408 | /// a: T, | ||
409 | /// b: u32, | ||
410 | /// } | ||
411 | /// ❱ | ||
412 | /// ``` | ||
413 | /// | ||
414 | /// [Reference](https://doc.rust-lang.org/reference/items/unions.html) | ||
415 | struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { | ||
416 | T![union], | ||
417 | RecordFieldDefList, | ||
418 | } | ||
419 | |||
420 | /// Record field definition list including enclosing curly braces. | ||
421 | /// | ||
422 | /// ``` | ||
423 | /// struct Foo // same for union | ||
424 | /// ❰ | ||
425 | /// { | ||
426 | /// a: u32, | ||
427 | /// b: bool, | ||
428 | /// } | ||
429 | /// ❱ | ||
430 | /// ``` | ||
431 | /// | ||
432 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
433 | struct RecordFieldDefList { T!['{'], fields: [RecordFieldDef], T!['}'] } | ||
434 | |||
435 | /// Record field definition including its attributes and doc comments. | ||
436 | /// | ||
437 | /// ` `` | ||
438 | /// same for union | ||
439 | /// struct Foo { | ||
440 | /// ❰ | ||
441 | /// /// Docs | ||
442 | /// #[attr] | ||
443 | /// pub a: u32 | ||
444 | /// ❱ | ||
445 | /// | ||
446 | /// ❰ b: bool ❱ | ||
447 | /// } | ||
448 | /// ``` | ||
449 | /// | ||
450 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
451 | struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { } | ||
452 | |||
453 | /// Tuple field definition list including enclosing parens. | ||
454 | /// | ||
455 | /// ``` | ||
456 | /// struct Foo ❰ (u32, String, Vec<u32>) ❱; | ||
457 | /// ``` | ||
458 | /// | ||
459 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
460 | struct TupleFieldDefList { T!['('], fields: [TupleFieldDef], T![')'] } | ||
461 | |||
462 | /// Tuple field definition including its attributes. | ||
463 | /// | ||
464 | /// ``` | ||
465 | /// struct Foo(❰ #[attr] u32 ❱); | ||
466 | /// ``` | ||
467 | /// | ||
468 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
469 | struct TupleFieldDef: VisibilityOwner, AttrsOwner { | ||
470 | TypeRef, | ||
471 | } | ||
472 | |||
473 | /// Enum definition. | ||
474 | /// Includes all of its attributes and doc comments. | ||
475 | /// | ||
476 | /// ``` | ||
477 | /// ❰ | ||
478 | /// /// Docs | ||
479 | /// #[attr] | ||
480 | /// pub enum Foo<T> where T: Debug { | ||
481 | /// /// Docs | ||
482 | /// #[attr] | ||
483 | /// Bar, | ||
484 | /// Baz(#[attr] u32), | ||
485 | /// Bruh { | ||
486 | /// a: u32, | ||
487 | /// /// Docs | ||
488 | /// #[attr] | ||
489 | /// b: T, | ||
490 | /// } | ||
491 | /// } | ||
492 | /// ❱ | ||
493 | /// ``` | ||
494 | /// | ||
495 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
496 | struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner { | ||
497 | T![enum], | ||
498 | variant_list: EnumVariantList, | ||
499 | } | ||
500 | |||
501 | /// Enum variant definition list including enclosing curly braces. | ||
502 | /// | ||
503 | /// ``` | ||
504 | /// enum Foo | ||
505 | /// ❰ | ||
506 | /// { | ||
507 | /// Bar, | ||
508 | /// Baz(u32), | ||
509 | /// Bruh { | ||
510 | /// a: u32 | ||
511 | /// } | ||
512 | /// } | ||
513 | /// ❱ | ||
514 | /// ``` | ||
515 | /// | ||
516 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
517 | struct EnumVariantList { | ||
518 | T!['{'], | ||
519 | variants: [EnumVariant], | ||
520 | T!['}'] | ||
521 | } | ||
522 | |||
523 | /// Enum variant definition including its attributes and discriminant value definition. | ||
524 | /// | ||
525 | /// ``` | ||
526 | /// enum Foo { | ||
527 | /// ❰ | ||
528 | /// /// Docs | ||
529 | /// #[attr] | ||
530 | /// Bar | ||
531 | /// ❱ | ||
532 | /// | ||
533 | /// // same for tuple and record variants | ||
534 | /// } | ||
535 | /// ``` | ||
536 | /// | ||
537 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
538 | struct EnumVariant: VisibilityOwner, NameOwner, DocCommentsOwner, AttrsOwner { | ||
539 | FieldDefList, | ||
540 | T![=], | ||
541 | Expr | ||
542 | } | ||
543 | |||
544 | /// Trait definition. | ||
545 | /// Includes all of its attributes and doc comments. | ||
546 | /// | ||
547 | /// ``` | ||
548 | /// ❰ | ||
549 | /// /// Docs | ||
550 | /// #[attr] | ||
551 | /// pub unsafe trait Foo<T>: Debug where T: Debug { | ||
552 | /// // ... | ||
553 | /// } | ||
554 | /// ❱ | ||
555 | /// ``` | ||
556 | /// | ||
557 | /// [Reference](https://doc.rust-lang.org/reference/items/traits.html) | ||
558 | struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner { | ||
559 | T![unsafe], | ||
560 | T![auto], | ||
561 | T![trait], | ||
562 | ItemList, | ||
563 | } | ||
564 | |||
565 | /// Module definition either with body or not. | ||
566 | /// Includes all of its inner and outer attributes, module items, doc comments. | ||
567 | /// | ||
568 | /// ``` | ||
569 | /// ❰ | ||
570 | /// /// Docs | ||
571 | /// #[attr] | ||
572 | /// pub mod foo; | ||
573 | /// ❱ | ||
574 | /// | ||
575 | /// ❰ | ||
576 | /// /// Docs | ||
577 | /// #[attr] | ||
578 | /// pub mod bar { | ||
579 | /// //! Inner docs | ||
580 | /// #![inner_attr] | ||
581 | /// } | ||
582 | /// ❱ | ||
583 | /// ``` | ||
584 | /// | ||
585 | /// [Reference](https://doc.rust-lang.org/reference/items/modules.html) | ||
586 | struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner { | ||
587 | T![mod], | ||
588 | ItemList, | ||
589 | T![;] | ||
590 | } | ||
591 | |||
592 | /// Item defintion list. | ||
593 | /// This is used for both top-level items and impl block items. | ||
594 | /// | ||
595 | /// ``` | ||
596 | /// ❰ | ||
597 | /// fn foo {} | ||
598 | /// struct Bar; | ||
599 | /// enum Baz; | ||
600 | /// trait Bruh; | ||
601 | /// const BRUUH: u32 = 42; | ||
602 | /// ❱ | ||
603 | /// | ||
604 | /// impl Foo | ||
605 | /// ❰ | ||
606 | /// { | ||
607 | /// fn bar() {} | ||
608 | /// const BAZ: u32 = 42; | ||
609 | /// } | ||
610 | /// ❱ | ||
611 | /// ``` | ||
612 | /// | ||
613 | /// [Reference](https://doc.rust-lang.org/reference/items.html) | ||
614 | struct ItemList: ModuleItemOwner { | ||
615 | T!['{'], | ||
616 | assoc_items: [AssocItem], | ||
617 | T!['}'] | ||
618 | } | ||
619 | |||
620 | /// Constant variable definition. | ||
621 | /// Includes all of its attributes and doc comments. | ||
622 | /// | ||
623 | /// ``` | ||
624 | /// ❰ | ||
625 | /// /// Docs | ||
626 | /// #[attr] | ||
627 | /// pub const FOO: u32 = 42; | ||
628 | /// ❱ | ||
629 | /// ``` | ||
630 | /// | ||
631 | /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) | ||
632 | struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { | ||
633 | T![default], | ||
634 | T![const], | ||
635 | T![=], | ||
636 | body: Expr, | ||
637 | T![;] | ||
638 | } | ||
639 | |||
640 | |||
641 | /// Static variable definition. | ||
642 | /// Includes all of its attributes and doc comments. | ||
643 | /// | ||
644 | /// ``` | ||
645 | /// ❰ | ||
646 | /// /// Docs | ||
647 | /// #[attr] | ||
648 | /// pub static mut FOO: u32 = 42; | ||
649 | /// ❱ | ||
650 | /// ``` | ||
651 | /// | ||
652 | /// [Reference](https://doc.rust-lang.org/reference/items/static-items.html) | ||
653 | struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { | ||
654 | T![static], | ||
655 | T![mut], | ||
656 | T![=], | ||
657 | body: Expr, | ||
658 | T![;] | ||
659 | } | ||
660 | |||
661 | /// Type alias definition. | ||
662 | /// Includes associated type clauses with type bounds. | ||
663 | /// | ||
664 | /// ``` | ||
665 | /// ❰ | ||
666 | /// /// Docs | ||
667 | /// #[attr] | ||
668 | /// pub type Foo<T> where T: Debug = T; | ||
669 | /// ❱ | ||
670 | /// | ||
671 | /// trait Bar { | ||
672 | /// ❰ type Baz: Debug; ❱ | ||
673 | /// ❰ type Bruh = String; ❱ | ||
674 | /// ❰ type Bruuh: Debug = u32; ❱ | ||
675 | /// } | ||
676 | /// ``` | ||
677 | /// | ||
678 | /// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html) | ||
679 | struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner { | ||
680 | T![default], | ||
681 | T![type], | ||
682 | T![=], | ||
683 | TypeRef, | ||
684 | T![;] | ||
685 | } | ||
686 | |||
687 | /// Inherent and trait impl definition. | ||
688 | /// Includes all of its inner and outer attributes. | ||
689 | /// | ||
690 | /// ``` | ||
691 | /// ❰ | ||
692 | /// #[attr] | ||
693 | /// unsafe impl<T> const !Foo for Bar where T: Debug { | ||
694 | /// #![inner_attr] | ||
695 | /// // ... | ||
696 | /// } | ||
697 | /// ❱ | ||
698 | /// ``` | ||
699 | /// | ||
700 | /// [Reference](https://doc.rust-lang.org/reference/items/implementations.html) | ||
701 | struct ImplDef: TypeParamsOwner, AttrsOwner, DocCommentsOwner { | ||
702 | T![default], | ||
703 | T![const], | ||
704 | T![unsafe], | ||
705 | T![impl], | ||
706 | T![!], | ||
707 | T![for], | ||
708 | ItemList, | ||
709 | } | ||
710 | |||
711 | |||
712 | /// Parenthesized type reference. | ||
713 | /// Note: parens are only used for grouping, this is not a tuple type. | ||
714 | /// | ||
715 | /// ``` | ||
716 | /// // This is effectively just `u32`. | ||
717 | /// // Single-item tuple must be defined with a trailing comma: `(u32,)` | ||
718 | /// type Foo = ❰ (u32) ❱; | ||
719 | /// | ||
720 | /// let bar: &'static ❰ (dyn Debug) ❱ = "bruh"; | ||
721 | /// ``` | ||
722 | struct ParenType { T!['('], TypeRef, T![')'] } | ||
723 | |||
724 | /// Unnamed tuple type. | ||
725 | /// | ||
726 | /// ``` | ||
727 | /// let foo: ❰ (u32, bool) ❱ = (42, true); | ||
728 | /// ``` | ||
729 | /// | ||
730 | /// [Reference](https://doc.rust-lang.org/reference/types/tuple.html) | ||
731 | struct TupleType { T!['('], fields: [TypeRef], T![')'] } | ||
732 | |||
733 | /// The never type (i.e. the exclamation point). | ||
734 | /// | ||
735 | /// ``` | ||
736 | /// type T = ❰ ! ❱; | ||
737 | /// | ||
738 | /// fn no_return() -> ❰ ! ❱ { | ||
739 | /// loop {} | ||
740 | /// } | ||
741 | /// ``` | ||
742 | /// | ||
743 | /// [Reference](https://doc.rust-lang.org/reference/types/never.html) | ||
744 | struct NeverType { T![!] } | ||
745 | |||
746 | /// Path to a type. | ||
747 | /// Includes single identifier type names and elaborate paths with | ||
748 | /// generic parameters. | ||
749 | /// | ||
750 | /// ``` | ||
751 | /// type Foo = ❰ String ❱; | ||
752 | /// type Bar = ❰ std::vec::Vec<T> ❱; | ||
753 | /// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱; | ||
754 | /// ``` | ||
755 | /// | ||
756 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
757 | struct PathType { Path } | ||
758 | |||
759 | /// Raw pointer type. | ||
760 | /// | ||
761 | /// ``` | ||
762 | /// type Foo = ❰ *const u32 ❱; | ||
763 | /// type Bar = ❰ *mut u32 ❱; | ||
764 | /// ``` | ||
765 | /// | ||
766 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut) | ||
767 | struct PointerType { T![*], T![const], T![mut], TypeRef } | ||
768 | |||
769 | /// Array type. | ||
770 | /// | ||
771 | /// ``` | ||
772 | /// type Foo = ❰ [u32; 24 - 3] ❱; | ||
773 | /// ``` | ||
774 | /// | ||
775 | /// [Reference](https://doc.rust-lang.org/reference/types/array.html) | ||
776 | struct ArrayType { T!['['], TypeRef, T![;], Expr, T![']'] } | ||
777 | |||
778 | /// Slice type. | ||
779 | /// | ||
780 | /// ``` | ||
781 | /// type Foo = ❰ [u8] ❱; | ||
782 | /// ``` | ||
783 | /// | ||
784 | /// [Reference](https://doc.rust-lang.org/reference/types/slice.html) | ||
785 | struct SliceType { T!['['], TypeRef, T![']'] } | ||
786 | |||
787 | /// Reference type. | ||
788 | /// | ||
789 | /// ``` | ||
790 | /// type Foo = ❰ &'static str ❱; | ||
791 | /// ``` | ||
792 | /// | ||
793 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html) | ||
794 | struct ReferenceType { T![&], T![lifetime], T![mut], TypeRef } | ||
795 | |||
796 | /// Placeholder type (i.e. the underscore). | ||
797 | /// | ||
798 | /// ``` | ||
799 | /// let foo: ❰ _ ❱ = 42_u32; | ||
800 | /// ``` | ||
801 | /// | ||
802 | /// [Reference](https://doc.rust-lang.org/reference/types/inferred.html) | ||
803 | struct PlaceholderType { T![_] } | ||
804 | |||
805 | /// Function pointer type (not to be confused with `Fn*` family of traits). | ||
806 | /// | ||
807 | /// ``` | ||
808 | /// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱; | ||
809 | /// | ||
810 | /// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱; | ||
811 | /// ``` | ||
812 | /// | ||
813 | /// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html) | ||
814 | struct FnPointerType { Abi, T![unsafe], T![fn], ParamList, RetType } | ||
815 | |||
816 | /// Higher order type. | ||
817 | /// | ||
818 | /// ``` | ||
819 | /// type Foo = ❰ for<'a> fn(&'a str) ❱; | ||
820 | /// ``` | ||
821 | /// | ||
822 | /// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html) | ||
823 | struct ForType { T![for], TypeParamList, TypeRef } | ||
824 | |||
825 | /// Opaque `impl Trait` type. | ||
826 | /// | ||
827 | /// ``` | ||
828 | /// fn foo(bar: ❰ impl Debug + Eq ❱) {} | ||
829 | /// ``` | ||
830 | /// | ||
831 | /// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html) | ||
832 | struct ImplTraitType: TypeBoundsOwner { T![impl] } | ||
833 | |||
834 | /// Trait object type. | ||
835 | /// | ||
836 | /// ``` | ||
837 | /// type Foo = ❰ dyn Debug ❱; | ||
838 | /// ``` | ||
839 | /// | ||
840 | /// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html) | ||
841 | struct DynTraitType: TypeBoundsOwner { T![dyn] } | ||
842 | |||
843 | /// Tuple literal. | ||
844 | /// | ||
845 | /// ``` | ||
846 | /// ❰ (42, true) ❱; | ||
847 | /// ``` | ||
848 | /// | ||
849 | /// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html) | ||
850 | struct TupleExpr: AttrsOwner { T!['('], exprs: [Expr], T![')'] } | ||
851 | |||
852 | /// Array literal. | ||
853 | /// | ||
854 | /// ``` | ||
855 | /// ❰ [#![inner_attr] true, false, true] ❱; | ||
856 | /// | ||
857 | /// ❰ ["baz"; 24] ❱; | ||
858 | /// ``` | ||
859 | /// | ||
860 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
861 | struct ArrayExpr: AttrsOwner { T!['['], exprs: [Expr], T![;], T![']'] } | ||
862 | |||
863 | /// Parenthesized expression. | ||
864 | /// Note: parens are only used for grouping, this is not a tuple literal. | ||
865 | /// | ||
866 | /// ``` | ||
867 | /// ❰ (#![inner_attr] 2 + 2) ❱ * 2; | ||
868 | /// ``` | ||
869 | /// | ||
870 | /// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html) | ||
871 | struct ParenExpr: AttrsOwner { T!['('], Expr, T![')'] } | ||
872 | |||
873 | /// Path to a symbol in expression context. | ||
874 | /// Includes single identifier variable names and elaborate paths with | ||
875 | /// generic parameters. | ||
876 | /// | ||
877 | /// ``` | ||
878 | /// ❰ Some::<i32> ❱; | ||
879 | /// ❰ foo ❱ + 42; | ||
880 | /// ❰ Vec::<i32>::push ❱; | ||
881 | /// ❰ <[i32]>::reverse ❱; | ||
882 | /// ❰ <String as std::borrow::Borrow<str>>::borrow ❱; | ||
883 | /// ``` | ||
884 | /// | ||
885 | /// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html) | ||
886 | struct PathExpr { Path } | ||
887 | |||
888 | /// Anonymous callable object literal a.k.a. closure, lambda or functor. | ||
889 | /// | ||
890 | /// ``` | ||
891 | /// ❰ || 42 ❱; | ||
892 | /// ❰ |a: u32| val + 1 ❱; | ||
893 | /// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱; | ||
894 | /// ❰ move || baz ❱; | ||
895 | /// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱ | ||
896 | /// ``` | ||
897 | /// | ||
898 | /// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html) | ||
899 | struct LambdaExpr: AttrsOwner { | ||
900 | T![static], // Note(@matklad): I belive this is (used to be?) syntax for generators | ||
901 | T![async], | ||
902 | T![move], | ||
903 | ParamList, | ||
904 | RetType, | ||
905 | body: Expr, | ||
906 | } | ||
907 | |||
908 | /// If expression. Includes both regular `if` and `if let` forms. | ||
909 | /// Beware that `else if` is a special case syntax sugar, because in general | ||
910 | /// there has to be block expression after `else`. | ||
911 | /// | ||
912 | /// ``` | ||
913 | /// ❰ if bool_cond { 42 } ❱ | ||
914 | /// ❰ if bool_cond { 42 } else { 24 } ❱ | ||
915 | /// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱ | ||
916 | /// | ||
917 | /// ❰ | ||
918 | /// if let Pattern(foo) = bar { | ||
919 | /// foo | ||
920 | /// } else { | ||
921 | /// panic!(); | ||
922 | /// } | ||
923 | /// ❱ | ||
924 | /// ``` | ||
925 | /// | ||
926 | /// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
927 | struct IfExpr: AttrsOwner { T![if], Condition } | ||
928 | |||
929 | /// Unconditional loop expression. | ||
930 | /// | ||
931 | /// ``` | ||
932 | /// ❰ | ||
933 | /// loop { | ||
934 | /// // yeah, it's that simple... | ||
935 | /// } | ||
936 | /// ❱ | ||
937 | /// ``` | ||
938 | /// | ||
939 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html) | ||
940 | struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } | ||
941 | |||
942 | /// Block expression with an optional prefix (label, try ketword, | ||
943 | /// unsafe keyword, async keyword...). | ||
944 | /// | ||
945 | /// ``` | ||
946 | /// ❰ | ||
947 | /// 'label: try { | ||
948 | /// None? | ||
949 | /// } | ||
950 | /// ❱ | ||
951 | /// ``` | ||
952 | /// | ||
953 | /// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html) | ||
954 | /// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks) | ||
955 | /// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks) | ||
956 | struct EffectExpr: AttrsOwner { Label, T![try], T![unsafe], T![async], BlockExpr } | ||
957 | |||
958 | |||
959 | /// For loop expression. | ||
960 | /// Note: record struct literals are not valid as iterable expression | ||
961 | /// due to ambiguity. | ||
962 | /// | ||
963 | /// ``` | ||
964 | /// ❰ | ||
965 | /// for i in (0..4) { | ||
966 | /// dbg!(i); | ||
967 | /// } | ||
968 | /// ❱ | ||
969 | /// ``` | ||
970 | /// | ||
971 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops) | ||
972 | struct ForExpr: AttrsOwner, LoopBodyOwner { | ||
973 | T![for], | ||
974 | Pat, | ||
975 | T![in], | ||
976 | iterable: Expr, | ||
977 | } | ||
978 | |||
979 | /// While loop expression. Includes both regular `while` and `while let` forms. | ||
980 | /// | ||
981 | /// ``` | ||
982 | /// ❰ | ||
983 | /// while bool_cond { | ||
984 | /// 42; | ||
985 | /// } | ||
986 | /// ❱ | ||
987 | /// ❰ | ||
988 | /// while let Pattern(foo) = bar { | ||
989 | /// bar += 1; | ||
990 | /// } | ||
991 | /// ❱ | ||
992 | /// ``` | ||
993 | /// | ||
994 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
995 | struct WhileExpr: AttrsOwner, LoopBodyOwner { T![while], Condition } | ||
996 | |||
997 | /// Continue expression. | ||
998 | /// | ||
999 | /// ``` | ||
1000 | /// while bool_cond { | ||
1001 | /// ❰ continue ❱; | ||
1002 | /// } | ||
1003 | /// | ||
1004 | /// 'outer: loop { | ||
1005 | /// loop { | ||
1006 | /// ❰ continue 'outer ❱; | ||
1007 | /// } | ||
1008 | /// } | ||
1009 | /// | ||
1010 | /// ``` | ||
1011 | /// | ||
1012 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions) | ||
1013 | struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } | ||
1014 | |||
1015 | /// Break expression. | ||
1016 | /// | ||
1017 | /// ``` | ||
1018 | /// while bool_cond { | ||
1019 | /// ❰ break ❱; | ||
1020 | /// } | ||
1021 | /// 'outer: loop { | ||
1022 | /// for foo in bar { | ||
1023 | /// ❰ break 'outer ❱; | ||
1024 | /// } | ||
1025 | /// } | ||
1026 | /// 'outer: loop { | ||
1027 | /// loop { | ||
1028 | /// ❰ break 'outer 42 ❱; | ||
1029 | /// } | ||
1030 | /// } | ||
1031 | /// ``` | ||
1032 | /// | ||
1033 | /// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions) | ||
1034 | struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } | ||
1035 | |||
1036 | /// Label. | ||
1037 | /// | ||
1038 | /// ``` | ||
1039 | /// ❰ 'outer: ❱ loop {} | ||
1040 | /// | ||
1041 | /// let foo = ❰ 'bar: ❱ loop {} | ||
1042 | /// | ||
1043 | /// ❰ 'baz: ❱ { | ||
1044 | /// break 'baz; | ||
1045 | /// } | ||
1046 | /// ``` | ||
1047 | /// | ||
1048 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels) | ||
1049 | /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) | ||
1050 | struct Label { T![lifetime] } | ||
1051 | |||
1052 | /// Block expression. Includes unsafe blocks and block labels. | ||
1053 | /// | ||
1054 | /// ``` | ||
1055 | /// let foo = ❰ | ||
1056 | /// { | ||
1057 | /// #![inner_attr] | ||
1058 | /// ❰ { } ❱ | ||
1059 | /// | ||
1060 | /// ❰ 'label: { break 'label } ❱ | ||
1061 | /// } | ||
1062 | /// ❱; | ||
1063 | /// ``` | ||
1064 | /// | ||
1065 | /// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html) | ||
1066 | /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) | ||
1067 | struct BlockExpr: AttrsOwner, ModuleItemOwner { | ||
1068 | Label, T!['{'], statements: [Stmt], Expr, T!['}'], | ||
1069 | } | ||
1070 | |||
1071 | /// Return expression. | ||
1072 | /// | ||
1073 | /// ``` | ||
1074 | /// || ❰ return 42 ❱; | ||
1075 | /// | ||
1076 | /// fn bar() { | ||
1077 | /// ❰ return ❱; | ||
1078 | /// } | ||
1079 | /// ``` | ||
1080 | /// | ||
1081 | /// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html) | ||
1082 | struct ReturnExpr: AttrsOwner { Expr } | ||
1083 | |||
1084 | /// Call expression (not to be confused with method call expression, it is | ||
1085 | /// a separate ast node). | ||
1086 | /// | ||
1087 | /// ``` | ||
1088 | /// ❰ foo() ❱; | ||
1089 | /// ❰ &str::len("bar") ❱; | ||
1090 | /// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱; | ||
1091 | /// ``` | ||
1092 | /// | ||
1093 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
1094 | struct CallExpr: ArgListOwner { Expr } | ||
1095 | |||
1096 | /// Method call expression. | ||
1097 | /// | ||
1098 | /// ``` | ||
1099 | /// ❰ receiver_expr.method() ❱; | ||
1100 | /// ❰ receiver_expr.method::<T>(42, true) ❱; | ||
1101 | /// | ||
1102 | /// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱; | ||
1103 | /// ``` | ||
1104 | /// | ||
1105 | /// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html) | ||
1106 | struct MethodCallExpr: AttrsOwner, ArgListOwner { | ||
1107 | Expr, T![.], NameRef, TypeArgList, | ||
1108 | } | ||
1109 | |||
1110 | /// Index expression a.k.a. subscript operator call. | ||
1111 | /// | ||
1112 | /// ``` | ||
1113 | /// ❰ foo[42] ❱; | ||
1114 | /// ``` | ||
1115 | /// | ||
1116 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
1117 | struct IndexExpr: AttrsOwner { T!['['], T![']'] } | ||
1118 | |||
1119 | /// Field access expression. | ||
1120 | /// | ||
1121 | /// ``` | ||
1122 | /// ❰ expr.bar ❱; | ||
1123 | /// | ||
1124 | /// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱; | ||
1125 | /// ``` | ||
1126 | /// | ||
1127 | /// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html) | ||
1128 | struct FieldExpr: AttrsOwner { Expr, T![.], NameRef } | ||
1129 | |||
1130 | /// Await operator call expression. | ||
1131 | /// | ||
1132 | /// ``` | ||
1133 | /// ❰ expr.await ❱; | ||
1134 | /// ``` | ||
1135 | /// | ||
1136 | /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html) | ||
1137 | struct AwaitExpr: AttrsOwner { Expr, T![.], T![await] } | ||
1138 | |||
1139 | /// The question mark operator call. | ||
1140 | /// | ||
1141 | /// ``` | ||
1142 | /// ❰ expr? ❱; | ||
1143 | /// ``` | ||
1144 | /// | ||
1145 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator) | ||
1146 | struct TryExpr: AttrsOwner { Expr, T![?] } | ||
1147 | |||
1148 | /// Type cast expression. | ||
1149 | /// | ||
1150 | /// ``` | ||
1151 | /// ❰ expr as T ❱; | ||
1152 | /// ``` | ||
1153 | /// | ||
1154 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions) | ||
1155 | struct CastExpr: AttrsOwner { Expr, T![as], TypeRef } | ||
1156 | |||
1157 | |||
1158 | /// Borrow operator call. | ||
1159 | /// | ||
1160 | /// ``` | ||
1161 | /// ❰ &foo ❱; | ||
1162 | /// ❰ &mut bar ❱; | ||
1163 | /// ❰ &raw const bar ❱; | ||
1164 | /// ❰ &raw mut bar ❱; | ||
1165 | /// ``` | ||
1166 | /// | ||
1167 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators) | ||
1168 | struct RefExpr: AttrsOwner { T![&], T![raw], T![mut], T![const], Expr } | ||
1169 | |||
1170 | /// Prefix operator call. This is either `!` or `*` or `-`. | ||
1171 | /// | ||
1172 | /// ``` | ||
1173 | /// ❰ !foo ❱; | ||
1174 | /// ❰ *bar ❱; | ||
1175 | /// ❰ -42 ❱; | ||
1176 | /// ``` | ||
1177 | /// | ||
1178 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html) | ||
1179 | struct PrefixExpr: AttrsOwner { /*PrefixOp,*/ Expr } | ||
1180 | |||
1181 | /// Box operator call. | ||
1182 | /// | ||
1183 | /// ``` | ||
1184 | /// ❰ box 42 ❱; | ||
1185 | /// ``` | ||
1186 | /// | ||
1187 | /// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md) | ||
1188 | struct BoxExpr: AttrsOwner { T![box], Expr } | ||
1189 | |||
1190 | /// Range operator call. | ||
1191 | /// | ||
1192 | /// ``` | ||
1193 | /// ❰ 0..42 ❱; | ||
1194 | /// ❰ ..42 ❱; | ||
1195 | /// ❰ 0.. ❱; | ||
1196 | /// ❰ .. ❱; | ||
1197 | /// ❰ 0..=42 ❱; | ||
1198 | /// ❰ ..=42 ❱; | ||
1199 | /// ``` | ||
1200 | /// | ||
1201 | /// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html) | ||
1202 | struct RangeExpr: AttrsOwner { /*RangeOp*/ } | ||
1203 | |||
1204 | |||
1205 | /// Binary operator call. | ||
1206 | /// Includes all arithmetic, logic, bitwise and assignment operators. | ||
1207 | /// | ||
1208 | /// ``` | ||
1209 | /// ❰ 2 + ❰ 2 * 2 ❱ ❱; | ||
1210 | /// ❰ ❰ true && false ❱ || true ❱; | ||
1211 | /// ``` | ||
1212 | /// | ||
1213 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators) | ||
1214 | struct BinExpr: AttrsOwner { /*BinOp*/ } | ||
1215 | |||
1216 | |||
1217 | /// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal. | ||
1218 | /// | ||
1219 | /// ``` | ||
1220 | /// ❰ "str" ❱; | ||
1221 | /// ❰ br##"raw byte str"## ❱; | ||
1222 | /// ❰ 'c' ❱; | ||
1223 | /// ❰ b'c' ❱; | ||
1224 | /// ❰ 42 ❱; | ||
1225 | /// ❰ 1e9 ❱; | ||
1226 | /// ❰ true ❱; | ||
1227 | /// ``` | ||
1228 | /// | ||
1229 | /// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html) | ||
1230 | struct Literal { /*LiteralToken*/ } | ||
1231 | |||
1232 | /// Match expression. | ||
1233 | /// | ||
1234 | /// ``` | ||
1235 | /// ❰ | ||
1236 | /// match expr { | ||
1237 | /// Pat1 => {} | ||
1238 | /// Pat2(_) => 42, | ||
1239 | /// } | ||
1240 | /// ❱ | ||
1241 | /// ``` | ||
1242 | /// | ||
1243 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
1244 | struct MatchExpr: AttrsOwner { T![match], Expr, MatchArmList } | ||
1245 | |||
1246 | /// Match arm list part of match expression. Includes its inner attributes. | ||
1247 | /// | ||
1248 | /// ``` | ||
1249 | /// match expr | ||
1250 | /// ❰ | ||
1251 | /// { | ||
1252 | /// #![inner_attr] | ||
1253 | /// Pat1 => {} | ||
1254 | /// Pat2(_) => 42, | ||
1255 | /// } | ||
1256 | /// ❱ | ||
1257 | /// ``` | ||
1258 | /// | ||
1259 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
1260 | struct MatchArmList: AttrsOwner { T!['{'], arms: [MatchArm], T!['}'] } | ||
1261 | |||
1262 | |||
1263 | /// Match arm. | ||
1264 | /// Note: record struct literals are not valid as target match expression | ||
1265 | /// due to ambiguity. | ||
1266 | /// ``` | ||
1267 | /// match expr { | ||
1268 | /// ❰ #[attr] Pattern(it) if bool_cond => it ❱, | ||
1269 | /// } | ||
1270 | /// ``` | ||
1271 | /// | ||
1272 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
1273 | struct MatchArm: AttrsOwner { | ||
1274 | pat: Pat, | ||
1275 | guard: MatchGuard, | ||
1276 | T![=>], | ||
1277 | Expr, | ||
1278 | } | ||
1279 | |||
1280 | /// Match guard. | ||
1281 | /// | ||
1282 | /// ``` | ||
1283 | /// match expr { | ||
1284 | /// Pattern(it) ❰ if bool_cond ❱ => it, | ||
1285 | /// } | ||
1286 | /// ``` | ||
1287 | /// | ||
1288 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards) | ||
1289 | struct MatchGuard { T![if], Expr } | ||
1290 | |||
1291 | /// Record literal expression. The same syntax is used for structs, | ||
1292 | /// unions and record enum variants. | ||
1293 | /// | ||
1294 | /// ``` | ||
1295 | /// ❰ | ||
1296 | /// foo::Bar { | ||
1297 | /// #![inner_attr] | ||
1298 | /// baz: 42, | ||
1299 | /// bruh: true, | ||
1300 | /// ..spread | ||
1301 | /// } | ||
1302 | /// ❱ | ||
1303 | /// ``` | ||
1304 | /// | ||
1305 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
1306 | struct RecordLit { Path, RecordFieldList} | ||
1307 | |||
1308 | /// Record field list including enclosing curly braces. | ||
1309 | /// | ||
1310 | /// foo::Bar ❰ | ||
1311 | /// { | ||
1312 | /// baz: 42, | ||
1313 | /// ..spread | ||
1314 | /// } | ||
1315 | /// ❱ | ||
1316 | /// | ||
1317 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
1318 | struct RecordFieldList { | ||
1319 | T!['{'], | ||
1320 | fields: [RecordField], | ||
1321 | T![..], | ||
1322 | spread: Expr, | ||
1323 | T!['}'] | ||
1324 | } | ||
1325 | |||
1326 | /// Record field. | ||
1327 | /// | ||
1328 | /// ``` | ||
1329 | /// foo::Bar { | ||
1330 | /// ❰ #[attr] baz: 42 ❱ | ||
1331 | /// } | ||
1332 | /// ``` | ||
1333 | /// | ||
1334 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
1335 | struct RecordField: AttrsOwner { NameRef, T![:], Expr } | ||
1336 | |||
1337 | /// Disjunction of patterns. | ||
1338 | /// | ||
1339 | /// ``` | ||
1340 | /// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh; | ||
1341 | /// ``` | ||
1342 | /// | ||
1343 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html) | ||
1344 | struct OrPat { pats: [Pat] } | ||
1345 | |||
1346 | /// Parenthesized pattern. | ||
1347 | /// Note: parens are only used for grouping, this is not a tuple pattern. | ||
1348 | /// | ||
1349 | /// ``` | ||
1350 | /// if let ❰ &(0..=42) ❱ = foo {} | ||
1351 | /// ``` | ||
1352 | /// | ||
1353 | /// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns | ||
1354 | struct ParenPat { T!['('], Pat, T![')'] } | ||
1355 | |||
1356 | /// Reference pattern. | ||
1357 | /// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns. | ||
1358 | /// | ||
1359 | /// ``` | ||
1360 | /// let ❰ &mut foo ❱ = bar; | ||
1361 | /// | ||
1362 | /// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz; | ||
1363 | /// ``` | ||
1364 | /// | ||
1365 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns) | ||
1366 | struct RefPat { T![&], T![mut], Pat } | ||
1367 | |||
1368 | /// Box pattern. | ||
1369 | /// | ||
1370 | /// ``` | ||
1371 | /// let ❰ box foo ❱ = box 42; | ||
1372 | /// ``` | ||
1373 | /// | ||
1374 | /// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html) | ||
1375 | struct BoxPat { T![box], Pat } | ||
1376 | |||
1377 | /// Bind pattern. | ||
1378 | /// | ||
1379 | /// ``` | ||
1380 | /// match foo { | ||
1381 | /// Some(❰ ref mut bar ❱) => {} | ||
1382 | /// ❰ baz @ None ❱ => {} | ||
1383 | /// } | ||
1384 | /// ``` | ||
1385 | /// | ||
1386 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns) | ||
1387 | struct BindPat: AttrsOwner, NameOwner { T![ref], T![mut], T![@], Pat } | ||
1388 | |||
1389 | /// Placeholder pattern a.k.a. the wildcard pattern or the underscore. | ||
1390 | /// | ||
1391 | /// ``` | ||
1392 | /// let ❰ _ ❱ = foo; | ||
1393 | /// ``` | ||
1394 | /// | ||
1395 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern) | ||
1396 | struct PlaceholderPat { T![_] } | ||
1397 | |||
1398 | /// Rest-of-the record/tuple pattern. | ||
1399 | /// Note: this is not the unbonded range pattern (even more: it doesn't exist). | ||
1400 | /// | ||
1401 | /// ``` | ||
1402 | /// let Foo { bar, ❰ .. ❱ } = baz; | ||
1403 | /// let (❰ .. ❱, bruh) = (42, 24, 42); | ||
1404 | /// let Bruuh(❰ .. ❱) = bruuuh; | ||
1405 | /// ``` | ||
1406 | /// | ||
1407 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
1408 | struct DotDotPat { T![..] } | ||
1409 | |||
1410 | /// Path pattern. | ||
1411 | /// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`). | ||
1412 | /// | ||
1413 | /// ``` | ||
1414 | /// let ❰ foo::bar::Baz ❱ { .. } = bruh; | ||
1415 | /// if let ❰ CONST ❱ = 42 {} | ||
1416 | /// ``` | ||
1417 | /// | ||
1418 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns) | ||
1419 | struct PathPat { Path } | ||
1420 | |||
1421 | /// Slice pattern. | ||
1422 | /// | ||
1423 | /// ``` | ||
1424 | /// let ❰ [foo, bar, baz] ❱ = [1, 2, 3]; | ||
1425 | /// ``` | ||
1426 | /// | ||
1427 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns) | ||
1428 | struct SlicePat { T!['['], args: [Pat], T![']'] } | ||
1429 | |||
1430 | /// Range pattern. | ||
1431 | /// | ||
1432 | /// ``` | ||
1433 | /// match foo { | ||
1434 | /// ❰ 0..42 ❱ => {} | ||
1435 | /// ❰ 0..=42 ❱ => {} | ||
1436 | /// } | ||
1437 | /// ``` | ||
1438 | /// | ||
1439 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns) | ||
1440 | struct RangePat { } // FIXME(@matklad): here should be T![..], T![..=] I think, if we don't already have an accessor in expresions_ext | ||
1441 | |||
1442 | /// Literal pattern. | ||
1443 | /// Includes only bool, number, char, and string literals. | ||
1444 | /// | ||
1445 | /// ``` | ||
1446 | /// match foo { | ||
1447 | /// Number(❰ 42 ❱) => {} | ||
1448 | /// String(❰ "42" ❱) => {} | ||
1449 | /// Bool(❰ true ❱) => {} | ||
1450 | /// } | ||
1451 | /// ``` | ||
1452 | /// | ||
1453 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns) | ||
1454 | struct LiteralPat { Literal } | ||
1455 | |||
1456 | /// Macro invocation in pattern position. | ||
1457 | /// | ||
1458 | /// ``` | ||
1459 | /// let ❰ foo!(my custom syntax) ❱ = baz; | ||
1460 | /// | ||
1461 | /// ``` | ||
1462 | /// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation) | ||
1463 | struct MacroPat { MacroCall } | ||
1464 | |||
1465 | /// Record literal pattern. | ||
1466 | /// | ||
1467 | /// ``` | ||
1468 | /// let ❰ foo::Bar { baz, .. } ❱ = bruh; | ||
1469 | /// ``` | ||
1470 | /// | ||
1471 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
1472 | struct RecordPat { RecordFieldPatList, Path } | ||
1473 | |||
1474 | /// Record literal's field patterns list including enclosing curly braces. | ||
1475 | /// | ||
1476 | /// ``` | ||
1477 | /// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh; | ||
1478 | /// `` | ||
1479 | /// | ||
1480 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
1481 | struct RecordFieldPatList { | ||
1482 | T!['{'], | ||
1483 | pats: [RecordInnerPat], | ||
1484 | record_field_pats: [RecordFieldPat], | ||
1485 | bind_pats: [BindPat], | ||
1486 | T![..], | ||
1487 | T!['}'] | ||
1488 | } | ||
1489 | |||
1490 | /// Record literal's field pattern. | ||
1491 | /// Note: record literal can also match tuple structs. | ||
1492 | /// | ||
1493 | /// ``` | ||
1494 | /// let Foo { ❰ bar: _ ❱ } = baz; | ||
1495 | /// let TupleStruct { ❰ 0: _ ❱ } = bruh; | ||
1496 | /// ``` | ||
1497 | /// | ||
1498 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
1499 | struct RecordFieldPat: AttrsOwner { NameRef, T![:], Pat } | ||
1500 | |||
1501 | /// Tuple struct literal pattern. | ||
1502 | /// | ||
1503 | /// ``` | ||
1504 | /// let ❰ foo::Bar(baz, bruh) ❱ = bruuh; | ||
1505 | /// ``` | ||
1506 | /// | ||
1507 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns) | ||
1508 | struct TupleStructPat { Path, T!['('], args: [Pat], T![')'] } | ||
1509 | |||
1510 | /// Tuple pattern. | ||
1511 | /// Note: this doesn't include tuple structs (see `TupleStructPat`) | ||
1512 | /// | ||
1513 | /// ``` | ||
1514 | /// let ❰ (foo, bar, .., baz) ❱ = bruh; | ||
1515 | /// ``` | ||
1516 | /// | ||
1517 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns) | ||
1518 | struct TuplePat { T!['('], args: [Pat], T![')'] } | ||
1519 | |||
1520 | /// Visibility. | ||
1521 | /// | ||
1522 | /// ``` | ||
1523 | /// ❰ pub mod ❱ foo; | ||
1524 | /// ❰ pub(crate) ❱ struct Bar; | ||
1525 | /// ❰ pub(self) ❱ enum Baz {} | ||
1526 | /// ❰ pub(super) ❱ fn bruh() {} | ||
1527 | /// ❰ pub(in bruuh::bruuuh) ❱ type T = u64; | ||
1528 | /// ``` | ||
1529 | /// | ||
1530 | /// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html) | ||
1531 | struct Visibility { T![pub], T![super], T![self], T![crate] } | ||
1532 | |||
1533 | /// Single identifier. | ||
1534 | /// Note(@matklad): `Name` is for things that install a new name into the scope, | ||
1535 | /// `NameRef` is a usage of a name. Most of the time, this definition/reference | ||
1536 | /// distinction can be determined purely syntactically, ie in | ||
1537 | /// ``` | ||
1538 | /// fn foo() { foo() } | ||
1539 | /// ``` | ||
1540 | /// the first foo is `Name`, the second one is `NameRef`. | ||
1541 | /// The notable exception are patterns, where in | ||
1542 | /// `` | ||
1543 | /// let x = 92 | ||
1544 | /// ``` | ||
1545 | /// `x` can be semantically either a name or a name ref, depeding on | ||
1546 | /// wether there's an `x` constant in scope. | ||
1547 | /// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db). | ||
1548 | /// | ||
1549 | /// ``` | ||
1550 | /// let ❰ foo ❱ = bar; | ||
1551 | /// struct ❰ Baz ❱; | ||
1552 | /// fn ❰ bruh ❱() {} | ||
1553 | /// ``` | ||
1554 | /// | ||
1555 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
1556 | struct Name { T![ident] } | ||
1557 | |||
1558 | /// Reference to a name. | ||
1559 | /// See the explanation on the difference between `Name` and `NameRef` | ||
1560 | /// in `Name` ast node docs. | ||
1561 | /// | ||
1562 | /// ``` | ||
1563 | /// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱; | ||
1564 | /// ``` | ||
1565 | /// | ||
1566 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
1567 | struct NameRef { } | ||
1568 | |||
1569 | /// Macro call. | ||
1570 | /// Includes all of its attributes and doc comments. | ||
1571 | /// | ||
1572 | /// ``` | ||
1573 | /// ❰ | ||
1574 | /// /// Docs | ||
1575 | /// #[attr] | ||
1576 | /// macro_rules! foo { // macro rules is also a macro call | ||
1577 | /// ($bar: tt) => {} | ||
1578 | /// } | ||
1579 | /// ❱ | ||
1580 | /// | ||
1581 | /// // semicolon is a part of `MacroCall` when it is used in item positions | ||
1582 | /// ❰ foo!(); ❱ | ||
1583 | /// | ||
1584 | /// fn main() { | ||
1585 | /// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi | ||
1586 | /// } | ||
1587 | /// ``` | ||
1588 | /// | ||
1589 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1590 | struct MacroCall: NameOwner, AttrsOwner, DocCommentsOwner { | ||
1591 | Path, T![!], TokenTree, T![;] | ||
1592 | } | ||
1593 | |||
1594 | /// Attribute. | ||
1595 | /// | ||
1596 | /// ``` | ||
1597 | /// ❰ #![inner_attr] ❱ | ||
1598 | /// | ||
1599 | /// ❰ #[attr] ❱ | ||
1600 | /// ❰ #[foo = "bar"] ❱ | ||
1601 | /// ❰ #[baz(bruh::bruuh = "42")] ❱ | ||
1602 | /// struct Foo; | ||
1603 | /// ``` | ||
1604 | /// | ||
1605 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html) | ||
1606 | struct Attr { T![#], T![!], T!['['], Path, T![=], input: AttrInput, T![']'] } | ||
1607 | |||
1608 | /// Stores a list of lexer tokens and other `TokenTree`s. | ||
1609 | /// It appears in attributes, macro_rules and macro call (foo!) | ||
1610 | /// | ||
1611 | /// ``` | ||
1612 | /// macro_call! ❰ { my syntax here } ❱; | ||
1613 | /// ``` | ||
1614 | /// | ||
1615 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1616 | struct TokenTree {} | ||
1617 | |||
1618 | /// Generic lifetime, type and constants parameters list **declaration**. | ||
1619 | /// | ||
1620 | /// ``` | ||
1621 | /// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {} | ||
1622 | /// | ||
1623 | /// struct Baz❰ <T> ❱(T); | ||
1624 | /// | ||
1625 | /// impl❰ <T> ❱ Bruh<T> {} | ||
1626 | /// | ||
1627 | /// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str; | ||
1628 | /// ``` | ||
1629 | /// | ||
1630 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1631 | struct TypeParamList { | ||
1632 | T![<], | ||
1633 | generic_params: [GenericParam], | ||
1634 | type_params: [TypeParam], | ||
1635 | lifetime_params: [LifetimeParam], | ||
1636 | const_params: [ConstParam], | ||
1637 | T![>] | ||
1638 | } | ||
1639 | |||
1640 | /// Single type parameter **declaration**. | ||
1641 | /// | ||
1642 | /// ``` | ||
1643 | /// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {} | ||
1644 | /// ``` | ||
1645 | /// | ||
1646 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1647 | struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner { | ||
1648 | T![=], | ||
1649 | default_type: TypeRef, | ||
1650 | } | ||
1651 | |||
1652 | /// Const generic parameter **declaration**. | ||
1653 | /// ``` | ||
1654 | /// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {} | ||
1655 | /// ``` | ||
1656 | /// | ||
1657 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
1658 | struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner { | ||
1659 | T![=], | ||
1660 | default_val: Expr, | ||
1661 | } | ||
1662 | |||
1663 | /// Lifetime parameter **declaration**. | ||
1664 | /// | ||
1665 | /// ``` | ||
1666 | /// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {} | ||
1667 | /// ``` | ||
1668 | /// | ||
1669 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html) | ||
1670 | struct LifetimeParam: AttrsOwner { T![lifetime] } | ||
1671 | |||
1672 | /// Type bound declaration clause. | ||
1673 | /// | ||
1674 | /// ``` | ||
1675 | /// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {} | ||
1676 | /// | ||
1677 | /// trait Bar<T> | ||
1678 | /// where | ||
1679 | /// T: ❰ Send ❱ + ❰ Sync ❱ | ||
1680 | /// { | ||
1681 | /// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱; | ||
1682 | /// } | ||
1683 | /// ``` | ||
1684 | /// | ||
1685 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
1686 | struct TypeBound { T![lifetime], /* Question, */ T![const], /* Question, */ TypeRef } | ||
1687 | |||
1688 | /// Type bounds list. | ||
1689 | /// | ||
1690 | /// ``` | ||
1691 | /// | ||
1692 | /// fn foo<T: ❰ ?Sized + Debug ❱>() {} | ||
1693 | /// | ||
1694 | /// trait Bar<T> | ||
1695 | /// where | ||
1696 | /// T: ❰ Send + Sync ❱ | ||
1697 | /// { | ||
1698 | /// type Baz: ❰ !Sync + Debug ❱; | ||
1699 | /// } | ||
1700 | /// ``` | ||
1701 | /// | ||
1702 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
1703 | struct TypeBoundList { bounds: [TypeBound] } | ||
1704 | |||
1705 | /// Single where predicate. | ||
1706 | /// | ||
1707 | /// ``` | ||
1708 | /// trait Foo<'a, 'b, T> | ||
1709 | /// where | ||
1710 | /// ❰ 'a: 'b ❱, | ||
1711 | /// ❰ T: IntoIterator ❱, | ||
1712 | /// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱ | ||
1713 | /// {} | ||
1714 | /// ``` | ||
1715 | /// | ||
1716 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
1717 | struct WherePred: TypeBoundsOwner { T![for], TypeParamList, T![lifetime], TypeRef } | ||
1718 | |||
1719 | /// Where clause. | ||
1720 | /// | ||
1721 | /// ``` | ||
1722 | /// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {} | ||
1723 | /// | ||
1724 | /// ``` | ||
1725 | /// | ||
1726 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
1727 | struct WhereClause { T![where], predicates: [WherePred] } | ||
1728 | |||
1729 | /// Abi declaration. | ||
1730 | /// Note: the abi string is optional. | ||
1731 | /// | ||
1732 | /// ``` | ||
1733 | /// ❰ extern "C" ❱ { | ||
1734 | /// fn foo() {} | ||
1735 | /// } | ||
1736 | /// | ||
1737 | /// type Bar = ❰ extern ❱ fn() -> u32; | ||
1738 | /// | ||
1739 | /// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool; | ||
1740 | /// ``` | ||
1741 | /// | ||
1742 | /// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
1743 | /// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions) | ||
1744 | struct Abi { /*String*/ } | ||
1745 | |||
1746 | /// Expression statement. | ||
1747 | /// | ||
1748 | /// ``` | ||
1749 | /// ❰ 42; ❱ | ||
1750 | /// ❰ foo(); ❱ | ||
1751 | /// ❰ (); ❱ | ||
1752 | /// ❰ {}; ❱ | ||
1753 | /// | ||
1754 | /// // constructions with trailing curly brace can omit the semicolon | ||
1755 | /// // but only when there are satements immediately after them (this is important!) | ||
1756 | /// ❰ if bool_cond { } ❱ | ||
1757 | /// ❰ loop {} ❱ | ||
1758 | /// ❰ somestatment; ❱ | ||
1759 | /// ``` | ||
1760 | /// | ||
1761 | /// [Reference](https://doc.rust-lang.org/reference/statements.html) | ||
1762 | struct ExprStmt: AttrsOwner { Expr, T![;] } | ||
1763 | |||
1764 | /// Let statement. | ||
1765 | /// | ||
1766 | /// ``` | ||
1767 | /// ❰ #[attr] let foo; ❱ | ||
1768 | /// ❰ let bar: u64; ❱ | ||
1769 | /// ❰ let baz = 42; ❱ | ||
1770 | /// ❰ let bruh: bool = true; ❱ | ||
1771 | /// ``` | ||
1772 | /// | ||
1773 | /// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements) | ||
1774 | struct LetStmt: AttrsOwner, TypeAscriptionOwner { | ||
1775 | T![let], | ||
1776 | Pat, | ||
1777 | T![=], | ||
1778 | initializer: Expr, | ||
1779 | T![;], | ||
1780 | } | ||
1781 | |||
1782 | /// Condition of `if` or `while` expression. | ||
1783 | /// | ||
1784 | /// ``` | ||
1785 | /// if ❰ true ❱ {} | ||
1786 | /// if ❰ let Pat(foo) = bar ❱ {} | ||
1787 | /// | ||
1788 | /// while ❰ true ❱ {} | ||
1789 | /// while ❰ let Pat(baz) = bruh ❱ {} | ||
1790 | /// ``` | ||
1791 | /// | ||
1792 | /// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
1793 | /// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
1794 | struct Condition { T![let], Pat, T![=], Expr } | ||
1795 | |||
1796 | /// Parameter list **declaration**. | ||
1797 | /// | ||
1798 | /// ``` | ||
1799 | /// fn foo❰ (a: u32, b: bool) ❱ -> u32 {} | ||
1800 | /// let bar = ❰ |a, b| ❱ {}; | ||
1801 | /// | ||
1802 | /// impl Baz { | ||
1803 | /// fn bruh❰ (&self, a: u32) ❱ {} | ||
1804 | /// } | ||
1805 | /// ``` | ||
1806 | /// | ||
1807 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script | ||
1808 | struct ParamList { // FIXME: this node is used by closure expressions too, but hey use pipes instead of parens... | ||
1809 | T!['('], | ||
1810 | SelfParam, | ||
1811 | params: [Param], | ||
1812 | T![')'] | ||
1813 | } | ||
1814 | |||
1815 | /// Self parameter **declaration**. | ||
1816 | /// | ||
1817 | /// ``` | ||
1818 | /// impl Bruh { | ||
1819 | /// fn foo(❰ self ❱) {} | ||
1820 | /// fn bar(❰ &self ❱) {} | ||
1821 | /// fn baz(❰ &mut self ❱) {} | ||
1822 | /// fn blah<'a>(❰ &'a self ❱) {} | ||
1823 | /// fn blin(❰ self: Box<Self> ❱) {} | ||
1824 | /// } | ||
1825 | /// ``` | ||
1826 | /// | ||
1827 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
1828 | struct SelfParam: TypeAscriptionOwner, AttrsOwner { T![&], T![mut], T![lifetime], T![self] } | ||
1829 | |||
1830 | /// Parameter **declaration**. | ||
1831 | /// | ||
1832 | /// ``` | ||
1833 | /// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {} | ||
1834 | /// | ||
1835 | /// extern "C" { | ||
1836 | /// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32; | ||
1837 | /// } | ||
1838 | /// ``` | ||
1839 | /// | ||
1840 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
1841 | struct Param: TypeAscriptionOwner, AttrsOwner { | ||
1842 | Pat, | ||
1843 | T![...] | ||
1844 | } | ||
1845 | |||
1846 | /// Use declaration. | ||
1847 | /// | ||
1848 | /// ``` | ||
1849 | /// ❰ #[attr] pub use foo; ❱ | ||
1850 | /// ❰ use bar as baz; ❱ | ||
1851 | /// ❰ use bruh::{self, bruuh}; ❱ | ||
1852 | /// ❰ use { blin::blen, blah::* }; | ||
1853 | /// ``` | ||
1854 | /// | ||
1855 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1856 | struct UseItem: AttrsOwner, VisibilityOwner { | ||
1857 | T![use], | ||
1858 | UseTree, | ||
1859 | } | ||
1860 | |||
1861 | /// Use tree. | ||
1862 | /// | ||
1863 | /// ``` | ||
1864 | /// pub use ❰ foo::❰ * ❱ ❱; | ||
1865 | /// use ❰ bar as baz ❱; | ||
1866 | /// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱; | ||
1867 | /// use ❰ { ❰ blin::blen ❱ } ❱ | ||
1868 | /// ``` | ||
1869 | /// | ||
1870 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1871 | struct UseTree { | ||
1872 | Path, T![*], UseTreeList, Alias | ||
1873 | } | ||
1874 | |||
1875 | /// Item alias. | ||
1876 | /// Note: this is not the type alias. | ||
1877 | /// | ||
1878 | /// ``` | ||
1879 | /// use foo ❰ as bar ❱; | ||
1880 | /// use baz::{bruh ❰ as _ ❱}; | ||
1881 | /// extern crate bruuh ❰ as blin ❱; | ||
1882 | /// ``` | ||
1883 | /// | ||
1884 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1885 | struct Alias: NameOwner { T![as] } | ||
1886 | |||
1887 | /// Sublist of use trees. | ||
1888 | /// | ||
1889 | /// ``` | ||
1890 | /// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱; | ||
1891 | /// use ❰ { blin::blen::❰ {} ❱ } ❱ | ||
1892 | /// ``` | ||
1893 | /// | ||
1894 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1895 | struct UseTreeList { T!['{'], use_trees: [UseTree], T!['}'] } | ||
1896 | |||
1897 | /// Extern crate item. | ||
1898 | /// | ||
1899 | /// ``` | ||
1900 | /// ❰ #[attr] pub extern crate foo; ❱ | ||
1901 | /// ❰ extern crate self as bar; ❱ | ||
1902 | /// ``` | ||
1903 | /// | ||
1904 | /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) | ||
1905 | struct ExternCrateItem: AttrsOwner, VisibilityOwner { | ||
1906 | T![extern], T![crate], NameRef, Alias, | ||
1907 | } | ||
1908 | |||
1909 | /// Call site arguments list. | ||
1910 | /// | ||
1911 | /// ``` | ||
1912 | /// foo::<T, U>❰ (42, true) ❱; | ||
1913 | /// ``` | ||
1914 | /// | ||
1915 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
1916 | struct ArgList { | ||
1917 | T!['('], | ||
1918 | args: [Expr], | ||
1919 | T![')'] | ||
1920 | } | ||
1921 | |||
1922 | /// Path to a symbol. Includes single identifier names and elaborate paths with | ||
1923 | /// generic parameters. | ||
1924 | /// | ||
1925 | /// ``` | ||
1926 | /// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱(); | ||
1927 | /// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024); | ||
1928 | /// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱(); | ||
1929 | /// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱(); | ||
1930 | /// ``` | ||
1931 | /// | ||
1932 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
1933 | struct Path { | ||
1934 | segment: PathSegment, | ||
1935 | T![::], | ||
1936 | qualifier: Path, | ||
1937 | } | ||
1938 | |||
1939 | /// Segment of the path to a symbol. | ||
1940 | /// Only path segment of an absolute path holds the `::` token, | ||
1941 | /// all other `::` tokens that connect path segments reside under `Path` itself.` | ||
1942 | /// | ||
1943 | /// ``` | ||
1944 | /// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱(); | ||
1945 | /// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024); | ||
1946 | /// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱(); | ||
1947 | /// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱(); | ||
1948 | /// | ||
1949 | /// // Note that only in this case `::` token is inlcuded: | ||
1950 | /// ❰ ::foo ❱; | ||
1951 | /// ``` | ||
1952 | /// | ||
1953 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
1954 | struct PathSegment { | ||
1955 | T![::], T![crate], T![self], T![super], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>] | ||
1956 | } | ||
1957 | |||
1958 | /// List of type arguments that are passed at generic instantiation site. | ||
1959 | /// | ||
1960 | /// ``` | ||
1961 | /// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar; | ||
1962 | /// | ||
1963 | /// Vec❰ ::<bool> ❱::(); | ||
1964 | /// ``` | ||
1965 | /// | ||
1966 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
1967 | struct TypeArgList { | ||
1968 | T![::], | ||
1969 | T![<], | ||
1970 | generic_args: [GenericArg], | ||
1971 | type_args: [TypeArg], | ||
1972 | lifetime_args: [LifetimeArg], | ||
1973 | assoc_type_args: [AssocTypeArg], | ||
1974 | const_args: [ConstArg], | ||
1975 | T![>] | ||
1976 | } | ||
1977 | |||
1978 | /// Type argument that is passed at generic instantiation site. | ||
1979 | /// | ||
1980 | /// ``` | ||
1981 | /// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz; | ||
1982 | /// ``` | ||
1983 | /// | ||
1984 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
1985 | struct TypeArg { TypeRef } | ||
1986 | |||
1987 | /// Associated type argument that is passed at generic instantiation site. | ||
1988 | /// ``` | ||
1989 | /// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh; | ||
1990 | /// | ||
1991 | /// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {} | ||
1992 | /// ``` | ||
1993 | /// | ||
1994 | struct AssocTypeArg : TypeBoundsOwner { NameRef, T![=], TypeRef } | ||
1995 | |||
1996 | /// Lifetime argument that is passed at generic instantiation site. | ||
1997 | /// | ||
1998 | /// ``` | ||
1999 | /// fn foo<'a>(s: &'a str) { | ||
2000 | /// bar::<❰ 'a ❱>(s); | ||
2001 | /// } | ||
2002 | /// ``` | ||
2003 | /// | ||
2004 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
2005 | struct LifetimeArg { T![lifetime] } | ||
2006 | |||
2007 | /// Constant value argument that is passed at generic instantiation site. | ||
2008 | /// | ||
2009 | /// ``` | ||
2010 | /// foo::<u32, ❰ { true } ❱>(); | ||
2011 | /// | ||
2012 | /// bar::<❰ { 2 + 2} ❱>(); | ||
2013 | /// ``` | ||
2014 | /// | ||
2015 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
2016 | struct ConstArg { Literal, BlockExpr } | ||
2017 | |||
2018 | |||
2019 | /// FIXME: (@edwin0cheng) Remove it to use ItemList instead | ||
2020 | /// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243 | ||
2021 | /// | ||
2022 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
2023 | struct MacroItems: ModuleItemOwner { } | ||
2024 | |||
2025 | /// FIXME: (@edwin0cheng) add some documentation here. As per the writing | ||
2026 | /// of this comment this ast node is not used. | ||
2027 | /// | ||
2028 | /// ``` | ||
2029 | /// // FIXME: example here | ||
2030 | /// ``` | ||
2031 | /// | ||
2032 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
2033 | struct MacroStmts { | ||
2034 | statements: [Stmt], | ||
2035 | Expr, | ||
2036 | } | ||
2037 | |||
2038 | /// List of items in an extern block. | ||
2039 | /// | ||
2040 | /// ``` | ||
2041 | /// extern "C" ❰ | ||
2042 | /// { | ||
2043 | /// fn foo(); | ||
2044 | /// static var: u32; | ||
2045 | /// } | ||
2046 | /// ❱ | ||
2047 | /// ``` | ||
2048 | /// | ||
2049 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
2050 | struct ExternItemList: ModuleItemOwner { | ||
2051 | T!['{'], | ||
2052 | extern_items: [ExternItem], | ||
2053 | T!['}'] | ||
2054 | } | ||
2055 | |||
2056 | /// Extern block. | ||
2057 | /// | ||
2058 | /// ``` | ||
2059 | /// ❰ | ||
2060 | /// extern "C" { | ||
2061 | /// fn foo(); | ||
2062 | /// } | ||
2063 | /// ❱ | ||
2064 | /// | ||
2065 | /// ``` | ||
2066 | /// | ||
2067 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
2068 | struct ExternBlock { | ||
2069 | Abi, | ||
2070 | ExternItemList | ||
2071 | } | ||
2072 | |||
2073 | /// Meta item in an attribute. | ||
2074 | /// | ||
2075 | /// ``` | ||
2076 | /// #[❰ bar::baz = "42" ❱] | ||
2077 | /// #[❰ bruh(bruuh("true")) ❱] | ||
2078 | /// struct Foo; | ||
2079 | /// ``` | ||
2080 | /// | ||
2081 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax) | ||
2082 | struct MetaItem { | ||
2083 | Path, T![=], AttrInput, nested_meta_items: [MetaItem] | ||
2084 | } | ||
2085 | |||
2086 | /// Macro 2.0 definition. | ||
2087 | /// Their syntax is still WIP by rustc team... | ||
2088 | /// ``` | ||
2089 | /// ❰ | ||
2090 | /// macro foo { } | ||
2091 | /// ❱ | ||
2092 | /// ``` | ||
2093 | /// | ||
2094 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md) | ||
2095 | struct MacroDef { | ||
2096 | Name, TokenTree | ||
2097 | } | ||
2098 | }, | ||
2099 | enums: ast_enums! { | ||
2100 | /// Any kind of nominal type definition. | ||
2101 | enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner { | ||
2102 | StructDef, EnumDef, UnionDef, | ||
2103 | } | ||
2104 | |||
2105 | /// Any kind of **declared** generic parameter | ||
2106 | enum GenericParam { | ||
2107 | LifetimeParam, | ||
2108 | TypeParam, | ||
2109 | ConstParam | ||
2110 | } | ||
2111 | |||
2112 | /// Any kind of generic argument passed at instantiation site | ||
2113 | enum GenericArg { | ||
2114 | LifetimeArg, | ||
2115 | TypeArg, | ||
2116 | ConstArg, | ||
2117 | AssocTypeArg | ||
2118 | } | ||
2119 | |||
2120 | /// Any kind of construct valid in type context | ||
2121 | enum TypeRef { | ||
2122 | ParenType, | ||
2123 | TupleType, | ||
2124 | NeverType, | ||
2125 | PathType, | ||
2126 | PointerType, | ||
2127 | ArrayType, | ||
2128 | SliceType, | ||
2129 | ReferenceType, | ||
2130 | PlaceholderType, | ||
2131 | FnPointerType, | ||
2132 | ForType, | ||
2133 | ImplTraitType, | ||
2134 | DynTraitType, | ||
2135 | } | ||
2136 | |||
2137 | /// Any kind of top-level item that may appear in a module | ||
2138 | enum ModuleItem: NameOwner, AttrsOwner, VisibilityOwner { | ||
2139 | StructDef, | ||
2140 | UnionDef, | ||
2141 | EnumDef, | ||
2142 | FnDef, | ||
2143 | TraitDef, | ||
2144 | TypeAliasDef, | ||
2145 | ImplDef, | ||
2146 | UseItem, | ||
2147 | ExternCrateItem, | ||
2148 | ConstDef, | ||
2149 | StaticDef, | ||
2150 | Module, | ||
2151 | MacroCall, | ||
2152 | ExternBlock | ||
2153 | } | ||
2154 | |||
2155 | |||
2156 | |||
2157 | /// Any kind of item that may appear in an impl block | ||
2158 | /// | ||
2159 | /// // FIXME: impl blocks can also contain MacroCall | ||
2160 | enum AssocItem: NameOwner, AttrsOwner { | ||
2161 | FnDef, TypeAliasDef, ConstDef | ||
2162 | } | ||
2163 | |||
2164 | /// Any kind of item that may appear in an extern block | ||
2165 | /// | ||
2166 | /// // FIXME: extern blocks can also contain MacroCall | ||
2167 | enum ExternItem: NameOwner, AttrsOwner, VisibilityOwner { | ||
2168 | FnDef, StaticDef | ||
2169 | } | ||
2170 | |||
2171 | /// Any kind of expression | ||
2172 | enum Expr: AttrsOwner { | ||
2173 | TupleExpr, | ||
2174 | ArrayExpr, | ||
2175 | ParenExpr, | ||
2176 | PathExpr, | ||
2177 | LambdaExpr, | ||
2178 | IfExpr, | ||
2179 | LoopExpr, | ||
2180 | ForExpr, | ||
2181 | WhileExpr, | ||
2182 | ContinueExpr, | ||
2183 | BreakExpr, | ||
2184 | Label, | ||
2185 | BlockExpr, | ||
2186 | ReturnExpr, | ||
2187 | MatchExpr, | ||
2188 | RecordLit, | ||
2189 | CallExpr, | ||
2190 | IndexExpr, | ||
2191 | MethodCallExpr, | ||
2192 | FieldExpr, | ||
2193 | AwaitExpr, | ||
2194 | TryExpr, | ||
2195 | EffectExpr, | ||
2196 | CastExpr, | ||
2197 | RefExpr, | ||
2198 | PrefixExpr, | ||
2199 | RangeExpr, | ||
2200 | BinExpr, | ||
2201 | Literal, | ||
2202 | MacroCall, | ||
2203 | BoxExpr, | ||
2204 | } | ||
2205 | |||
2206 | /// Any kind of pattern | ||
2207 | enum Pat { | ||
2208 | OrPat, | ||
2209 | ParenPat, | ||
2210 | RefPat, | ||
2211 | BoxPat, | ||
2212 | BindPat, | ||
2213 | PlaceholderPat, | ||
2214 | DotDotPat, | ||
2215 | PathPat, | ||
2216 | RecordPat, | ||
2217 | TupleStructPat, | ||
2218 | TuplePat, | ||
2219 | SlicePat, | ||
2220 | RangePat, | ||
2221 | LiteralPat, | ||
2222 | MacroPat, | ||
2223 | } | ||
2224 | |||
2225 | /// Any kind of pattern that appears directly inside of the curly | ||
2226 | /// braces of a record pattern | ||
2227 | enum RecordInnerPat { | ||
2228 | RecordFieldPat, | ||
2229 | BindPat | ||
2230 | } | ||
2231 | |||
2232 | /// Any kind of input to an attribute | ||
2233 | enum AttrInput { Literal, TokenTree } | ||
2234 | |||
2235 | /// Any kind of statement | ||
2236 | /// Note: there are no empty statements, these are just represented as | ||
2237 | /// bare semicolons without a dedicated statement ast node. | ||
2238 | enum Stmt { | ||
2239 | LetStmt, | ||
2240 | ExprStmt, | ||
2241 | // macro calls are parsed as expression statements | ||
2242 | } | ||
2243 | |||
2244 | /// Any kind of fields list (record or tuple field lists) | ||
2245 | enum FieldDefList { | ||
2246 | RecordFieldDefList, | ||
2247 | TupleFieldDefList, | ||
2248 | } | ||
2249 | }, | ||
2250 | } | ||
2251 | } | ||
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 5a18b3e2b..24e8be1fb 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -3,19 +3,27 @@ | |||
3 | //! Specifically, it generates the `SyntaxKind` enum and a number of newtype | 3 | //! Specifically, it generates the `SyntaxKind` enum and a number of newtype |
4 | //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. | 4 | //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. |
5 | 5 | ||
6 | use std::{collections::HashSet, fmt::Write}; | 6 | use std::{ |
7 | collections::{BTreeSet, HashSet}, | ||
8 | fmt::Write, | ||
9 | }; | ||
7 | 10 | ||
8 | use proc_macro2::{Punct, Spacing}; | 11 | use proc_macro2::{Punct, Spacing}; |
9 | use quote::{format_ident, quote}; | 12 | use quote::{format_ident, quote}; |
13 | use ungrammar::{Grammar, Rule}; | ||
10 | 14 | ||
11 | use crate::{ | 15 | use crate::{ |
12 | ast_src::{rust_ast, AstSrc, Field, FieldSrc, KindsSrc, KINDS_SRC}, | 16 | ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Field, FieldSrc, KindsSrc, KINDS_SRC}, |
13 | codegen::{self, update, Mode}, | 17 | codegen::{self, update, Mode}, |
14 | project_root, Result, | 18 | project_root, Result, |
15 | }; | 19 | }; |
16 | 20 | ||
17 | pub fn generate_syntax(mode: Mode) -> Result<()> { | 21 | pub fn generate_syntax(mode: Mode) -> Result<()> { |
18 | let ast = rust_ast(); | 22 | let grammar = include_str!("rust.ungram") |
23 | .parse::<Grammar>() | ||
24 | .unwrap_or_else(|err| panic!("\n \x1b[91merror\x1b[0m: {}\n", err)); | ||
25 | let ast = lower(&grammar); | ||
26 | |||
19 | let syntax_kinds_file = project_root().join(codegen::SYNTAX_KINDS); | 27 | let syntax_kinds_file = project_root().join(codegen::SYNTAX_KINDS); |
20 | let syntax_kinds = generate_syntax_kinds(KINDS_SRC)?; | 28 | let syntax_kinds = generate_syntax_kinds(KINDS_SRC)?; |
21 | update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?; | 29 | update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?; |
@@ -215,7 +223,9 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> { | |||
215 | .map(|kind| to_pascal_case(kind)) | 223 | .map(|kind| to_pascal_case(kind)) |
216 | .filter(|name| !defined_nodes.iter().any(|&it| it == name)) | 224 | .filter(|name| !defined_nodes.iter().any(|&it| it == name)) |
217 | { | 225 | { |
218 | eprintln!("Warning: node {} not defined in ast source", node); | 226 | drop(node) |
227 | // TODO: restore this | ||
228 | // eprintln!("Warning: node {} not defined in ast source", node); | ||
219 | } | 229 | } |
220 | 230 | ||
221 | let ast = quote! { | 231 | let ast = quote! { |
@@ -414,6 +424,10 @@ fn to_pascal_case(s: &str) -> String { | |||
414 | buf | 424 | buf |
415 | } | 425 | } |
416 | 426 | ||
427 | fn pluralize(s: &str) -> String { | ||
428 | format!("{}s", s) | ||
429 | } | ||
430 | |||
417 | impl Field { | 431 | impl Field { |
418 | fn is_many(&self) -> bool { | 432 | fn is_many(&self) -> bool { |
419 | matches!(self, Field::Node { src: FieldSrc::Many(_), .. }) | 433 | matches!(self, Field::Node { src: FieldSrc::Many(_), .. }) |
@@ -449,6 +463,7 @@ impl Field { | |||
449 | "." => "dot", | 463 | "." => "dot", |
450 | ".." => "dotdot", | 464 | ".." => "dotdot", |
451 | "..." => "dotdotdot", | 465 | "..." => "dotdotdot", |
466 | "..=" => "dotdoteq", | ||
452 | "=>" => "fat_arrow", | 467 | "=>" => "fat_arrow", |
453 | "@" => "at", | 468 | "@" => "at", |
454 | ":" => "colon", | 469 | ":" => "colon", |
@@ -475,3 +490,204 @@ impl Field { | |||
475 | } | 490 | } |
476 | } | 491 | } |
477 | } | 492 | } |
493 | |||
494 | fn lower(grammar: &Grammar) -> AstSrc { | ||
495 | let mut res = AstSrc::default(); | ||
496 | res.tokens = vec!["Whitespace".into(), "Comment".into(), "String".into(), "RawString".into()]; | ||
497 | |||
498 | let nodes = grammar | ||
499 | .iter() | ||
500 | .filter(|&node| match grammar[node].rule { | ||
501 | Rule::Node(it) if it == node => false, | ||
502 | _ => true, | ||
503 | }) | ||
504 | .collect::<Vec<_>>(); | ||
505 | |||
506 | for &node in &nodes { | ||
507 | let name = grammar[node].name.clone(); | ||
508 | let rule = &grammar[node].rule; | ||
509 | match lower_enum(grammar, rule) { | ||
510 | Some(variants) => { | ||
511 | let enum_src = AstEnumSrc { doc: Vec::new(), name, traits: Vec::new(), variants }; | ||
512 | res.enums.push(enum_src); | ||
513 | } | ||
514 | None => { | ||
515 | let mut fields = Vec::new(); | ||
516 | lower_rule(&mut fields, grammar, rule); | ||
517 | res.nodes.push(AstNodeSrc { doc: Vec::new(), name, traits: Vec::new(), fields }); | ||
518 | } | ||
519 | } | ||
520 | } | ||
521 | |||
522 | deduplicate_fields(&mut res); | ||
523 | extract_enums(&mut res); | ||
524 | extract_struct_traits(&mut res); | ||
525 | extract_enum_traits(&mut res); | ||
526 | res | ||
527 | } | ||
528 | |||
529 | fn lower_enum(grammar: &Grammar, rule: &Rule) -> Option<Vec<String>> { | ||
530 | let alternatives = match rule { | ||
531 | Rule::Alt(it) => it, | ||
532 | _ => return None, | ||
533 | }; | ||
534 | let mut variants = Vec::new(); | ||
535 | for alternative in alternatives { | ||
536 | match alternative { | ||
537 | Rule::Node(it) => variants.push(grammar[*it].name.clone()), | ||
538 | _ => return None, | ||
539 | } | ||
540 | } | ||
541 | Some(variants) | ||
542 | } | ||
543 | |||
544 | fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) { | ||
545 | match rule { | ||
546 | Rule::Node(node) => { | ||
547 | let field = Field::Node { name: grammar[*node].name.clone(), src: FieldSrc::Shorthand }; | ||
548 | acc.push(field); | ||
549 | } | ||
550 | Rule::Token(token) => { | ||
551 | let mut name = grammar[*token].name.clone(); | ||
552 | if name != "int_number" && name != "string" { | ||
553 | if "[]{}()".contains(&name) { | ||
554 | name = format!("'{}'", name); | ||
555 | } | ||
556 | let field = Field::Token(name); | ||
557 | acc.push(field); | ||
558 | } | ||
559 | } | ||
560 | Rule::Rep(inner) => { | ||
561 | if let Rule::Node(node) = &**inner { | ||
562 | let name = grammar[*node].name.clone(); | ||
563 | let label = pluralize(&to_lower_snake_case(&name)); | ||
564 | let field = Field::Node { name: label.clone(), src: FieldSrc::Many(name) }; | ||
565 | acc.push(field); | ||
566 | return; | ||
567 | } | ||
568 | todo!("{:?}", rule) | ||
569 | } | ||
570 | Rule::Labeled { label, rule } => { | ||
571 | let node = match &**rule { | ||
572 | Rule::Rep(inner) | Rule::Opt(inner) => match &**inner { | ||
573 | Rule::Node(node) => node, | ||
574 | _ => todo!("{:?}", rule), | ||
575 | }, | ||
576 | Rule::Node(node) => node, | ||
577 | _ => todo!("{:?}", rule), | ||
578 | }; | ||
579 | let field = Field::Node { | ||
580 | name: label.clone(), | ||
581 | src: match &**rule { | ||
582 | Rule::Rep(_) => FieldSrc::Many(grammar[*node].name.clone()), | ||
583 | _ => FieldSrc::Optional(grammar[*node].name.clone()), | ||
584 | }, | ||
585 | }; | ||
586 | acc.push(field); | ||
587 | } | ||
588 | Rule::Seq(rules) | Rule::Alt(rules) => { | ||
589 | for rule in rules { | ||
590 | lower_rule(acc, grammar, rule) | ||
591 | } | ||
592 | } | ||
593 | Rule::Opt(rule) => lower_rule(acc, grammar, rule), | ||
594 | } | ||
595 | } | ||
596 | |||
597 | fn deduplicate_fields(ast: &mut AstSrc) { | ||
598 | eprintln!(); | ||
599 | for node in &mut ast.nodes { | ||
600 | let mut i = 0; | ||
601 | 'outer: while i < node.fields.len() { | ||
602 | for j in 0..i { | ||
603 | let f1 = &node.fields[i]; | ||
604 | let f2 = &node.fields[j]; | ||
605 | if f1 == f2 { | ||
606 | node.fields.remove(i); | ||
607 | continue 'outer; | ||
608 | } | ||
609 | } | ||
610 | i += 1; | ||
611 | } | ||
612 | } | ||
613 | } | ||
614 | |||
615 | fn extract_enums(ast: &mut AstSrc) { | ||
616 | for node in &mut ast.nodes { | ||
617 | for enm in &ast.enums { | ||
618 | let mut to_remove = Vec::new(); | ||
619 | for (i, field) in node.fields.iter().enumerate() { | ||
620 | let ty = field.ty().to_string(); | ||
621 | if enm.variants.iter().any(|it| it == &ty) { | ||
622 | to_remove.push(i); | ||
623 | } | ||
624 | } | ||
625 | if to_remove.len() == enm.variants.len() { | ||
626 | node.remove_field(to_remove); | ||
627 | node.fields.push(Field::Node { name: enm.name.clone(), src: FieldSrc::Shorthand }); | ||
628 | } | ||
629 | } | ||
630 | } | ||
631 | } | ||
632 | |||
633 | fn extract_struct_traits(ast: &mut AstSrc) { | ||
634 | let traits: &[(&str, &[&str])] = &[ | ||
635 | ("AttrsOwner", &["attrs"]), | ||
636 | ("NameOwner", &["name"]), | ||
637 | ("VisibilityOwner", &["visibility"]), | ||
638 | ("TypeParamsOwner", &["type_param_list", "where_clause"]), | ||
639 | ("TypeBoundsOwner", &["type_bound_list", "colon_token"]), | ||
640 | ("ModuleItemOwner", &["items"]), | ||
641 | ("TypeAscriptionOwner", &["ascribed_type"]), | ||
642 | ("LoopBodyOwner", &["label", "loop_body"]), | ||
643 | ("ArgListOwner", &["arg_list"]), | ||
644 | ]; | ||
645 | |||
646 | for node in &mut ast.nodes { | ||
647 | for (name, methods) in traits { | ||
648 | extract_struct_trait(node, name, methods); | ||
649 | } | ||
650 | } | ||
651 | } | ||
652 | |||
653 | fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str]) { | ||
654 | let mut to_remove = Vec::new(); | ||
655 | for (i, field) in node.fields.iter().enumerate() { | ||
656 | let method_name = field.method_name().to_string(); | ||
657 | if methods.iter().any(|&it| it == &method_name) { | ||
658 | to_remove.push(i); | ||
659 | } | ||
660 | } | ||
661 | if to_remove.len() == methods.len() { | ||
662 | node.traits.push(trait_name.to_string()); | ||
663 | node.remove_field(to_remove); | ||
664 | } | ||
665 | } | ||
666 | |||
667 | fn extract_enum_traits(ast: &mut AstSrc) { | ||
668 | for enm in &mut ast.enums { | ||
669 | let nodes = &ast.nodes; | ||
670 | let mut variant_traits = enm | ||
671 | .variants | ||
672 | .iter() | ||
673 | .map(|var| nodes.iter().find(|it| &it.name == var).unwrap()) | ||
674 | .map(|node| node.traits.iter().cloned().collect::<BTreeSet<_>>()); | ||
675 | |||
676 | let mut enum_traits = match variant_traits.next() { | ||
677 | Some(it) => it, | ||
678 | None => continue, | ||
679 | }; | ||
680 | for traits in variant_traits { | ||
681 | enum_traits = enum_traits.intersection(&traits).cloned().collect(); | ||
682 | } | ||
683 | enm.traits = enum_traits.into_iter().collect(); | ||
684 | } | ||
685 | } | ||
686 | |||
687 | impl AstNodeSrc { | ||
688 | fn remove_field(&mut self, to_remove: Vec<usize>) { | ||
689 | to_remove.into_iter().rev().for_each(|idx| { | ||
690 | self.fields.remove(idx); | ||
691 | }); | ||
692 | } | ||
693 | } | ||
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram new file mode 100644 index 000000000..b6ec5d5e7 --- /dev/null +++ b/xtask/src/codegen/rust.ungram | |||
@@ -0,0 +1,529 @@ | |||
1 | SourceFile = | ||
2 | Attr* | ||
3 | items:ModuleItem* | ||
4 | |||
5 | FnDef = | ||
6 | Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList? | ||
7 | ParamList RetType? | ||
8 | WhereClause? | ||
9 | (body:BlockExpr | ';') | ||
10 | |||
11 | RetType = | ||
12 | '->' TypeRef | ||
13 | |||
14 | StructDef = | ||
15 | Attr* Visibility? 'struct' Name TypeParamList? ( | ||
16 | WhereClause? (RecordFieldDefList | ';') | ||
17 | | TupleFieldDefList WhereClause? ';' | ||
18 | ) | ||
19 | |||
20 | UnionDef = | ||
21 | Attr* Visibility? 'union' Name TypeParamList? WhereClause? | ||
22 | RecordFieldDefList | ||
23 | |||
24 | RecordFieldDefList = | ||
25 | '{' fields:RecordFieldDef* '}' | ||
26 | |||
27 | RecordFieldDef = | ||
28 | Attr* Visibility? Name ':' ascribed_type:TypeRef | ||
29 | |||
30 | TupleFieldDefList = | ||
31 | '(' fields:TupleFieldDef* ')' | ||
32 | |||
33 | TupleFieldDef = | ||
34 | Attr* Visibility? Name TypeRef | ||
35 | |||
36 | FieldDefList = | ||
37 | RecordFieldDefList | ||
38 | | TupleFieldDefList | ||
39 | |||
40 | EnumDef = | ||
41 | Attr* Visibility? 'enum' Name TypeParamList? WhereClause? | ||
42 | variant_list:EnumVariantList | ||
43 | |||
44 | EnumVariantList = | ||
45 | '{' variants:EnumVariant* '}' | ||
46 | |||
47 | EnumVariant = | ||
48 | Attr* Visibility? Name FieldDefList ('=' Expr)? | ||
49 | |||
50 | TraitDef = | ||
51 | Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name TypeParamList | ||
52 | (':' TypeBoundList?)? WhereClause | ||
53 | ItemList | ||
54 | |||
55 | Module = | ||
56 | Attr* Visibility? 'mod' Name | ||
57 | (ItemList | ';') | ||
58 | |||
59 | ItemList = | ||
60 | '{' | ||
61 | AssocItem* | ||
62 | items:ModuleItem* | ||
63 | '}' | ||
64 | |||
65 | ConstDef = | ||
66 | Attr* Visibility? 'default'? 'const' Name ':' ascribed_type:TypeRef | ||
67 | '=' body:Expr ';' | ||
68 | |||
69 | StaticDef = | ||
70 | Attr* Visibility? 'static'? 'mut'? 'static' Name ':' ascribed_type:TypeRef | ||
71 | '=' body:Expr ';' | ||
72 | |||
73 | TypeAliasDef = | ||
74 | Attr* Visibility? 'default'? 'type' Name TypeParamList? WhereClause? (':' TypeBoundList?)? | ||
75 | '=' TypeRef ';' | ||
76 | |||
77 | ImplDef = | ||
78 | Attr* Visibility? 'const'? 'default'? 'unsafe'? 'impl' TypeParamList? '!'? 'for' | ||
79 | WhereClause? | ||
80 | ItemList | ||
81 | |||
82 | ParenType = | ||
83 | '(' TypeRef ')' | ||
84 | |||
85 | TupleType = | ||
86 | '(' fields:TypeRef* ')' | ||
87 | |||
88 | NeverType = | ||
89 | '!' | ||
90 | |||
91 | PathType = | ||
92 | Path | ||
93 | |||
94 | PointerType = | ||
95 | '*' ('const' | 'mut') TypeRef | ||
96 | |||
97 | ArrayType = | ||
98 | '[' TypeRef ';' Expr ']' | ||
99 | |||
100 | SliceType = | ||
101 | '[' TypeRef ']' | ||
102 | |||
103 | ReferenceType = | ||
104 | '&' 'lifetime'? 'mut'? TypeRef | ||
105 | |||
106 | PlaceholderType = | ||
107 | '_' | ||
108 | |||
109 | FnPointerType = | ||
110 | Abi 'unsafe'? 'fn' ParamList RetType? | ||
111 | |||
112 | ForType = | ||
113 | 'for' TypeParamList TypeRef | ||
114 | |||
115 | ImplTraitType = | ||
116 | 'impl' TypeBoundList | ||
117 | |||
118 | DynTraitType = | ||
119 | 'dyn' TypeBoundList | ||
120 | |||
121 | TupleExpr = | ||
122 | Attr* '(' Expr* ')' | ||
123 | |||
124 | ArrayExpr = | ||
125 | Attr* '[' (Expr* | Expr ';' Expr) ']' | ||
126 | |||
127 | ParenExpr = | ||
128 | Attr* '(' Expr ')' | ||
129 | |||
130 | PathExpr = | ||
131 | Path | ||
132 | |||
133 | LambdaExpr = | ||
134 | Attr* 'static'? 'async'? 'move'? ParamList RetType? | ||
135 | body:Expr | ||
136 | |||
137 | IfExpr = | ||
138 | Attr* 'if' Condition | ||
139 | |||
140 | Condition = | ||
141 | 'let' Pat '=' Expr | ||
142 | | Expr | ||
143 | |||
144 | EffectExpr = | ||
145 | Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr | ||
146 | |||
147 | LoopExpr = | ||
148 | Attr* Label? 'loop' | ||
149 | loop_body:BlockExpr? | ||
150 | |||
151 | ForExpr = | ||
152 | Attr* Label? 'for' Pat 'in' iterable:Expr | ||
153 | loop_body:BlockExpr? | ||
154 | |||
155 | WhileExpr = | ||
156 | Attr* Label? 'while' Condition | ||
157 | loop_body:BlockExpr? | ||
158 | |||
159 | ContinueExpr = | ||
160 | Attr* 'continue' 'lifetime'? | ||
161 | |||
162 | BreakExpr = | ||
163 | Attr* 'break' 'lifetime'? Expr? | ||
164 | |||
165 | Label = | ||
166 | 'lifetime' | ||
167 | |||
168 | BlockExpr = | ||
169 | Attr* Label | ||
170 | '{' | ||
171 | items:ModuleItem* | ||
172 | statements:Stmt* | ||
173 | Expr? | ||
174 | '}' | ||
175 | |||
176 | ReturnExpr = | ||
177 | Attr* 'return' Expr | ||
178 | |||
179 | CallExpr = | ||
180 | Attr* Expr ArgList | ||
181 | |||
182 | MethodCallExpr = | ||
183 | Attr* Expr '.' NameRef TypeArgList? ArgList | ||
184 | |||
185 | ArgList = | ||
186 | '(' args:Expr* ')' | ||
187 | |||
188 | FieldExpr = | ||
189 | Attr* Expr '.' NameRef | ||
190 | |||
191 | IndexExpr = | ||
192 | Attr* '[' ']' | ||
193 | |||
194 | AwaitExpr = | ||
195 | Attr* Expr '.' 'await' | ||
196 | |||
197 | TryExpr = | ||
198 | Attr* Expr '?' | ||
199 | |||
200 | CastExpr = | ||
201 | Attr* Expr 'as' TypeRef | ||
202 | |||
203 | RefExpr = | ||
204 | Attr* '&' ('raw' | 'mut' | 'const') Expr | ||
205 | |||
206 | PrefixExpr = | ||
207 | Attr* Expr | ||
208 | |||
209 | BoxExpr = | ||
210 | Attr* 'box' Expr | ||
211 | |||
212 | RangeExpr = | ||
213 | Attr* | ||
214 | |||
215 | BinExpr = | ||
216 | Attr* | ||
217 | |||
218 | Literal = | ||
219 | 'int_number' | ||
220 | |||
221 | MatchExpr = | ||
222 | Attr* 'match' Expr MatchArmList | ||
223 | |||
224 | MatchArmList = | ||
225 | '{' arms:MatchArm* '}' | ||
226 | |||
227 | MatchArm = | ||
228 | Attr* Pat guard:MatchGuard? '=>' Expr | ||
229 | |||
230 | MatchGuard = | ||
231 | 'if' Expr | ||
232 | |||
233 | RecordLit = | ||
234 | Path RecordFieldList | ||
235 | |||
236 | RecordFieldList = | ||
237 | '{' | ||
238 | fields:RecordField* | ||
239 | ('..' spread:Expr)? | ||
240 | '}' | ||
241 | |||
242 | RecordField = | ||
243 | Attr* NameRef (':' Expr)? | ||
244 | |||
245 | OrPat = | ||
246 | Pat* | ||
247 | |||
248 | ParenPat = | ||
249 | '(' Pat ')' | ||
250 | |||
251 | RefPat = | ||
252 | '&' 'mut'? Pat | ||
253 | |||
254 | BoxPat = | ||
255 | 'box' Path | ||
256 | |||
257 | BindPat = | ||
258 | Attr* 'ref'? 'mut'? Name ('@' Pat)? | ||
259 | |||
260 | PlaceholderPat = | ||
261 | '_' | ||
262 | |||
263 | DotDotPat = | ||
264 | '..' | ||
265 | |||
266 | PathPat = | ||
267 | Path | ||
268 | |||
269 | SlicePat = | ||
270 | '[' args:Pat* ']' | ||
271 | |||
272 | RangePat = | ||
273 | '..' | '..=' | ||
274 | |||
275 | LiteralPat = | ||
276 | Literal | ||
277 | |||
278 | MacroPat = | ||
279 | MacroCall | ||
280 | |||
281 | RecordPat = | ||
282 | Path RecordFieldPatList | ||
283 | |||
284 | RecordFieldPatList = | ||
285 | '{' | ||
286 | record_field_pats:RecordFieldPat* | ||
287 | BindPat* | ||
288 | '..'? | ||
289 | '}' | ||
290 | |||
291 | RecordFieldPat = | ||
292 | Attr* NameRef ':' Pat | ||
293 | |||
294 | TupleStructPat = | ||
295 | Path '(' args:Pat* ')' | ||
296 | |||
297 | TuplePat = | ||
298 | '(' args:Pat* ')' | ||
299 | |||
300 | Visibility = | ||
301 | 'pub' ('(' 'super' | 'self' | 'crate' | 'in' Path ')')? | ||
302 | |||
303 | Name = | ||
304 | 'ident' | ||
305 | |||
306 | NameRef = | ||
307 | 'ident' | 'int_number' | ||
308 | |||
309 | MacroCall = | ||
310 | Attr* Path '!' Name? TokenTree ';'? | ||
311 | |||
312 | MacroDef = | ||
313 | Name TokenTree | ||
314 | |||
315 | TokenTree = | ||
316 | '(' ')' | '{' '}' | '[' ']' | ||
317 | |||
318 | MacroItems = | ||
319 | items:ModuleItem* | ||
320 | |||
321 | MacroStmts = | ||
322 | statements:Stmt* | ||
323 | Expr? | ||
324 | |||
325 | Attr = | ||
326 | '#' '!'? '[' Path ('=' input:AttrInput)? ']' | ||
327 | |||
328 | TypeParamList = | ||
329 | '<' | ||
330 | TypeParam* | ||
331 | LifetimeParam* | ||
332 | ConstParam* | ||
333 | '>' | ||
334 | |||
335 | TypeParam = | ||
336 | Attr* Name (':' TypeBoundList?)? | ||
337 | ('=' default_type:TypeRef)? | ||
338 | |||
339 | ConstParam = | ||
340 | Attr* 'const' Name ':' ascribed_type:TypeRef | ||
341 | ('=' default_val:Expr)? | ||
342 | |||
343 | LifetimeParam = | ||
344 | Attr* 'lifetime' | ||
345 | |||
346 | TypeBound = | ||
347 | 'lifetime' | 'const'? TypeRef | ||
348 | |||
349 | TypeBoundList = | ||
350 | bounds:TypeBound* | ||
351 | |||
352 | WherePred = | ||
353 | ('for' TypeParamList)? ('lifetime' | TypeRef) ':' TypeBoundList | ||
354 | |||
355 | WhereClause = | ||
356 | 'where' predicates:WherePred* | ||
357 | |||
358 | Abi = | ||
359 | 'string' | ||
360 | |||
361 | ExprStmt = | ||
362 | Attr* Expr ';' | ||
363 | |||
364 | LetStmt = | ||
365 | Attr* 'let' Pat (':' ascribed_type:TypeRef) | ||
366 | '=' initializer:Expr ';' | ||
367 | |||
368 | ParamList = | ||
369 | '(' SelfParam Param* ')' | ||
370 | |||
371 | SelfParam = | ||
372 | Attr* ('&' 'lifetime'?)? 'mut'? 'self' (':' ascribed_type:TypeRef) | ||
373 | |||
374 | Param = | ||
375 | Attr* Pat (':' ascribed_type:TypeRef) | ||
376 | | '...' | ||
377 | |||
378 | UseItem = | ||
379 | Attr* Visibility? 'use' UseTree ';' | ||
380 | |||
381 | UseTree = | ||
382 | Path ('::' ('*' | UseTreeList)) Alias? | ||
383 | |||
384 | UseTreeList = | ||
385 | '{' UseTree* '}' | ||
386 | |||
387 | Alias = | ||
388 | 'as' Name | ||
389 | |||
390 | ExternCrateItem = | ||
391 | Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Alias? ';' | ||
392 | |||
393 | Path = | ||
394 | (qualifier:Path '::')? segment:PathSegment | ||
395 | |||
396 | PathSegment = | ||
397 | '::' | 'crate' | 'self' | 'super' | ||
398 | | '<' NameRef TypeArgList ParamList RetType PathType '>' | ||
399 | |||
400 | TypeArgList = | ||
401 | '::'? '<' | ||
402 | TypeArg* | ||
403 | LifetimeArg* | ||
404 | AssocTypeArg* | ||
405 | ConstArg* | ||
406 | '>' | ||
407 | |||
408 | TypeArg = | ||
409 | TypeRef | ||
410 | |||
411 | AssocTypeArg = | ||
412 | NameRef (':' TypeBoundList | '=' TypeRef) | ||
413 | |||
414 | LifetimeArg = | ||
415 | 'lifetime' | ||
416 | |||
417 | ConstArg = | ||
418 | Literal | BlockExpr BlockExpr | ||
419 | |||
420 | ExternBlock = | ||
421 | Attr* Abi ExternItemList | ||
422 | |||
423 | ExternItemList = | ||
424 | '{' extern_items:ExternItem* '}' | ||
425 | |||
426 | MetaItem = | ||
427 | Path '=' AttrInput nested_meta_items:MetaItem* | ||
428 | |||
429 | AdtDef = | ||
430 | StructDef | ||
431 | | EnumDef | ||
432 | | UnionDef | ||
433 | |||
434 | TypeRef = | ||
435 | ParenType | ||
436 | | TupleType | ||
437 | | NeverType | ||
438 | | PathType | ||
439 | | PointerType | ||
440 | | ArrayType | ||
441 | | SliceType | ||
442 | | ReferenceType | ||
443 | | PlaceholderType | ||
444 | | FnPointerType | ||
445 | | ForType | ||
446 | | ImplTraitType | ||
447 | | DynTraitType | ||
448 | |||
449 | AssocItem = | ||
450 | FnDef | ||
451 | | TypeAliasDef | ||
452 | | ConstDef | ||
453 | |||
454 | ExternItem = | ||
455 | FnDef | StaticDef | ||
456 | |||
457 | ModuleItem = | ||
458 | StructDef | ||
459 | | UnionDef | ||
460 | | EnumDef | ||
461 | | FnDef | ||
462 | | TraitDef | ||
463 | | TypeAliasDef | ||
464 | | ImplDef | ||
465 | | UseItem | ||
466 | | ExternCrateItem | ||
467 | | ConstDef | ||
468 | | StaticDef | ||
469 | | Module | ||
470 | | MacroCall | ||
471 | | ExternBlock | ||
472 | |||
473 | AttrInput = | ||
474 | Literal | ||
475 | | TokenTree | ||
476 | |||
477 | Stmt = | ||
478 | LetStmt | ||
479 | | ExprStmt | ||
480 | |||
481 | Pat = | ||
482 | OrPat | ||
483 | | ParenPat | ||
484 | | RefPat | ||
485 | | BoxPat | ||
486 | | BindPat | ||
487 | | PlaceholderPat | ||
488 | | DotDotPat | ||
489 | | PathPat | ||
490 | | RecordPat | ||
491 | | TupleStructPat | ||
492 | | TuplePat | ||
493 | | SlicePat | ||
494 | | RangePat | ||
495 | | LiteralPat | ||
496 | | MacroPat | ||
497 | |||
498 | Expr = | ||
499 | TupleExpr | ||
500 | | ArrayExpr | ||
501 | | ParenExpr | ||
502 | | PathExpr | ||
503 | | LambdaExpr | ||
504 | | IfExpr | ||
505 | | LoopExpr | ||
506 | | ForExpr | ||
507 | | WhileExpr | ||
508 | | ContinueExpr | ||
509 | | BreakExpr | ||
510 | | Label | ||
511 | | BlockExpr | ||
512 | | ReturnExpr | ||
513 | | MatchExpr | ||
514 | | RecordLit | ||
515 | | CallExpr | ||
516 | | IndexExpr | ||
517 | | MethodCallExpr | ||
518 | | FieldExpr | ||
519 | | AwaitExpr | ||
520 | | TryExpr | ||
521 | | EffectExpr | ||
522 | | CastExpr | ||
523 | | RefExpr | ||
524 | | PrefixExpr | ||
525 | | RangeExpr | ||
526 | | BinExpr | ||
527 | | Literal | ||
528 | | MacroCall | ||
529 | | BoxExpr | ||
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index adadffc53..d65a2acbc 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs | |||
@@ -55,7 +55,6 @@ fn check_licenses() { | |||
55 | 0BSD OR MIT OR Apache-2.0 | 55 | 0BSD OR MIT OR Apache-2.0 |
56 | Apache-2.0 OR BSL-1.0 | 56 | Apache-2.0 OR BSL-1.0 |
57 | Apache-2.0 OR MIT | 57 | Apache-2.0 OR MIT |
58 | Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT | ||
59 | Apache-2.0/MIT | 58 | Apache-2.0/MIT |
60 | BSD-2-Clause | 59 | BSD-2-Clause |
61 | BSD-3-Clause | 60 | BSD-3-Clause |