diff options
61 files changed, 2504 insertions, 3762 deletions
diff --git a/Cargo.lock b/Cargo.lock index dbadfc64e..6ef51fed0 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -221,7 +221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
221 | dependencies = [ | 221 | dependencies = [ |
222 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 222 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
223 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 223 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
224 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 224 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
225 | ] | 225 | ] |
226 | 226 | ||
227 | [[package]] | 227 | [[package]] |
@@ -284,7 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
284 | dependencies = [ | 284 | dependencies = [ |
285 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 285 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
286 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 286 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
287 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 287 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
288 | "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", | 288 | "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", |
289 | ] | 289 | ] |
290 | 290 | ||
@@ -295,7 +295,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
295 | 295 | ||
296 | [[package]] | 296 | [[package]] |
297 | name = "flexi_logger" | 297 | name = "flexi_logger" |
298 | version = "0.10.3" | 298 | version = "0.10.4" |
299 | source = "registry+https://github.com/rust-lang/crates.io-index" | 299 | source = "registry+https://github.com/rust-lang/crates.io-index" |
300 | dependencies = [ | 300 | dependencies = [ |
301 | "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | 301 | "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -501,7 +501,7 @@ dependencies = [ | |||
501 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", | 501 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", |
502 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 502 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
503 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 503 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
504 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 504 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
505 | ] | 505 | ] |
506 | 506 | ||
507 | [[package]] | 507 | [[package]] |
@@ -585,7 +585,7 @@ dependencies = [ | |||
585 | "pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 585 | "pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
586 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 586 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
587 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 587 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
588 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 588 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
589 | ] | 589 | ] |
590 | 590 | ||
591 | [[package]] | 591 | [[package]] |
@@ -706,7 +706,7 @@ version = "0.1.0" | |||
706 | dependencies = [ | 706 | dependencies = [ |
707 | "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", | 707 | "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", |
708 | "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", | 708 | "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", |
709 | "flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", | 709 | "flexi_logger 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", |
710 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | 710 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |
711 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 711 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
712 | "ra_arena 0.1.0", | 712 | "ra_arena 0.1.0", |
@@ -728,7 +728,7 @@ dependencies = [ | |||
728 | "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", | 728 | "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", |
729 | "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 729 | "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", |
730 | "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 730 | "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", |
731 | "flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", | 731 | "flexi_logger 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", |
732 | "gen_lsp_server 0.1.0", | 732 | "gen_lsp_server 0.1.0", |
733 | "im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | 733 | "im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
734 | "languageserver-types 0.53.1 (registry+https://github.com/rust-lang/crates.io-index)", | 734 | "languageserver-types 0.53.1 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -764,7 +764,7 @@ dependencies = [ | |||
764 | "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", | 764 | "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", |
765 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 765 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
766 | "ra_text_edit 0.1.0", | 766 | "ra_text_edit 0.1.0", |
767 | "rowan 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", | 767 | "rowan 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
768 | "test_utils 0.1.0", | 768 | "test_utils 0.1.0", |
769 | "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 769 | "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", |
770 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 770 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -969,7 +969,7 @@ dependencies = [ | |||
969 | 969 | ||
970 | [[package]] | 970 | [[package]] |
971 | name = "rowan" | 971 | name = "rowan" |
972 | version = "0.1.4" | 972 | version = "0.2.0" |
973 | source = "registry+https://github.com/rust-lang/crates.io-index" | 973 | source = "registry+https://github.com/rust-lang/crates.io-index" |
974 | dependencies = [ | 974 | dependencies = [ |
975 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 975 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1075,7 +1075,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1075 | dependencies = [ | 1075 | dependencies = [ |
1076 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 1076 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
1077 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 1077 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
1078 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 1078 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
1079 | ] | 1079 | ] |
1080 | 1080 | ||
1081 | [[package]] | 1081 | [[package]] |
@@ -1140,7 +1140,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1140 | 1140 | ||
1141 | [[package]] | 1141 | [[package]] |
1142 | name = "syn" | 1142 | name = "syn" |
1143 | version = "0.15.23" | 1143 | version = "0.15.24" |
1144 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1144 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1145 | dependencies = [ | 1145 | dependencies = [ |
1146 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 1146 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1155,7 +1155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1155 | dependencies = [ | 1155 | dependencies = [ |
1156 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 1156 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
1157 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 1157 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
1158 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 1158 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
1159 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1159 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1160 | ] | 1160 | ] |
1161 | 1161 | ||
@@ -1510,7 +1510,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1510 | "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" | 1510 | "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" |
1511 | "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" | 1511 | "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" |
1512 | "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" | 1512 | "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" |
1513 | "checksum flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4dda06444ccc8b0a6da19d939989b4a4e83f328710ada449eedaed48c8b903cd" | 1513 | "checksum flexi_logger 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7d3681306880a7ce87740ceb3d1ce98ca92ae636ff30a629494488cbbcf85ff8" |
1514 | "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" | 1514 | "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" |
1515 | "checksum fst 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "db72126ca7dff566cdbbdd54af44668c544897d9d3862b198141f176f1238bdf" | 1515 | "checksum fst 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "db72126ca7dff566cdbbdd54af44668c544897d9d3862b198141f176f1238bdf" |
1516 | "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" | 1516 | "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" |
@@ -1571,7 +1571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1571 | "checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c" | 1571 | "checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c" |
1572 | "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" | 1572 | "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" |
1573 | "checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f" | 1573 | "checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f" |
1574 | "checksum rowan 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c218b4430ab922850b71b14fa9bca224425097f935f6155c0b6a4b1f398a54f0" | 1574 | "checksum rowan 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9ae7dba5e703f423ceb8646d636c73e6d858a2f8c834808b4565e42ccda9e2" |
1575 | "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" | 1575 | "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" |
1576 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" | 1576 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" |
1577 | "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" | 1577 | "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" |
@@ -1593,7 +1593,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1593 | "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" | 1593 | "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" |
1594 | "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" | 1594 | "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" |
1595 | "checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" | 1595 | "checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" |
1596 | "checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc" | 1596 | "checksum syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)" = "734ecc29cd36e8123850d9bf21dfd62ef8300aaa8f879aabaa899721808be37c" |
1597 | "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" | 1597 | "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" |
1598 | "checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2" | 1598 | "checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2" |
1599 | "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" | 1599 | "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" |
diff --git a/crates/ra_analysis/src/completion/complete_fn_param.rs b/crates/ra_analysis/src/completion/complete_fn_param.rs index bb5fdfda0..c1739e47e 100644 --- a/crates/ra_analysis/src/completion/complete_fn_param.rs +++ b/crates/ra_analysis/src/completion/complete_fn_param.rs | |||
@@ -39,9 +39,9 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
39 | .add_to(acc) | 39 | .add_to(acc) |
40 | }); | 40 | }); |
41 | 41 | ||
42 | fn process<'a, N: ast::FnDefOwner<'a>>( | 42 | fn process<'a, N: ast::FnDefOwner>( |
43 | node: N, | 43 | node: &'a N, |
44 | params: &mut FxHashMap<String, (u32, ast::Param<'a>)>, | 44 | params: &mut FxHashMap<String, (u32, &'a ast::Param)>, |
45 | ) { | 45 | ) { |
46 | node.functions() | 46 | node.functions() |
47 | .filter_map(|it| it.param_list()) | 47 | .filter_map(|it| it.param_list()) |
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index 28194c908..d350f06ce 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs | |||
@@ -2,7 +2,7 @@ use ra_syntax::{ | |||
2 | algo::visit::{visitor, Visitor}, | 2 | algo::visit::{visitor, Visitor}, |
3 | AstNode, | 3 | AstNode, |
4 | ast::{self, LoopBodyOwner}, | 4 | ast::{self, LoopBodyOwner}, |
5 | SyntaxKind::*, SyntaxNodeRef, | 5 | SyntaxKind::*, SyntaxNode, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; | 8 | use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; |
@@ -76,7 +76,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
76 | acc.add_all(complete_return(fn_def, ctx.can_be_stmt)); | 76 | acc.add_all(complete_return(fn_def, ctx.can_be_stmt)); |
77 | } | 77 | } |
78 | 78 | ||
79 | fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool { | 79 | fn is_in_loop_body(leaf: &SyntaxNode) -> bool { |
80 | for node in leaf.ancestors() { | 80 | for node in leaf.ancestors() { |
81 | if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { | 81 | if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { |
82 | break; | 82 | break; |
@@ -95,7 +95,7 @@ fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool { | |||
95 | false | 95 | false |
96 | } | 96 | } |
97 | 97 | ||
98 | fn complete_return(fn_def: ast::FnDef, can_be_stmt: bool) -> Option<CompletionItem> { | 98 | fn complete_return(fn_def: &ast::FnDef, can_be_stmt: bool) -> Option<CompletionItem> { |
99 | let snip = match (can_be_stmt, fn_def.ret_type().is_some()) { | 99 | let snip = match (can_be_stmt, fn_def.ret_type().is_some()) { |
100 | (true, true) => "return $0;", | 100 | (true, true) => "return $0;", |
101 | (true, false) => "return;", | 101 | (true, false) => "return;", |
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs index 4584f355d..988c21c58 100644 --- a/crates/ra_analysis/src/completion/completion_context.rs +++ b/crates/ra_analysis/src/completion/completion_context.rs | |||
@@ -1,13 +1,9 @@ | |||
1 | use ra_editor::find_node_at_offset; | 1 | use ra_editor::find_node_at_offset; |
2 | use ra_text_edit::AtomTextEdit; | 2 | use ra_text_edit::AtomTextEdit; |
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::{find_leaf_at_offset, find_covering_node}, | 4 | AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, |
5 | ast, | 5 | ast, |
6 | AstNode, | 6 | algo::{find_leaf_at_offset, find_covering_node}, |
7 | SyntaxNodeRef, | ||
8 | SourceFileNode, | ||
9 | TextUnit, | ||
10 | TextRange, | ||
11 | SyntaxKind::*, | 7 | SyntaxKind::*, |
12 | }; | 8 | }; |
13 | use hir::source_binder; | 9 | use hir::source_binder; |
@@ -20,11 +16,11 @@ use crate::{db, FilePosition, Cancelable}; | |||
20 | pub(super) struct CompletionContext<'a> { | 16 | pub(super) struct CompletionContext<'a> { |
21 | pub(super) db: &'a db::RootDatabase, | 17 | pub(super) db: &'a db::RootDatabase, |
22 | pub(super) offset: TextUnit, | 18 | pub(super) offset: TextUnit, |
23 | pub(super) leaf: SyntaxNodeRef<'a>, | 19 | pub(super) leaf: &'a SyntaxNode, |
24 | pub(super) module: Option<hir::Module>, | 20 | pub(super) module: Option<hir::Module>, |
25 | pub(super) function: Option<hir::Function>, | 21 | pub(super) function: Option<hir::Function>, |
26 | pub(super) function_syntax: Option<ast::FnDef<'a>>, | 22 | pub(super) function_syntax: Option<&'a ast::FnDef>, |
27 | pub(super) use_item_syntax: Option<ast::UseItem<'a>>, | 23 | pub(super) use_item_syntax: Option<&'a ast::UseItem>, |
28 | pub(super) is_param: bool, | 24 | pub(super) is_param: bool, |
29 | /// A single-indent path, like `foo`. | 25 | /// A single-indent path, like `foo`. |
30 | pub(super) is_trivial_path: bool, | 26 | pub(super) is_trivial_path: bool, |
@@ -36,7 +32,7 @@ pub(super) struct CompletionContext<'a> { | |||
36 | /// Something is typed at the "top" level, in module or impl/trait. | 32 | /// Something is typed at the "top" level, in module or impl/trait. |
37 | pub(super) is_new_item: bool, | 33 | pub(super) is_new_item: bool, |
38 | /// The receiver if this is a field or method access, i.e. writing something.<|> | 34 | /// The receiver if this is a field or method access, i.e. writing something.<|> |
39 | pub(super) dot_receiver: Option<ast::Expr<'a>>, | 35 | pub(super) dot_receiver: Option<&'a ast::Expr>, |
40 | /// If this is a method call in particular, i.e. the () are already there. | 36 | /// If this is a method call in particular, i.e. the () are already there. |
41 | pub(super) is_method_call: bool, | 37 | pub(super) is_method_call: bool, |
42 | } | 38 | } |
@@ -44,7 +40,7 @@ pub(super) struct CompletionContext<'a> { | |||
44 | impl<'a> CompletionContext<'a> { | 40 | impl<'a> CompletionContext<'a> { |
45 | pub(super) fn new( | 41 | pub(super) fn new( |
46 | db: &'a db::RootDatabase, | 42 | db: &'a db::RootDatabase, |
47 | original_file: &'a SourceFileNode, | 43 | original_file: &'a SourceFile, |
48 | position: FilePosition, | 44 | position: FilePosition, |
49 | ) -> Cancelable<Option<CompletionContext<'a>>> { | 45 | ) -> Cancelable<Option<CompletionContext<'a>>> { |
50 | let module = source_binder::module_from_position(db, position)?; | 46 | let module = source_binder::module_from_position(db, position)?; |
@@ -71,7 +67,7 @@ impl<'a> CompletionContext<'a> { | |||
71 | Ok(Some(ctx)) | 67 | Ok(Some(ctx)) |
72 | } | 68 | } |
73 | 69 | ||
74 | fn fill(&mut self, original_file: &'a SourceFileNode, offset: TextUnit) { | 70 | fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) { |
75 | // Insert a fake ident to get a valid parse tree. We will use this file | 71 | // Insert a fake ident to get a valid parse tree. We will use this file |
76 | // to determine context, though the original_file will be used for | 72 | // to determine context, though the original_file will be used for |
77 | // actual completion. | 73 | // actual completion. |
@@ -100,7 +96,7 @@ impl<'a> CompletionContext<'a> { | |||
100 | } | 96 | } |
101 | } | 97 | } |
102 | } | 98 | } |
103 | fn classify_name_ref(&mut self, original_file: &'a SourceFileNode, name_ref: ast::NameRef) { | 99 | fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::NameRef) { |
104 | let name_range = name_ref.syntax().range(); | 100 | let name_range = name_ref.syntax().range(); |
105 | let top_node = name_ref | 101 | let top_node = name_ref |
106 | .syntax() | 102 | .syntax() |
@@ -197,15 +193,12 @@ impl<'a> CompletionContext<'a> { | |||
197 | } | 193 | } |
198 | } | 194 | } |
199 | 195 | ||
200 | fn find_node_with_range<'a, N: AstNode<'a>>( | 196 | fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<&N> { |
201 | syntax: SyntaxNodeRef<'a>, | ||
202 | range: TextRange, | ||
203 | ) -> Option<N> { | ||
204 | let node = find_covering_node(syntax, range); | 197 | let node = find_covering_node(syntax, range); |
205 | node.ancestors().find_map(N::cast) | 198 | node.ancestors().find_map(N::cast) |
206 | } | 199 | } |
207 | 200 | ||
208 | fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { | 201 | fn is_node<N: AstNode>(node: &SyntaxNode) -> bool { |
209 | match node.ancestors().filter_map(N::cast).next() { | 202 | match node.ancestors().filter_map(N::cast).next() { |
210 | None => false, | 203 | None => false, |
211 | Some(n) => n.syntax().range() == node.range(), | 204 | Some(n) => n.syntax().range() == node.range(), |
diff --git a/crates/ra_analysis/src/extend_selection.rs b/crates/ra_analysis/src/extend_selection.rs index f1b77f981..3b130f966 100644 --- a/crates/ra_analysis/src/extend_selection.rs +++ b/crates/ra_analysis/src/extend_selection.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use ra_db::SyntaxDatabase; | 1 | use ra_db::SyntaxDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | SyntaxNodeRef, AstNode, SourceFileNode, | 3 | SyntaxNode, AstNode, SourceFile, |
4 | ast, algo::find_covering_node, | 4 | ast, algo::find_covering_node, |
5 | }; | 5 | }; |
6 | 6 | ||
@@ -19,18 +19,18 @@ pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRang | |||
19 | 19 | ||
20 | fn extend_selection_in_macro( | 20 | fn extend_selection_in_macro( |
21 | _db: &RootDatabase, | 21 | _db: &RootDatabase, |
22 | source_file: &SourceFileNode, | 22 | source_file: &SourceFile, |
23 | frange: FileRange, | 23 | frange: FileRange, |
24 | ) -> Option<TextRange> { | 24 | ) -> Option<TextRange> { |
25 | let macro_call = find_macro_call(source_file.syntax(), frange.range)?; | 25 | let macro_call = find_macro_call(source_file.syntax(), frange.range)?; |
26 | let (off, exp) = hir::MacroDef::ast_expand(macro_call)?; | 26 | let (off, exp) = hir::MacroDef::ast_expand(macro_call)?; |
27 | let dst_range = exp.map_range_forward(frange.range - off)?; | 27 | let dst_range = exp.map_range_forward(frange.range - off)?; |
28 | let dst_range = ra_editor::extend_selection(exp.syntax().borrowed(), dst_range)?; | 28 | let dst_range = ra_editor::extend_selection(&exp.syntax(), dst_range)?; |
29 | let src_range = exp.map_range_back(dst_range)? + off; | 29 | let src_range = exp.map_range_back(dst_range)? + off; |
30 | Some(src_range) | 30 | Some(src_range) |
31 | } | 31 | } |
32 | 32 | ||
33 | fn find_macro_call(node: SyntaxNodeRef, range: TextRange) -> Option<ast::MacroCall> { | 33 | fn find_macro_call(node: &SyntaxNode, range: TextRange) -> Option<&ast::MacroCall> { |
34 | find_covering_node(node, range) | 34 | find_covering_node(node, range) |
35 | .ancestors() | 35 | .ancestors() |
36 | .find_map(ast::MacroCall::cast) | 36 | .find_map(ast::MacroCall::cast) |
diff --git a/crates/ra_analysis/src/goto_defenition.rs b/crates/ra_analysis/src/goto_defenition.rs index aa0616e3b..0bcf13ebd 100644 --- a/crates/ra_analysis/src/goto_defenition.rs +++ b/crates/ra_analysis/src/goto_defenition.rs | |||
@@ -23,7 +23,7 @@ pub(crate) fn goto_defenition( | |||
23 | pub(crate) fn reference_defenition( | 23 | pub(crate) fn reference_defenition( |
24 | db: &RootDatabase, | 24 | db: &RootDatabase, |
25 | file_id: FileId, | 25 | file_id: FileId, |
26 | name_ref: ast::NameRef, | 26 | name_ref: &ast::NameRef, |
27 | ) -> Cancelable<Vec<NavigationTarget>> { | 27 | ) -> Cancelable<Vec<NavigationTarget>> { |
28 | if let Some(fn_descr) = | 28 | if let Some(fn_descr) = |
29 | hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? | 29 | hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? |
@@ -53,7 +53,7 @@ pub(crate) fn reference_defenition( | |||
53 | fn name_defenition( | 53 | fn name_defenition( |
54 | db: &RootDatabase, | 54 | db: &RootDatabase, |
55 | file_id: FileId, | 55 | file_id: FileId, |
56 | name: ast::Name, | 56 | name: &ast::Name, |
57 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { | 57 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { |
58 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { | 58 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { |
59 | if module.has_semi() { | 59 | if module.has_semi() { |
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs index 06632df4f..5607c3ef3 100644 --- a/crates/ra_analysis/src/hover.rs +++ b/crates/ra_analysis/src/hover.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use ra_db::{Cancelable, SyntaxDatabase}; | 1 | use ra_db::{Cancelable, SyntaxDatabase}; |
2 | use ra_editor::find_node_at_offset; | 2 | use ra_editor::find_node_at_offset; |
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | AstNode, SyntaxNode, | 4 | AstNode, SyntaxNode, TreePtr, |
5 | ast::{self, NameOwner}, | 5 | ast::{self, NameOwner}, |
6 | algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}}, | 6 | algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}}, |
7 | }; | 7 | }; |
@@ -88,20 +88,19 @@ fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Cancelable<Option<S | |||
88 | } | 88 | } |
89 | 89 | ||
90 | impl NavigationTarget { | 90 | impl NavigationTarget { |
91 | fn node(&self, db: &RootDatabase) -> Option<SyntaxNode> { | 91 | fn node(&self, db: &RootDatabase) -> Option<TreePtr<SyntaxNode>> { |
92 | let source_file = db.source_file(self.file_id); | 92 | let source_file = db.source_file(self.file_id); |
93 | let source_file = source_file.syntax(); | 93 | let source_file = source_file.syntax(); |
94 | let node = source_file | 94 | let node = source_file |
95 | .descendants() | 95 | .descendants() |
96 | .find(|node| node.kind() == self.kind && node.range() == self.range)? | 96 | .find(|node| node.kind() == self.kind && node.range() == self.range)? |
97 | .owned(); | 97 | .to_owned(); |
98 | Some(node) | 98 | Some(node) |
99 | } | 99 | } |
100 | 100 | ||
101 | fn docs(&self, db: &RootDatabase) -> Option<String> { | 101 | fn docs(&self, db: &RootDatabase) -> Option<String> { |
102 | let node = self.node(db)?; | 102 | let node = self.node(db)?; |
103 | let node = node.borrowed(); | 103 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { |
104 | fn doc_comments<'a, N: ast::DocCommentsOwner<'a>>(node: N) -> Option<String> { | ||
105 | let comments = node.doc_comment_text(); | 104 | let comments = node.doc_comment_text(); |
106 | if comments.is_empty() { | 105 | if comments.is_empty() { |
107 | None | 106 | None |
@@ -119,7 +118,7 @@ impl NavigationTarget { | |||
119 | .visit(doc_comments::<ast::TypeDef>) | 118 | .visit(doc_comments::<ast::TypeDef>) |
120 | .visit(doc_comments::<ast::ConstDef>) | 119 | .visit(doc_comments::<ast::ConstDef>) |
121 | .visit(doc_comments::<ast::StaticDef>) | 120 | .visit(doc_comments::<ast::StaticDef>) |
122 | .accept(node)? | 121 | .accept(&node)? |
123 | } | 122 | } |
124 | 123 | ||
125 | /// Get a description of this node. | 124 | /// Get a description of this node. |
@@ -128,50 +127,49 @@ impl NavigationTarget { | |||
128 | fn description(&self, db: &RootDatabase) -> Option<String> { | 127 | fn description(&self, db: &RootDatabase) -> Option<String> { |
129 | // TODO: After type inference is done, add type information to improve the output | 128 | // TODO: After type inference is done, add type information to improve the output |
130 | let node = self.node(db)?; | 129 | let node = self.node(db)?; |
131 | let node = node.borrowed(); | ||
132 | // TODO: Refactor to be have less repetition | 130 | // TODO: Refactor to be have less repetition |
133 | visitor() | 131 | visitor() |
134 | .visit(|node: ast::FnDef| { | 132 | .visit(|node: &ast::FnDef| { |
135 | let mut string = "fn ".to_string(); | 133 | let mut string = "fn ".to_string(); |
136 | node.name()?.syntax().text().push_to(&mut string); | 134 | node.name()?.syntax().text().push_to(&mut string); |
137 | Some(string) | 135 | Some(string) |
138 | }) | 136 | }) |
139 | .visit(|node: ast::StructDef| { | 137 | .visit(|node: &ast::StructDef| { |
140 | let mut string = "struct ".to_string(); | 138 | let mut string = "struct ".to_string(); |
141 | node.name()?.syntax().text().push_to(&mut string); | 139 | node.name()?.syntax().text().push_to(&mut string); |
142 | Some(string) | 140 | Some(string) |
143 | }) | 141 | }) |
144 | .visit(|node: ast::EnumDef| { | 142 | .visit(|node: &ast::EnumDef| { |
145 | let mut string = "enum ".to_string(); | 143 | let mut string = "enum ".to_string(); |
146 | node.name()?.syntax().text().push_to(&mut string); | 144 | node.name()?.syntax().text().push_to(&mut string); |
147 | Some(string) | 145 | Some(string) |
148 | }) | 146 | }) |
149 | .visit(|node: ast::TraitDef| { | 147 | .visit(|node: &ast::TraitDef| { |
150 | let mut string = "trait ".to_string(); | 148 | let mut string = "trait ".to_string(); |
151 | node.name()?.syntax().text().push_to(&mut string); | 149 | node.name()?.syntax().text().push_to(&mut string); |
152 | Some(string) | 150 | Some(string) |
153 | }) | 151 | }) |
154 | .visit(|node: ast::Module| { | 152 | .visit(|node: &ast::Module| { |
155 | let mut string = "mod ".to_string(); | 153 | let mut string = "mod ".to_string(); |
156 | node.name()?.syntax().text().push_to(&mut string); | 154 | node.name()?.syntax().text().push_to(&mut string); |
157 | Some(string) | 155 | Some(string) |
158 | }) | 156 | }) |
159 | .visit(|node: ast::TypeDef| { | 157 | .visit(|node: &ast::TypeDef| { |
160 | let mut string = "type ".to_string(); | 158 | let mut string = "type ".to_string(); |
161 | node.name()?.syntax().text().push_to(&mut string); | 159 | node.name()?.syntax().text().push_to(&mut string); |
162 | Some(string) | 160 | Some(string) |
163 | }) | 161 | }) |
164 | .visit(|node: ast::ConstDef| { | 162 | .visit(|node: &ast::ConstDef| { |
165 | let mut string = "const ".to_string(); | 163 | let mut string = "const ".to_string(); |
166 | node.name()?.syntax().text().push_to(&mut string); | 164 | node.name()?.syntax().text().push_to(&mut string); |
167 | Some(string) | 165 | Some(string) |
168 | }) | 166 | }) |
169 | .visit(|node: ast::StaticDef| { | 167 | .visit(|node: &ast::StaticDef| { |
170 | let mut string = "static ".to_string(); | 168 | let mut string = "static ".to_string(); |
171 | node.name()?.syntax().text().push_to(&mut string); | 169 | node.name()?.syntax().text().push_to(&mut string); |
172 | Some(string) | 170 | Some(string) |
173 | }) | 171 | }) |
174 | .accept(node)? | 172 | .accept(&node)? |
175 | } | 173 | } |
176 | } | 174 | } |
177 | 175 | ||
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 07a966290..8ac430e41 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -8,10 +8,9 @@ use hir::{ | |||
8 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; | 8 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; |
9 | use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity}; | 9 | use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity}; |
10 | use ra_syntax::{ | 10 | use ra_syntax::{ |
11 | ast::{self, ArgListOwner, Expr, NameOwner}, | 11 | SyntaxNode, TextRange, TextUnit, AstNode, SourceFile, |
12 | AstNode, SourceFileNode, | 12 | ast::{self, ArgListOwner, NameOwner}, |
13 | SyntaxKind::*, | 13 | SyntaxKind::*, |
14 | SyntaxNodeRef, TextRange, TextUnit, | ||
15 | }; | 14 | }; |
16 | 15 | ||
17 | use crate::{ | 16 | use crate::{ |
@@ -113,7 +112,6 @@ impl db::RootDatabase { | |||
113 | None => return Ok(Vec::new()), | 112 | None => return Ok(Vec::new()), |
114 | Some(it) => it, | 113 | Some(it) => it, |
115 | }; | 114 | }; |
116 | let ast_module = ast_module.borrowed(); | ||
117 | let name = ast_module.name().unwrap(); | 115 | let name = ast_module.name().unwrap(); |
118 | Ok(vec![NavigationTarget { | 116 | Ok(vec![NavigationTarget { |
119 | file_id, | 117 | file_id, |
@@ -163,9 +161,9 @@ impl db::RootDatabase { | |||
163 | 161 | ||
164 | fn find_binding<'a>( | 162 | fn find_binding<'a>( |
165 | db: &db::RootDatabase, | 163 | db: &db::RootDatabase, |
166 | source_file: &'a SourceFileNode, | 164 | source_file: &'a SourceFile, |
167 | position: FilePosition, | 165 | position: FilePosition, |
168 | ) -> Cancelable<Option<(ast::BindPat<'a>, hir::Function)>> { | 166 | ) -> Cancelable<Option<(&'a ast::BindPat, hir::Function)>> { |
169 | let syntax = source_file.syntax(); | 167 | let syntax = source_file.syntax(); |
170 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { | 168 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { |
171 | let descr = ctry!(source_binder::function_from_child_node( | 169 | let descr = ctry!(source_binder::function_from_child_node( |
@@ -281,7 +279,7 @@ impl db::RootDatabase { | |||
281 | if symbol.ptr.kind() == FN_DEF { | 279 | if symbol.ptr.kind() == FN_DEF { |
282 | let fn_file = self.source_file(symbol.file_id); | 280 | let fn_file = self.source_file(symbol.file_id); |
283 | let fn_def = symbol.ptr.resolve(&fn_file); | 281 | let fn_def = symbol.ptr.resolve(&fn_file); |
284 | let fn_def = ast::FnDef::cast(fn_def.borrowed()).unwrap(); | 282 | let fn_def = ast::FnDef::cast(&fn_def).unwrap(); |
285 | let descr = ctry!(source_binder::function_from_source( | 283 | let descr = ctry!(source_binder::function_from_source( |
286 | self, | 284 | self, |
287 | symbol.file_id, | 285 | symbol.file_id, |
@@ -352,7 +350,7 @@ impl db::RootDatabase { | |||
352 | .collect::<Vec<_>>(); | 350 | .collect::<Vec<_>>(); |
353 | Ok(res) | 351 | Ok(res) |
354 | } | 352 | } |
355 | pub(crate) fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<FileSymbol>> { | 353 | pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Cancelable<Vec<FileSymbol>> { |
356 | let name = name_ref.text(); | 354 | let name = name_ref.text(); |
357 | let mut query = Query::new(name.to_string()); | 355 | let mut query = Query::new(name.to_string()); |
358 | query.exact(); | 356 | query.exact(); |
@@ -379,12 +377,12 @@ impl SourceChange { | |||
379 | } | 377 | } |
380 | 378 | ||
381 | enum FnCallNode<'a> { | 379 | enum FnCallNode<'a> { |
382 | CallExpr(ast::CallExpr<'a>), | 380 | CallExpr(&'a ast::CallExpr), |
383 | MethodCallExpr(ast::MethodCallExpr<'a>), | 381 | MethodCallExpr(&'a ast::MethodCallExpr), |
384 | } | 382 | } |
385 | 383 | ||
386 | impl<'a> FnCallNode<'a> { | 384 | impl<'a> FnCallNode<'a> { |
387 | pub fn with_node(syntax: SyntaxNodeRef, offset: TextUnit) -> Option<FnCallNode> { | 385 | pub fn with_node(syntax: &'a SyntaxNode, offset: TextUnit) -> Option<FnCallNode<'a>> { |
388 | if let Some(expr) = find_node_at_offset::<ast::CallExpr>(syntax, offset) { | 386 | if let Some(expr) = find_node_at_offset::<ast::CallExpr>(syntax, offset) { |
389 | return Some(FnCallNode::CallExpr(expr)); | 387 | return Some(FnCallNode::CallExpr(expr)); |
390 | } | 388 | } |
@@ -394,10 +392,10 @@ impl<'a> FnCallNode<'a> { | |||
394 | None | 392 | None |
395 | } | 393 | } |
396 | 394 | ||
397 | pub fn name_ref(&self) -> Option<ast::NameRef> { | 395 | pub fn name_ref(&self) -> Option<&'a ast::NameRef> { |
398 | match *self { | 396 | match *self { |
399 | FnCallNode::CallExpr(call_expr) => Some(match call_expr.expr()? { | 397 | FnCallNode::CallExpr(call_expr) => Some(match call_expr.expr()?.kind() { |
400 | Expr::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?, | 398 | ast::ExprKind::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?, |
401 | _ => return None, | 399 | _ => return None, |
402 | }), | 400 | }), |
403 | 401 | ||
@@ -409,7 +407,7 @@ impl<'a> FnCallNode<'a> { | |||
409 | } | 407 | } |
410 | } | 408 | } |
411 | 409 | ||
412 | pub fn arg_list(&self) -> Option<ast::ArgList> { | 410 | pub fn arg_list(&self) -> Option<&'a ast::ArgList> { |
413 | match *self { | 411 | match *self { |
414 | FnCallNode::CallExpr(expr) => expr.arg_list(), | 412 | FnCallNode::CallExpr(expr) => expr.arg_list(), |
415 | FnCallNode::MethodCallExpr(expr) => expr.arg_list(), | 413 | FnCallNode::MethodCallExpr(expr) => expr.arg_list(), |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index c8f846c56..ec400ffe2 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -26,7 +26,7 @@ mod syntax_highlighting; | |||
26 | 26 | ||
27 | use std::{fmt, sync::Arc}; | 27 | use std::{fmt, sync::Arc}; |
28 | 28 | ||
29 | use ra_syntax::{SmolStr, SourceFileNode, SyntaxKind, TextRange, TextUnit}; | 29 | use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; |
30 | use ra_text_edit::TextEdit; | 30 | use ra_text_edit::TextEdit; |
31 | use rayon::prelude::*; | 31 | use rayon::prelude::*; |
32 | use relative_path::RelativePathBuf; | 32 | use relative_path::RelativePathBuf; |
@@ -308,7 +308,7 @@ impl Analysis { | |||
308 | self.db.file_text(file_id) | 308 | self.db.file_text(file_id) |
309 | } | 309 | } |
310 | /// Gets the syntax tree of the file. | 310 | /// Gets the syntax tree of the file. |
311 | pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { | 311 | pub fn file_syntax(&self, file_id: FileId) -> TreePtr<SourceFile> { |
312 | self.db.source_file(file_id).clone() | 312 | self.db.source_file(file_id).clone() |
313 | } | 313 | } |
314 | /// Gets the file's `LineIndex`: data structure to convert between absolute | 314 | /// Gets the file's `LineIndex`: data structure to convert between absolute |
@@ -322,7 +322,7 @@ impl Analysis { | |||
322 | } | 322 | } |
323 | /// Returns position of the mathcing brace (all types of braces are | 323 | /// Returns position of the mathcing brace (all types of braces are |
324 | /// supported). | 324 | /// supported). |
325 | pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { | 325 | pub fn matching_brace(&self, file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { |
326 | ra_editor::matching_brace(file, offset) | 326 | ra_editor::matching_brace(file, offset) |
327 | } | 327 | } |
328 | /// Returns a syntax tree represented as `String`, for debug purposes. | 328 | /// Returns a syntax tree represented as `String`, for debug purposes. |
@@ -469,7 +469,7 @@ impl LibraryData { | |||
469 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, | 469 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, |
470 | ) -> LibraryData { | 470 | ) -> LibraryData { |
471 | let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { | 471 | let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { |
472 | let file = SourceFileNode::parse(text); | 472 | let file = SourceFile::parse(text); |
473 | (*file_id, file) | 473 | (*file_id, file) |
474 | })); | 474 | })); |
475 | let mut root_change = RootChange::default(); | 475 | let mut root_change = RootChange::default(); |
diff --git a/crates/ra_analysis/src/runnables.rs b/crates/ra_analysis/src/runnables.rs index 216209098..98b1d2d55 100644 --- a/crates/ra_analysis/src/runnables.rs +++ b/crates/ra_analysis/src/runnables.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use itertools::Itertools; | 1 | use itertools::Itertools; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | TextRange, SyntaxNode, | ||
3 | ast::{self, AstNode, NameOwner, ModuleItemOwner}, | 4 | ast::{self, AstNode, NameOwner, ModuleItemOwner}, |
4 | TextRange, SyntaxNodeRef, | ||
5 | }; | 5 | }; |
6 | use ra_db::{Cancelable, SyntaxDatabase}; | 6 | use ra_db::{Cancelable, SyntaxDatabase}; |
7 | 7 | ||
@@ -30,7 +30,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Ru | |||
30 | Ok(res) | 30 | Ok(res) |
31 | } | 31 | } |
32 | 32 | ||
33 | fn runnable(db: &RootDatabase, file_id: FileId, item: SyntaxNodeRef) -> Option<Runnable> { | 33 | fn runnable(db: &RootDatabase, file_id: FileId, item: &SyntaxNode) -> Option<Runnable> { |
34 | if let Some(fn_def) = ast::FnDef::cast(item) { | 34 | if let Some(fn_def) = ast::FnDef::cast(item) { |
35 | runnable_fn(fn_def) | 35 | runnable_fn(fn_def) |
36 | } else if let Some(m) = ast::Module::cast(item) { | 36 | } else if let Some(m) = ast::Module::cast(item) { |
@@ -40,7 +40,7 @@ fn runnable(db: &RootDatabase, file_id: FileId, item: SyntaxNodeRef) -> Option<R | |||
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> { | 43 | fn runnable_fn(fn_def: &ast::FnDef) -> Option<Runnable> { |
44 | let name = fn_def.name()?.text(); | 44 | let name = fn_def.name()?.text(); |
45 | let kind = if name == "main" { | 45 | let kind = if name == "main" { |
46 | RunnableKind::Bin | 46 | RunnableKind::Bin |
@@ -57,12 +57,12 @@ fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> { | |||
57 | }) | 57 | }) |
58 | } | 58 | } |
59 | 59 | ||
60 | fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Option<Runnable> { | 60 | fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Option<Runnable> { |
61 | let has_test_function = module | 61 | let has_test_function = module |
62 | .item_list()? | 62 | .item_list()? |
63 | .items() | 63 | .items() |
64 | .filter_map(|it| match it { | 64 | .filter_map(|it| match it.kind() { |
65 | ast::ModuleItem::FnDef(it) => Some(it), | 65 | ast::ModuleItemKind::FnDef(it) => Some(it), |
66 | _ => None, | 66 | _ => None, |
67 | }) | 67 | }) |
68 | .any(|f| f.has_atom_attr("test")); | 68 | .any(|f| f.has_atom_attr("test")); |
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs index e2b1c88fe..ed1796756 100644 --- a/crates/ra_analysis/src/symbol_index.rs +++ b/crates/ra_analysis/src/symbol_index.rs | |||
@@ -27,7 +27,7 @@ use std::{ | |||
27 | 27 | ||
28 | use fst::{self, Streamer}; | 28 | use fst::{self, Streamer}; |
29 | use ra_syntax::{ | 29 | use ra_syntax::{ |
30 | SyntaxNodeRef, SourceFileNode, SmolStr, | 30 | SyntaxNode, SourceFile, SmolStr, TreePtr, AstNode, |
31 | algo::{visit::{visitor, Visitor}, find_covering_node}, | 31 | algo::{visit::{visitor, Visitor}, find_covering_node}, |
32 | SyntaxKind::{self, *}, | 32 | SyntaxKind::{self, *}, |
33 | ast::{self, NameOwner}, | 33 | ast::{self, NameOwner}, |
@@ -141,7 +141,7 @@ impl SymbolIndex { | |||
141 | } | 141 | } |
142 | 142 | ||
143 | pub(crate) fn for_files( | 143 | pub(crate) fn for_files( |
144 | files: impl ParallelIterator<Item = (FileId, SourceFileNode)>, | 144 | files: impl ParallelIterator<Item = (FileId, TreePtr<SourceFile>)>, |
145 | ) -> SymbolIndex { | 145 | ) -> SymbolIndex { |
146 | let symbols = files | 146 | let symbols = files |
147 | .flat_map(|(file_id, file)| { | 147 | .flat_map(|(file_id, file)| { |
@@ -203,8 +203,8 @@ pub(crate) struct FileSymbol { | |||
203 | pub(crate) ptr: LocalSyntaxPtr, | 203 | pub(crate) ptr: LocalSyntaxPtr, |
204 | } | 204 | } |
205 | 205 | ||
206 | fn to_symbol(node: SyntaxNodeRef) -> Option<(SmolStr, LocalSyntaxPtr)> { | 206 | fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, LocalSyntaxPtr)> { |
207 | fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<(SmolStr, LocalSyntaxPtr)> { | 207 | fn decl<N: NameOwner>(node: &N) -> Option<(SmolStr, LocalSyntaxPtr)> { |
208 | let name = node.name()?.text(); | 208 | let name = node.name()?.text(); |
209 | let ptr = LocalSyntaxPtr::new(node.syntax()); | 209 | let ptr = LocalSyntaxPtr::new(node.syntax()); |
210 | Some((name, ptr)) | 210 | Some((name, ptr)) |
diff --git a/crates/ra_analysis/src/syntax_highlighting.rs b/crates/ra_analysis/src/syntax_highlighting.rs index 35e153ca0..d2dc6cfbb 100644 --- a/crates/ra_analysis/src/syntax_highlighting.rs +++ b/crates/ra_analysis/src/syntax_highlighting.rs | |||
@@ -16,7 +16,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Hi | |||
16 | .filter_map(ast::MacroCall::cast) | 16 | .filter_map(ast::MacroCall::cast) |
17 | { | 17 | { |
18 | if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) { | 18 | if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) { |
19 | let mapped_ranges = ra_editor::highlight(exp.syntax().borrowed()) | 19 | let mapped_ranges = ra_editor::highlight(&exp.syntax()) |
20 | .into_iter() | 20 | .into_iter() |
21 | .filter_map(|r| { | 21 | .filter_map(|r| { |
22 | let mapped_range = exp.map_range_back(r.range)?; | 22 | let mapped_range = exp.map_range_back(r.range)?; |
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index a3b856aa9..0d12f3a88 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -3,7 +3,7 @@ use std::{fs, io::Read, path::Path, time::Instant}; | |||
3 | use clap::{App, Arg, SubCommand}; | 3 | use clap::{App, Arg, SubCommand}; |
4 | use join_to_string::join; | 4 | use join_to_string::join; |
5 | use ra_editor::{extend_selection, file_structure, syntax_tree}; | 5 | use ra_editor::{extend_selection, file_structure, syntax_tree}; |
6 | use ra_syntax::{SourceFileNode, TextRange}; | 6 | use ra_syntax::{SourceFile, TextRange, TreePtr, AstNode}; |
7 | use tools::collect_tests; | 7 | use tools::collect_tests; |
8 | 8 | ||
9 | type Result<T> = ::std::result::Result<T, failure::Error>; | 9 | type Result<T> = ::std::result::Result<T, failure::Error>; |
@@ -71,9 +71,9 @@ fn main() -> Result<()> { | |||
71 | Ok(()) | 71 | Ok(()) |
72 | } | 72 | } |
73 | 73 | ||
74 | fn file() -> Result<SourceFileNode> { | 74 | fn file() -> Result<TreePtr<SourceFile>> { |
75 | let text = read_stdin()?; | 75 | let text = read_stdin()?; |
76 | Ok(SourceFileNode::parse(&text)) | 76 | Ok(SourceFile::parse(&text)) |
77 | } | 77 | } |
78 | 78 | ||
79 | fn read_stdin() -> Result<String> { | 79 | fn read_stdin() -> Result<String> { |
@@ -92,12 +92,12 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> { | |||
92 | None => failure::bail!("No test found at line {} at {}", line, file.display()), | 92 | None => failure::bail!("No test found at line {} at {}", line, file.display()), |
93 | Some((_start_line, test)) => test, | 93 | Some((_start_line, test)) => test, |
94 | }; | 94 | }; |
95 | let file = SourceFileNode::parse(&test.text); | 95 | let file = SourceFile::parse(&test.text); |
96 | let tree = syntax_tree(&file); | 96 | let tree = syntax_tree(&file); |
97 | Ok((test.text, tree)) | 97 | Ok((test.text, tree)) |
98 | } | 98 | } |
99 | 99 | ||
100 | fn selections(file: &SourceFileNode, start: u32, end: u32) -> String { | 100 | fn selections(file: &SourceFile, start: u32, end: u32) -> String { |
101 | let mut ranges = Vec::new(); | 101 | let mut ranges = Vec::new(); |
102 | let mut cur = Some(TextRange::from_to((start - 1).into(), (end - 1).into())); | 102 | let mut cur = Some(TextRange::from_to((start - 1).into(), (end - 1).into())); |
103 | while let Some(r) = cur { | 103 | while let Some(r) = cur { |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 7181f2950..3c41ee56d 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -8,7 +8,7 @@ pub mod mock; | |||
8 | use std::sync::Arc; | 8 | use std::sync::Arc; |
9 | 9 | ||
10 | use ra_editor::LineIndex; | 10 | use ra_editor::LineIndex; |
11 | use ra_syntax::{TextUnit, TextRange, SourceFileNode}; | 11 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; |
12 | 12 | ||
13 | pub use crate::{ | 13 | pub use crate::{ |
14 | cancelation::{Canceled, Cancelable}, | 14 | cancelation::{Canceled, Cancelable}, |
@@ -47,7 +47,7 @@ pub trait BaseDatabase: salsa::Database { | |||
47 | 47 | ||
48 | salsa::query_group! { | 48 | salsa::query_group! { |
49 | pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase { | 49 | pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase { |
50 | fn source_file(file_id: FileId) -> SourceFileNode { | 50 | fn source_file(file_id: FileId) -> TreePtr<SourceFile> { |
51 | type SourceFileQuery; | 51 | type SourceFileQuery; |
52 | } | 52 | } |
53 | fn file_lines(file_id: FileId) -> Arc<LineIndex> { | 53 | fn file_lines(file_id: FileId) -> Arc<LineIndex> { |
@@ -56,9 +56,9 @@ salsa::query_group! { | |||
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode { | 59 | fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreePtr<SourceFile> { |
60 | let text = db.file_text(file_id); | 60 | let text = db.file_text(file_id); |
61 | SourceFileNode::parse(&*text) | 61 | SourceFile::parse(&*text) |
62 | } | 62 | } |
63 | fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { | 63 | fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { |
64 | let text = db.file_text(file_id); | 64 | let text = db.file_text(file_id); |
diff --git a/crates/ra_db/src/syntax_ptr.rs b/crates/ra_db/src/syntax_ptr.rs index 5bfcedf2b..be64d417c 100644 --- a/crates/ra_db/src/syntax_ptr.rs +++ b/crates/ra_db/src/syntax_ptr.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; | 1 | use ra_syntax::{AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, TreePtr}; |
2 | 2 | ||
3 | /// A pointer to a syntax node inside a file. | 3 | /// A pointer to a syntax node inside a file. |
4 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 4 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -8,18 +8,18 @@ pub struct LocalSyntaxPtr { | |||
8 | } | 8 | } |
9 | 9 | ||
10 | impl LocalSyntaxPtr { | 10 | impl LocalSyntaxPtr { |
11 | pub fn new(node: SyntaxNodeRef) -> LocalSyntaxPtr { | 11 | pub fn new(node: &SyntaxNode) -> LocalSyntaxPtr { |
12 | LocalSyntaxPtr { | 12 | LocalSyntaxPtr { |
13 | range: node.range(), | 13 | range: node.range(), |
14 | kind: node.kind(), | 14 | kind: node.kind(), |
15 | } | 15 | } |
16 | } | 16 | } |
17 | 17 | ||
18 | pub fn resolve(self, file: &SourceFileNode) -> SyntaxNode { | 18 | pub fn resolve(self, file: &SourceFile) -> TreePtr<SyntaxNode> { |
19 | let mut curr = file.syntax(); | 19 | let mut curr = file.syntax(); |
20 | loop { | 20 | loop { |
21 | if curr.range() == self.range && curr.kind() == self.kind { | 21 | if curr.range() == self.range && curr.kind() == self.kind { |
22 | return curr.owned(); | 22 | return curr.to_owned(); |
23 | } | 23 | } |
24 | curr = curr | 24 | curr = curr |
25 | .children() | 25 | .children() |
@@ -40,7 +40,7 @@ impl LocalSyntaxPtr { | |||
40 | #[test] | 40 | #[test] |
41 | fn test_local_syntax_ptr() { | 41 | fn test_local_syntax_ptr() { |
42 | use ra_syntax::{ast, AstNode}; | 42 | use ra_syntax::{ast, AstNode}; |
43 | let file = SourceFileNode::parse("struct Foo { f: u32, }"); | 43 | let file = SourceFile::parse("struct Foo { f: u32, }"); |
44 | let field = file | 44 | let field = file |
45 | .syntax() | 45 | .syntax() |
46 | .descendants() | 46 | .descendants() |
@@ -48,5 +48,5 @@ fn test_local_syntax_ptr() { | |||
48 | .unwrap(); | 48 | .unwrap(); |
49 | let ptr = LocalSyntaxPtr::new(field.syntax()); | 49 | let ptr = LocalSyntaxPtr::new(field.syntax()); |
50 | let field_syntax = ptr.resolve(&file); | 50 | let field_syntax = ptr.resolve(&file); |
51 | assert_eq!(field.syntax(), field_syntax); | 51 | assert_eq!(field.syntax(), &*field_syntax); |
52 | } | 52 | } |
diff --git a/crates/ra_editor/src/assists.rs b/crates/ra_editor/src/assists.rs index 57b78342a..a320caabf 100644 --- a/crates/ra_editor/src/assists.rs +++ b/crates/ra_editor/src/assists.rs | |||
@@ -12,7 +12,7 @@ mod split_import; | |||
12 | 12 | ||
13 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 13 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
14 | use ra_syntax::{ | 14 | use ra_syntax::{ |
15 | Direction, SyntaxNodeRef, TextUnit, TextRange,SourceFileNode, AstNode, | 15 | Direction, SyntaxNode, TextUnit, TextRange, SourceFile, AstNode, |
16 | algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset}, | 16 | algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset}, |
17 | }; | 17 | }; |
18 | 18 | ||
@@ -28,7 +28,7 @@ pub use self::{ | |||
28 | }; | 28 | }; |
29 | 29 | ||
30 | /// Return all the assists applicable at the given position. | 30 | /// Return all the assists applicable at the given position. |
31 | pub fn assists(file: &SourceFileNode, range: TextRange) -> Vec<LocalEdit> { | 31 | pub fn assists(file: &SourceFile, range: TextRange) -> Vec<LocalEdit> { |
32 | let ctx = AssistCtx::new(file, range); | 32 | let ctx = AssistCtx::new(file, range); |
33 | [ | 33 | [ |
34 | flip_comma, | 34 | flip_comma, |
@@ -50,7 +50,7 @@ pub struct LocalEdit { | |||
50 | pub cursor_position: Option<TextUnit>, | 50 | pub cursor_position: Option<TextUnit>, |
51 | } | 51 | } |
52 | 52 | ||
53 | fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { | 53 | fn non_trivia_sibling(node: &SyntaxNode, direction: Direction) -> Option<&SyntaxNode> { |
54 | node.siblings(direction) | 54 | node.siblings(direction) |
55 | .skip(1) | 55 | .skip(1) |
56 | .find(|node| !node.kind().is_trivia()) | 56 | .find(|node| !node.kind().is_trivia()) |
@@ -88,7 +88,7 @@ fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<Synta | |||
88 | /// easier to just compute the edit eagarly :-) | 88 | /// easier to just compute the edit eagarly :-) |
89 | #[derive(Debug, Clone)] | 89 | #[derive(Debug, Clone)] |
90 | pub struct AssistCtx<'a> { | 90 | pub struct AssistCtx<'a> { |
91 | source_file: &'a SourceFileNode, | 91 | source_file: &'a SourceFile, |
92 | range: TextRange, | 92 | range: TextRange, |
93 | should_compute_edit: bool, | 93 | should_compute_edit: bool, |
94 | } | 94 | } |
@@ -106,7 +106,7 @@ struct AssistBuilder { | |||
106 | } | 106 | } |
107 | 107 | ||
108 | impl<'a> AssistCtx<'a> { | 108 | impl<'a> AssistCtx<'a> { |
109 | pub fn new(source_file: &'a SourceFileNode, range: TextRange) -> AssistCtx { | 109 | pub fn new(source_file: &'a SourceFile, range: TextRange) -> AssistCtx { |
110 | AssistCtx { | 110 | AssistCtx { |
111 | source_file, | 111 | source_file, |
112 | range, | 112 | range, |
@@ -145,13 +145,13 @@ impl<'a> AssistCtx<'a> { | |||
145 | })) | 145 | })) |
146 | } | 146 | } |
147 | 147 | ||
148 | pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<SyntaxNodeRef<'a>> { | 148 | pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<&'a SyntaxNode> { |
149 | find_leaf_at_offset(self.source_file.syntax(), self.range.start()) | 149 | find_leaf_at_offset(self.source_file.syntax(), self.range.start()) |
150 | } | 150 | } |
151 | pub(crate) fn node_at_offset<N: AstNode<'a>>(&self) -> Option<N> { | 151 | pub(crate) fn node_at_offset<N: AstNode>(&self) -> Option<&'a N> { |
152 | find_node_at_offset(self.source_file.syntax(), self.range.start()) | 152 | find_node_at_offset(self.source_file.syntax(), self.range.start()) |
153 | } | 153 | } |
154 | pub(crate) fn covering_node(&self) -> SyntaxNodeRef<'a> { | 154 | pub(crate) fn covering_node(&self) -> &'a SyntaxNode { |
155 | find_covering_node(self.source_file.syntax(), self.range) | 155 | find_covering_node(self.source_file.syntax(), self.range) |
156 | } | 156 | } |
157 | } | 157 | } |
diff --git a/crates/ra_editor/src/assists/add_derive.rs b/crates/ra_editor/src/assists/add_derive.rs index 1e2cd4f30..6e964d011 100644 --- a/crates/ra_editor/src/assists/add_derive.rs +++ b/crates/ra_editor/src/assists/add_derive.rs | |||
@@ -28,7 +28,7 @@ pub fn add_derive(ctx: AssistCtx) -> Option<Assist> { | |||
28 | } | 28 | } |
29 | 29 | ||
30 | // Insert `derive` after doc comments. | 30 | // Insert `derive` after doc comments. |
31 | fn derive_insertion_offset(nominal: ast::NominalDef) -> Option<TextUnit> { | 31 | fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextUnit> { |
32 | let non_ws_child = nominal | 32 | let non_ws_child = nominal |
33 | .syntax() | 33 | .syntax() |
34 | .children() | 34 | .children() |
diff --git a/crates/ra_editor/src/assists/change_visibility.rs b/crates/ra_editor/src/assists/change_visibility.rs index 6c8466394..89729e2c2 100644 --- a/crates/ra_editor/src/assists/change_visibility.rs +++ b/crates/ra_editor/src/assists/change_visibility.rs | |||
@@ -46,7 +46,7 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> { | |||
46 | }) | 46 | }) |
47 | } | 47 | } |
48 | 48 | ||
49 | fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> { | 49 | fn change_vis(ctx: AssistCtx, vis: &ast::Visibility) -> Option<Assist> { |
50 | if vis.syntax().text() != "pub" { | 50 | if vis.syntax().text() != "pub" { |
51 | return None; | 51 | return None; |
52 | } | 52 | } |
diff --git a/crates/ra_editor/src/assists/introduce_variable.rs b/crates/ra_editor/src/assists/introduce_variable.rs index 782861023..523ec7034 100644 --- a/crates/ra_editor/src/assists/introduce_variable.rs +++ b/crates/ra_editor/src/assists/introduce_variable.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use ra_syntax::{ | 1 | use ra_syntax::{ |
2 | ast::{self, AstNode}, | 2 | ast::{self, AstNode}, |
3 | SyntaxKind::WHITESPACE, | 3 | SyntaxKind::WHITESPACE, |
4 | SyntaxNodeRef, TextUnit, | 4 | SyntaxNode, TextUnit, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use crate::assists::{AssistCtx, Assist}; | 7 | use crate::assists::{AssistCtx, Assist}; |
@@ -39,7 +39,7 @@ pub fn introduce_variable<'a>(ctx: AssistCtx) -> Option<Assist> { | |||
39 | 39 | ||
40 | /// Statement or last in the block expression, which will follow | 40 | /// Statement or last in the block expression, which will follow |
41 | /// the freshly introduced var. | 41 | /// the freshly introduced var. |
42 | fn anchor_stmt(expr: ast::Expr) -> Option<SyntaxNodeRef> { | 42 | fn anchor_stmt(expr: &ast::Expr) -> Option<&SyntaxNode> { |
43 | expr.syntax().ancestors().find(|&node| { | 43 | expr.syntax().ancestors().find(|&node| { |
44 | if ast::Stmt::cast(node).is_some() { | 44 | if ast::Stmt::cast(node).is_some() { |
45 | return true; | 45 | return true; |
diff --git a/crates/ra_editor/src/diagnostics.rs b/crates/ra_editor/src/diagnostics.rs index 199b0e502..2b695dfdf 100644 --- a/crates/ra_editor/src/diagnostics.rs +++ b/crates/ra_editor/src/diagnostics.rs | |||
@@ -1,25 +1,15 @@ | |||
1 | use itertools::Itertools; | 1 | use itertools::Itertools; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | Location, SourceFile, SyntaxKind, TextRange, SyntaxNode, | ||
4 | ast::{self, AstNode}, | 5 | ast::{self, AstNode}, |
5 | Location, | ||
6 | SourceFileNode, | ||
7 | SyntaxKind, | ||
8 | TextRange, | ||
9 | }; | ||
10 | use ra_syntax::SyntaxNodeRef; | ||
11 | use ra_text_edit::{ | ||
12 | TextEdit, | ||
13 | TextEditBuilder, | ||
14 | }; | ||
15 | 6 | ||
16 | use crate::{ | ||
17 | Diagnostic, | ||
18 | LocalEdit, | ||
19 | Severity, | ||
20 | }; | 7 | }; |
8 | use ra_text_edit::{TextEdit, TextEditBuilder}; | ||
9 | |||
10 | use crate::{Diagnostic, LocalEdit, Severity}; | ||
21 | 11 | ||
22 | pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> { | 12 | pub fn diagnostics(file: &SourceFile) -> Vec<Diagnostic> { |
23 | fn location_to_range(location: Location) -> TextRange { | 13 | fn location_to_range(location: Location) -> TextRange { |
24 | match location { | 14 | match location { |
25 | Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), | 15 | Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), |
@@ -48,7 +38,7 @@ pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> { | |||
48 | 38 | ||
49 | fn check_unnecessary_braces_in_use_statement( | 39 | fn check_unnecessary_braces_in_use_statement( |
50 | acc: &mut Vec<Diagnostic>, | 40 | acc: &mut Vec<Diagnostic>, |
51 | node: SyntaxNodeRef, | 41 | node: &SyntaxNode, |
52 | ) -> Option<()> { | 42 | ) -> Option<()> { |
53 | let use_tree_list = ast::UseTreeList::cast(node)?; | 43 | let use_tree_list = ast::UseTreeList::cast(node)?; |
54 | if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() { | 44 | if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() { |
@@ -79,7 +69,7 @@ fn check_unnecessary_braces_in_use_statement( | |||
79 | } | 69 | } |
80 | 70 | ||
81 | fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( | 71 | fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( |
82 | single_use_tree: ast::UseTree, | 72 | single_use_tree: &ast::UseTree, |
83 | ) -> Option<TextEdit> { | 73 | ) -> Option<TextEdit> { |
84 | let use_tree_list_node = single_use_tree.syntax().parent()?; | 74 | let use_tree_list_node = single_use_tree.syntax().parent()?; |
85 | if single_use_tree | 75 | if single_use_tree |
@@ -102,7 +92,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( | |||
102 | 92 | ||
103 | fn check_struct_shorthand_initialization( | 93 | fn check_struct_shorthand_initialization( |
104 | acc: &mut Vec<Diagnostic>, | 94 | acc: &mut Vec<Diagnostic>, |
105 | node: SyntaxNodeRef, | 95 | node: &SyntaxNode, |
106 | ) -> Option<()> { | 96 | ) -> Option<()> { |
107 | let struct_lit = ast::StructLit::cast(node)?; | 97 | let struct_lit = ast::StructLit::cast(node)?; |
108 | let named_field_list = struct_lit.named_field_list()?; | 98 | let named_field_list = struct_lit.named_field_list()?; |
@@ -138,10 +128,10 @@ mod tests { | |||
138 | 128 | ||
139 | use super::*; | 129 | use super::*; |
140 | 130 | ||
141 | type DiagnosticChecker = fn(&mut Vec<Diagnostic>, SyntaxNodeRef) -> Option<()>; | 131 | type DiagnosticChecker = fn(&mut Vec<Diagnostic>, &SyntaxNode) -> Option<()>; |
142 | 132 | ||
143 | fn check_not_applicable(code: &str, func: DiagnosticChecker) { | 133 | fn check_not_applicable(code: &str, func: DiagnosticChecker) { |
144 | let file = SourceFileNode::parse(code); | 134 | let file = SourceFile::parse(code); |
145 | let mut diagnostics = Vec::new(); | 135 | let mut diagnostics = Vec::new(); |
146 | for node in file.syntax().descendants() { | 136 | for node in file.syntax().descendants() { |
147 | func(&mut diagnostics, node); | 137 | func(&mut diagnostics, node); |
@@ -150,7 +140,7 @@ mod tests { | |||
150 | } | 140 | } |
151 | 141 | ||
152 | fn check_apply(before: &str, after: &str, func: DiagnosticChecker) { | 142 | fn check_apply(before: &str, after: &str, func: DiagnosticChecker) { |
153 | let file = SourceFileNode::parse(before); | 143 | let file = SourceFile::parse(before); |
154 | let mut diagnostics = Vec::new(); | 144 | let mut diagnostics = Vec::new(); |
155 | for node in file.syntax().descendants() { | 145 | for node in file.syntax().descendants() { |
156 | func(&mut diagnostics, node); | 146 | func(&mut diagnostics, node); |
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs index 7a423852b..08cae5a51 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs | |||
@@ -1,11 +1,10 @@ | |||
1 | use ra_syntax::{ | 1 | use ra_syntax::{ |
2 | Direction, SyntaxNode, TextRange, TextUnit, | ||
2 | algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, | 3 | algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, |
3 | Direction, | ||
4 | SyntaxKind::*, | 4 | SyntaxKind::*, |
5 | SyntaxNodeRef, TextRange, TextUnit, | ||
6 | }; | 5 | }; |
7 | 6 | ||
8 | pub fn extend_selection(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> { | 7 | pub fn extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange> { |
9 | let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; | 8 | let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; |
10 | if range.is_empty() { | 9 | if range.is_empty() { |
11 | let offset = range.start(); | 10 | let offset = range.start(); |
@@ -40,7 +39,7 @@ pub fn extend_selection(root: SyntaxNodeRef, range: TextRange) -> Option<TextRan | |||
40 | } | 39 | } |
41 | 40 | ||
42 | fn extend_single_word_in_comment_or_string( | 41 | fn extend_single_word_in_comment_or_string( |
43 | leaf: SyntaxNodeRef, | 42 | leaf: &SyntaxNode, |
44 | offset: TextUnit, | 43 | offset: TextUnit, |
45 | ) -> Option<TextRange> { | 44 | ) -> Option<TextRange> { |
46 | let text: &str = leaf.leaf_text()?; | 45 | let text: &str = leaf.leaf_text()?; |
@@ -66,7 +65,7 @@ fn extend_single_word_in_comment_or_string( | |||
66 | } | 65 | } |
67 | } | 66 | } |
68 | 67 | ||
69 | fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { | 68 | fn extend_ws(root: &SyntaxNode, ws: &SyntaxNode, offset: TextUnit) -> TextRange { |
70 | let ws_text = ws.leaf_text().unwrap(); | 69 | let ws_text = ws.leaf_text().unwrap(); |
71 | let suffix = TextRange::from_to(offset, ws.range().end()) - ws.range().start(); | 70 | let suffix = TextRange::from_to(offset, ws.range().end()) - ws.range().start(); |
72 | let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start(); | 71 | let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start(); |
@@ -89,9 +88,9 @@ fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRa | |||
89 | ws.range() | 88 | ws.range() |
90 | } | 89 | } |
91 | 90 | ||
92 | fn pick_best<'a>(l: SyntaxNodeRef<'a>, r: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> { | 91 | fn pick_best<'a>(l: &'a SyntaxNode, r: &'a SyntaxNode) -> &'a SyntaxNode { |
93 | return if priority(r) > priority(l) { r } else { l }; | 92 | return if priority(r) > priority(l) { r } else { l }; |
94 | fn priority(n: SyntaxNodeRef) -> usize { | 93 | fn priority(n: &SyntaxNode) -> usize { |
95 | match n.kind() { | 94 | match n.kind() { |
96 | WHITESPACE => 0, | 95 | WHITESPACE => 0, |
97 | IDENT | SELF_KW | SUPER_KW | CRATE_KW | LIFETIME => 2, | 96 | IDENT | SELF_KW | SUPER_KW | CRATE_KW | LIFETIME => 2, |
@@ -100,7 +99,7 @@ fn pick_best<'a>(l: SyntaxNodeRef<'a>, r: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a | |||
100 | } | 99 | } |
101 | } | 100 | } |
102 | 101 | ||
103 | fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> { | 102 | fn extend_comments(node: &SyntaxNode) -> Option<TextRange> { |
104 | let prev = adj_comments(node, Direction::Prev); | 103 | let prev = adj_comments(node, Direction::Prev); |
105 | let next = adj_comments(node, Direction::Next); | 104 | let next = adj_comments(node, Direction::Next); |
106 | if prev != next { | 105 | if prev != next { |
@@ -110,7 +109,7 @@ fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> { | |||
110 | } | 109 | } |
111 | } | 110 | } |
112 | 111 | ||
113 | fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef { | 112 | fn adj_comments(node: &SyntaxNode, dir: Direction) -> &SyntaxNode { |
114 | let mut res = node; | 113 | let mut res = node; |
115 | for node in node.siblings(dir) { | 114 | for node in node.siblings(dir) { |
116 | match node.kind() { | 115 | match node.kind() { |
@@ -124,13 +123,14 @@ fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef { | |||
124 | 123 | ||
125 | #[cfg(test)] | 124 | #[cfg(test)] |
126 | mod tests { | 125 | mod tests { |
127 | use super::*; | 126 | use ra_syntax::{SourceFile, AstNode}; |
128 | use ra_syntax::SourceFileNode; | ||
129 | use test_utils::extract_offset; | 127 | use test_utils::extract_offset; |
130 | 128 | ||
129 | use super::*; | ||
130 | |||
131 | fn do_check(before: &str, afters: &[&str]) { | 131 | fn do_check(before: &str, afters: &[&str]) { |
132 | let (cursor, before) = extract_offset(before); | 132 | let (cursor, before) = extract_offset(before); |
133 | let file = SourceFileNode::parse(&before); | 133 | let file = SourceFile::parse(&before); |
134 | let mut range = TextRange::offset_len(cursor, 0.into()); | 134 | let mut range = TextRange::offset_len(cursor, 0.into()); |
135 | for &after in afters { | 135 | for &after in afters { |
136 | range = extend_selection(file.syntax(), range).unwrap(); | 136 | range = extend_selection(file.syntax(), range).unwrap(); |
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index da542ecf0..6f3106889 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | ast, AstNode, Direction, SourceFileNode, | 4 | ast, AstNode, Direction, SourceFile, SyntaxNode, TextRange, |
5 | SyntaxKind::{self, *}, | 5 | SyntaxKind::{self, *}, |
6 | SyntaxNodeRef, TextRange, | ||
7 | }; | 6 | }; |
8 | 7 | ||
9 | #[derive(Debug, PartialEq, Eq)] | 8 | #[derive(Debug, PartialEq, Eq)] |
@@ -19,7 +18,7 @@ pub struct Fold { | |||
19 | pub kind: FoldKind, | 18 | pub kind: FoldKind, |
20 | } | 19 | } |
21 | 20 | ||
22 | pub fn folding_ranges(file: &SourceFileNode) -> Vec<Fold> { | 21 | pub fn folding_ranges(file: &SourceFile) -> Vec<Fold> { |
23 | let mut res = vec![]; | 22 | let mut res = vec![]; |
24 | let mut visited_comments = FxHashSet::default(); | 23 | let mut visited_comments = FxHashSet::default(); |
25 | let mut visited_imports = FxHashSet::default(); | 24 | let mut visited_imports = FxHashSet::default(); |
@@ -69,7 +68,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> { | |||
69 | } | 68 | } |
70 | } | 69 | } |
71 | 70 | ||
72 | fn has_newline(node: SyntaxNodeRef) -> bool { | 71 | fn has_newline(node: &SyntaxNode) -> bool { |
73 | for descendant in node.descendants() { | 72 | for descendant in node.descendants() { |
74 | if let Some(ws) = ast::Whitespace::cast(descendant) { | 73 | if let Some(ws) = ast::Whitespace::cast(descendant) { |
75 | if ws.has_newlines() { | 74 | if ws.has_newlines() { |
@@ -86,8 +85,8 @@ fn has_newline(node: SyntaxNodeRef) -> bool { | |||
86 | } | 85 | } |
87 | 86 | ||
88 | fn contiguous_range_for_group<'a>( | 87 | fn contiguous_range_for_group<'a>( |
89 | first: SyntaxNodeRef<'a>, | 88 | first: &'a SyntaxNode, |
90 | visited: &mut FxHashSet<SyntaxNodeRef<'a>>, | 89 | visited: &mut FxHashSet<&'a SyntaxNode>, |
91 | ) -> Option<TextRange> { | 90 | ) -> Option<TextRange> { |
92 | visited.insert(first); | 91 | visited.insert(first); |
93 | 92 | ||
@@ -124,8 +123,8 @@ fn contiguous_range_for_group<'a>( | |||
124 | } | 123 | } |
125 | 124 | ||
126 | fn contiguous_range_for_comment<'a>( | 125 | fn contiguous_range_for_comment<'a>( |
127 | first: SyntaxNodeRef<'a>, | 126 | first: &'a SyntaxNode, |
128 | visited: &mut FxHashSet<SyntaxNodeRef<'a>>, | 127 | visited: &mut FxHashSet<&'a SyntaxNode>, |
129 | ) -> Option<TextRange> { | 128 | ) -> Option<TextRange> { |
130 | visited.insert(first); | 129 | visited.insert(first); |
131 | 130 | ||
@@ -174,7 +173,7 @@ mod tests { | |||
174 | 173 | ||
175 | fn do_check(text: &str, fold_kinds: &[FoldKind]) { | 174 | fn do_check(text: &str, fold_kinds: &[FoldKind]) { |
176 | let (ranges, text) = extract_ranges(text, "fold"); | 175 | let (ranges, text) = extract_ranges(text, "fold"); |
177 | let file = SourceFileNode::parse(&text); | 176 | let file = SourceFile::parse(&text); |
178 | let folds = folding_ranges(&file); | 177 | let folds = folding_ranges(&file); |
179 | 178 | ||
180 | assert_eq!( | 179 | assert_eq!( |
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index a3c85ed5d..6731260a3 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs | |||
@@ -21,11 +21,10 @@ pub use self::{ | |||
21 | }; | 21 | }; |
22 | use ra_text_edit::TextEditBuilder; | 22 | use ra_text_edit::TextEditBuilder; |
23 | use ra_syntax::{ | 23 | use ra_syntax::{ |
24 | algo::find_leaf_at_offset, | 24 | SourceFile, SyntaxNode, TextRange, TextUnit, Direction, |
25 | ast::{self, AstNode}, | ||
26 | SourceFileNode, | ||
27 | SyntaxKind::{self, *}, | 25 | SyntaxKind::{self, *}, |
28 | SyntaxNodeRef, TextRange, TextUnit, Direction, | 26 | ast::{self, AstNode}, |
27 | algo::find_leaf_at_offset, | ||
29 | }; | 28 | }; |
30 | use rustc_hash::FxHashSet; | 29 | use rustc_hash::FxHashSet; |
31 | 30 | ||
@@ -49,7 +48,7 @@ pub struct Diagnostic { | |||
49 | pub fix: Option<LocalEdit>, | 48 | pub fix: Option<LocalEdit>, |
50 | } | 49 | } |
51 | 50 | ||
52 | pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { | 51 | pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { |
53 | const BRACES: &[SyntaxKind] = &[ | 52 | const BRACES: &[SyntaxKind] = &[ |
54 | L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE, | 53 | L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE, |
55 | ]; | 54 | ]; |
@@ -67,7 +66,7 @@ pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUni | |||
67 | Some(matching_node.range().start()) | 66 | Some(matching_node.range().start()) |
68 | } | 67 | } |
69 | 68 | ||
70 | pub fn highlight(root: SyntaxNodeRef) -> Vec<HighlightedRange> { | 69 | pub fn highlight(root: &SyntaxNode) -> Vec<HighlightedRange> { |
71 | // Visited nodes to handle highlighting priorities | 70 | // Visited nodes to handle highlighting priorities |
72 | let mut highlighted = FxHashSet::default(); | 71 | let mut highlighted = FxHashSet::default(); |
73 | let mut res = Vec::new(); | 72 | let mut res = Vec::new(); |
@@ -117,26 +116,25 @@ pub fn highlight(root: SyntaxNodeRef) -> Vec<HighlightedRange> { | |||
117 | res | 116 | res |
118 | } | 117 | } |
119 | 118 | ||
120 | pub fn syntax_tree(file: &SourceFileNode) -> String { | 119 | pub fn syntax_tree(file: &SourceFile) -> String { |
121 | ::ra_syntax::utils::dump_tree(file.syntax()) | 120 | ::ra_syntax::utils::dump_tree(file.syntax()) |
122 | } | 121 | } |
123 | 122 | ||
124 | pub fn find_node_at_offset<'a, N: AstNode<'a>>( | 123 | pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> { |
125 | syntax: SyntaxNodeRef<'a>, | ||
126 | offset: TextUnit, | ||
127 | ) -> Option<N> { | ||
128 | find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast)) | 124 | find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast)) |
129 | } | 125 | } |
130 | 126 | ||
131 | #[cfg(test)] | 127 | #[cfg(test)] |
132 | mod tests { | 128 | mod tests { |
129 | use ra_syntax::AstNode; | ||
130 | |||
133 | use crate::test_utils::{add_cursor, assert_eq_dbg, assert_eq_text, extract_offset}; | 131 | use crate::test_utils::{add_cursor, assert_eq_dbg, assert_eq_text, extract_offset}; |
134 | 132 | ||
135 | use super::*; | 133 | use super::*; |
136 | 134 | ||
137 | #[test] | 135 | #[test] |
138 | fn test_highlighting() { | 136 | fn test_highlighting() { |
139 | let file = SourceFileNode::parse( | 137 | let file = SourceFile::parse( |
140 | r#" | 138 | r#" |
141 | // comment | 139 | // comment |
142 | fn main() {} | 140 | fn main() {} |
@@ -159,7 +157,7 @@ fn main() {} | |||
159 | fn test_matching_brace() { | 157 | fn test_matching_brace() { |
160 | fn do_check(before: &str, after: &str) { | 158 | fn do_check(before: &str, after: &str) { |
161 | let (pos, before) = extract_offset(before); | 159 | let (pos, before) = extract_offset(before); |
162 | let file = SourceFileNode::parse(&before); | 160 | let file = SourceFile::parse(&before); |
163 | let new_pos = match matching_brace(&file, pos) { | 161 | let new_pos = match matching_brace(&file, pos) { |
164 | None => pos, | 162 | None => pos, |
165 | Some(pos) => pos, | 163 | Some(pos) => pos, |
diff --git a/crates/ra_editor/src/structure.rs b/crates/ra_editor/src/structure.rs index 32d59e335..8bd57555f 100644 --- a/crates/ra_editor/src/structure.rs +++ b/crates/ra_editor/src/structure.rs | |||
@@ -3,7 +3,7 @@ use crate::TextRange; | |||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::visit::{visitor, Visitor}, | 4 | algo::visit::{visitor, Visitor}, |
5 | ast::{self, NameOwner}, | 5 | ast::{self, NameOwner}, |
6 | AstNode, SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent, | 6 | AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | #[derive(Debug, Clone)] | 9 | #[derive(Debug, Clone)] |
@@ -15,7 +15,7 @@ pub struct StructureNode { | |||
15 | pub kind: SyntaxKind, | 15 | pub kind: SyntaxKind, |
16 | } | 16 | } |
17 | 17 | ||
18 | pub fn file_structure(file: &SourceFileNode) -> Vec<StructureNode> { | 18 | pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> { |
19 | let mut res = Vec::new(); | 19 | let mut res = Vec::new(); |
20 | let mut stack = Vec::new(); | 20 | let mut stack = Vec::new(); |
21 | 21 | ||
@@ -38,8 +38,8 @@ pub fn file_structure(file: &SourceFileNode) -> Vec<StructureNode> { | |||
38 | res | 38 | res |
39 | } | 39 | } |
40 | 40 | ||
41 | fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> { | 41 | fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { |
42 | fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<StructureNode> { | 42 | fn decl<N: NameOwner>(node: &N) -> Option<StructureNode> { |
43 | let name = node.name()?; | 43 | let name = node.name()?; |
44 | Some(StructureNode { | 44 | Some(StructureNode { |
45 | parent: None, | 45 | parent: None, |
@@ -60,7 +60,7 @@ fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> { | |||
60 | .visit(decl::<ast::TypeDef>) | 60 | .visit(decl::<ast::TypeDef>) |
61 | .visit(decl::<ast::ConstDef>) | 61 | .visit(decl::<ast::ConstDef>) |
62 | .visit(decl::<ast::StaticDef>) | 62 | .visit(decl::<ast::StaticDef>) |
63 | .visit(|im: ast::ImplBlock| { | 63 | .visit(|im: &ast::ImplBlock| { |
64 | let target_type = im.target_type()?; | 64 | let target_type = im.target_type()?; |
65 | let target_trait = im.target_trait(); | 65 | let target_trait = im.target_trait(); |
66 | let label = match target_trait { | 66 | let label = match target_trait { |
@@ -91,7 +91,7 @@ mod tests { | |||
91 | 91 | ||
92 | #[test] | 92 | #[test] |
93 | fn test_file_structure() { | 93 | fn test_file_structure() { |
94 | let file = SourceFileNode::parse( | 94 | let file = SourceFile::parse( |
95 | r#" | 95 | r#" |
96 | struct Foo { | 96 | struct Foo { |
97 | x: i32 | 97 | x: i32 |
diff --git a/crates/ra_editor/src/test_utils.rs b/crates/ra_editor/src/test_utils.rs index f0a4f250a..bf40c92c0 100644 --- a/crates/ra_editor/src/test_utils.rs +++ b/crates/ra_editor/src/test_utils.rs | |||
@@ -1,15 +1,15 @@ | |||
1 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; | 1 | use ra_syntax::{SourceFile, TextRange, TextUnit}; |
2 | 2 | ||
3 | use crate::LocalEdit; | 3 | use crate::LocalEdit; |
4 | pub use test_utils::*; | 4 | pub use test_utils::*; |
5 | 5 | ||
6 | pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>( | 6 | pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>( |
7 | before: &str, | 7 | before: &str, |
8 | after: &str, | 8 | after: &str, |
9 | f: F, | 9 | f: F, |
10 | ) { | 10 | ) { |
11 | let (before_cursor_pos, before) = extract_offset(before); | 11 | let (before_cursor_pos, before) = extract_offset(before); |
12 | let file = SourceFileNode::parse(&before); | 12 | let file = SourceFile::parse(&before); |
13 | let result = f(&file, before_cursor_pos).expect("code action is not applicable"); | 13 | let result = f(&file, before_cursor_pos).expect("code action is not applicable"); |
14 | let actual = result.edit.apply(&before); | 14 | let actual = result.edit.apply(&before); |
15 | let actual_cursor_pos = match result.cursor_position { | 15 | let actual_cursor_pos = match result.cursor_position { |
@@ -20,13 +20,13 @@ pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>( | |||
20 | assert_eq_text!(after, &actual); | 20 | assert_eq_text!(after, &actual); |
21 | } | 21 | } |
22 | 22 | ||
23 | pub fn check_action_range<F: Fn(&SourceFileNode, TextRange) -> Option<LocalEdit>>( | 23 | pub fn check_action_range<F: Fn(&SourceFile, TextRange) -> Option<LocalEdit>>( |
24 | before: &str, | 24 | before: &str, |
25 | after: &str, | 25 | after: &str, |
26 | f: F, | 26 | f: F, |
27 | ) { | 27 | ) { |
28 | let (range, before) = extract_range(before); | 28 | let (range, before) = extract_range(before); |
29 | let file = SourceFileNode::parse(&before); | 29 | let file = SourceFile::parse(&before); |
30 | let result = f(&file, range).expect("code action is not applicable"); | 30 | let result = f(&file, range).expect("code action is not applicable"); |
31 | let actual = result.edit.apply(&before); | 31 | let actual = result.edit.apply(&before); |
32 | let actual_cursor_pos = match result.cursor_position { | 32 | let actual_cursor_pos = match result.cursor_position { |
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 12500854c..5b260d2ac 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs | |||
@@ -5,15 +5,15 @@ use ra_syntax::{ | |||
5 | algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, | 5 | algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, |
6 | ast, | 6 | ast, |
7 | text_utils::intersect, | 7 | text_utils::intersect, |
8 | AstNode, Direction, SourceFileNode, SyntaxKind, | 8 | AstNode, Direction, SourceFile, SyntaxKind, |
9 | SyntaxKind::*, | 9 | SyntaxKind::*, |
10 | SyntaxNodeRef, TextRange, TextUnit, | 10 | SyntaxNode, TextRange, TextUnit, |
11 | }; | 11 | }; |
12 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 12 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
13 | 13 | ||
14 | use crate::{find_node_at_offset, LocalEdit, TextEditBuilder}; | 14 | use crate::{find_node_at_offset, LocalEdit, TextEditBuilder}; |
15 | 15 | ||
16 | pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { | 16 | pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { |
17 | let range = if range.is_empty() { | 17 | let range = if range.is_empty() { |
18 | let syntax = file.syntax(); | 18 | let syntax = file.syntax(); |
19 | let text = syntax.text().slice(range.start()..); | 19 | let text = syntax.text().slice(range.start()..); |
@@ -59,7 +59,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { | |||
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | 62 | pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { |
63 | let comment = find_leaf_at_offset(file.syntax(), offset) | 63 | let comment = find_leaf_at_offset(file.syntax(), offset) |
64 | .left_biased() | 64 | .left_biased() |
65 | .and_then(ast::Comment::cast)?; | 65 | .and_then(ast::Comment::cast)?; |
@@ -85,7 +85,7 @@ pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | |||
85 | }) | 85 | }) |
86 | } | 86 | } |
87 | 87 | ||
88 | fn node_indent<'a>(file: &'a SourceFileNode, node: SyntaxNodeRef) -> Option<&'a str> { | 88 | fn node_indent<'a>(file: &'a SourceFile, node: &SyntaxNode) -> Option<&'a str> { |
89 | let ws = match find_leaf_at_offset(file.syntax(), node.range().start()) { | 89 | let ws = match find_leaf_at_offset(file.syntax(), node.range().start()) { |
90 | LeafAtOffset::Between(l, r) => { | 90 | LeafAtOffset::Between(l, r) => { |
91 | assert!(r == node); | 91 | assert!(r == node); |
@@ -105,8 +105,8 @@ fn node_indent<'a>(file: &'a SourceFileNode, node: SyntaxNodeRef) -> Option<&'a | |||
105 | Some(&text[pos..]) | 105 | Some(&text[pos..]) |
106 | } | 106 | } |
107 | 107 | ||
108 | pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | 108 | pub fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { |
109 | let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; | 109 | let let_stmt: &ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; |
110 | if let_stmt.has_semi() { | 110 | if let_stmt.has_semi() { |
111 | return None; | 111 | return None; |
112 | } | 112 | } |
@@ -136,7 +136,7 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> | |||
136 | }) | 136 | }) |
137 | } | 137 | } |
138 | 138 | ||
139 | pub fn on_dot_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | 139 | pub fn on_dot_typed(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { |
140 | let before_dot_offset = offset - TextUnit::of_char('.'); | 140 | let before_dot_offset = offset - TextUnit::of_char('.'); |
141 | 141 | ||
142 | let whitespace = find_leaf_at_offset(file.syntax(), before_dot_offset).left_biased()?; | 142 | let whitespace = find_leaf_at_offset(file.syntax(), before_dot_offset).left_biased()?; |
@@ -151,7 +151,7 @@ pub fn on_dot_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit | |||
151 | .skip(1) | 151 | .skip(1) |
152 | .next()?; | 152 | .next()?; |
153 | 153 | ||
154 | ast::MethodCallExprNode::cast(method_call)?; | 154 | ast::MethodCallExpr::cast(method_call)?; |
155 | 155 | ||
156 | // find how much the _method call is indented | 156 | // find how much the _method call is indented |
157 | let method_chain_indent = method_call | 157 | let method_chain_indent = method_call |
@@ -188,7 +188,7 @@ fn last_line_indent_in_whitespace(ws: &str) -> &str { | |||
188 | 188 | ||
189 | fn remove_newline( | 189 | fn remove_newline( |
190 | edit: &mut TextEditBuilder, | 190 | edit: &mut TextEditBuilder, |
191 | node: SyntaxNodeRef, | 191 | node: &SyntaxNode, |
192 | node_text: &str, | 192 | node_text: &str, |
193 | offset: TextUnit, | 193 | offset: TextUnit, |
194 | ) { | 194 | ) { |
@@ -266,7 +266,7 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { | |||
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | fn join_single_expr_block(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { | 269 | fn join_single_expr_block(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Option<()> { |
270 | let block = ast::Block::cast(node.parent()?)?; | 270 | let block = ast::Block::cast(node.parent()?)?; |
271 | let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; | 271 | let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; |
272 | let expr = single_expr(block)?; | 272 | let expr = single_expr(block)?; |
@@ -277,7 +277,7 @@ fn join_single_expr_block(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Op | |||
277 | Some(()) | 277 | Some(()) |
278 | } | 278 | } |
279 | 279 | ||
280 | fn single_expr(block: ast::Block) -> Option<ast::Expr> { | 280 | fn single_expr(block: &ast::Block) -> Option<&ast::Expr> { |
281 | let mut res = None; | 281 | let mut res = None; |
282 | for child in block.syntax().children() { | 282 | for child in block.syntax().children() { |
283 | if let Some(expr) = ast::Expr::cast(child) { | 283 | if let Some(expr) = ast::Expr::cast(child) { |
@@ -297,7 +297,7 @@ fn single_expr(block: ast::Block) -> Option<ast::Expr> { | |||
297 | res | 297 | res |
298 | } | 298 | } |
299 | 299 | ||
300 | fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { | 300 | fn join_single_use_tree(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Option<()> { |
301 | let use_tree_list = ast::UseTreeList::cast(node.parent()?)?; | 301 | let use_tree_list = ast::UseTreeList::cast(node.parent()?)?; |
302 | let (tree,) = use_tree_list.use_trees().collect_tuple()?; | 302 | let (tree,) = use_tree_list.use_trees().collect_tuple()?; |
303 | edit.replace( | 303 | edit.replace( |
@@ -307,7 +307,7 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Opti | |||
307 | Some(()) | 307 | Some(()) |
308 | } | 308 | } |
309 | 309 | ||
310 | fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { | 310 | fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str { |
311 | match left.kind() { | 311 | match left.kind() { |
312 | L_PAREN | L_BRACK => return "", | 312 | L_PAREN | L_BRACK => return "", |
313 | L_CURLY => { | 313 | L_CURLY => { |
@@ -547,7 +547,7 @@ fn foo() { | |||
547 | 547 | ||
548 | fn check_join_lines_sel(before: &str, after: &str) { | 548 | fn check_join_lines_sel(before: &str, after: &str) { |
549 | let (sel, before) = extract_range(before); | 549 | let (sel, before) = extract_range(before); |
550 | let file = SourceFileNode::parse(&before); | 550 | let file = SourceFile::parse(&before); |
551 | let result = join_lines(&file, sel); | 551 | let result = join_lines(&file, sel); |
552 | let actual = result.edit.apply(&before); | 552 | let actual = result.edit.apply(&before); |
553 | assert_eq_text!(after, &actual); | 553 | assert_eq_text!(after, &actual); |
@@ -626,7 +626,7 @@ pub fn handle_find_matching_brace() { | |||
626 | fn test_on_eq_typed() { | 626 | fn test_on_eq_typed() { |
627 | fn do_check(before: &str, after: &str) { | 627 | fn do_check(before: &str, after: &str) { |
628 | let (offset, before) = extract_offset(before); | 628 | let (offset, before) = extract_offset(before); |
629 | let file = SourceFileNode::parse(&before); | 629 | let file = SourceFile::parse(&before); |
630 | let result = on_eq_typed(&file, offset).unwrap(); | 630 | let result = on_eq_typed(&file, offset).unwrap(); |
631 | let actual = result.edit.apply(&before); | 631 | let actual = result.edit.apply(&before); |
632 | assert_eq_text!(after, &actual); | 632 | assert_eq_text!(after, &actual); |
@@ -670,7 +670,7 @@ fn foo() { | |||
670 | fn test_on_dot_typed() { | 670 | fn test_on_dot_typed() { |
671 | fn do_check(before: &str, after: &str) { | 671 | fn do_check(before: &str, after: &str) { |
672 | let (offset, before) = extract_offset(before); | 672 | let (offset, before) = extract_offset(before); |
673 | let file = SourceFileNode::parse(&before); | 673 | let file = SourceFile::parse(&before); |
674 | if let Some(result) = on_eq_typed(&file, offset) { | 674 | if let Some(result) = on_eq_typed(&file, offset) { |
675 | let actual = result.edit.apply(&before); | 675 | let actual = result.edit.apply(&before); |
676 | assert_eq_text!(after, &actual); | 676 | assert_eq_text!(after, &actual); |
@@ -779,7 +779,7 @@ fn foo() { | |||
779 | fn test_on_enter() { | 779 | fn test_on_enter() { |
780 | fn apply_on_enter(before: &str) -> Option<String> { | 780 | fn apply_on_enter(before: &str) -> Option<String> { |
781 | let (offset, before) = extract_offset(before); | 781 | let (offset, before) = extract_offset(before); |
782 | let file = SourceFileNode::parse(&before); | 782 | let file = SourceFile::parse(&before); |
783 | let result = on_enter(&file, offset)?; | 783 | let result = on_enter(&file, offset)?; |
784 | let actual = result.edit.apply(&before); | 784 | let actual = result.edit.apply(&before); |
785 | let actual = add_cursor(&actual, result.cursor_position.unwrap()); | 785 | let actual = add_cursor(&actual, result.cursor_position.unwrap()); |
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index c6463235c..b700be267 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -42,7 +42,7 @@ pub struct StructData { | |||
42 | } | 42 | } |
43 | 43 | ||
44 | impl StructData { | 44 | impl StructData { |
45 | pub(crate) fn new(struct_def: ast::StructDef) -> StructData { | 45 | pub(crate) fn new(struct_def: &ast::StructDef) -> StructData { |
46 | let name = struct_def.name().map(|n| n.as_name()); | 46 | let name = struct_def.name().map(|n| n.as_name()); |
47 | let variant_data = VariantData::new(struct_def.flavor()); | 47 | let variant_data = VariantData::new(struct_def.flavor()); |
48 | let variant_data = Arc::new(variant_data); | 48 | let variant_data = Arc::new(variant_data); |
@@ -87,7 +87,7 @@ pub struct EnumData { | |||
87 | } | 87 | } |
88 | 88 | ||
89 | impl EnumData { | 89 | impl EnumData { |
90 | pub(crate) fn new(enum_def: ast::EnumDef) -> Self { | 90 | pub(crate) fn new(enum_def: &ast::EnumDef) -> Self { |
91 | let name = enum_def.name().map(|n| n.as_name()); | 91 | let name = enum_def.name().map(|n| n.as_name()); |
92 | let variants = if let Some(evl) = enum_def.variant_list() { | 92 | let variants = if let Some(evl) = enum_def.variant_list() { |
93 | evl.variants() | 93 | evl.variants() |
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 09b532f74..43cddb504 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use relative_path::RelativePathBuf; | 1 | use relative_path::RelativePathBuf; |
2 | use ra_db::{CrateId, Cancelable, FileId}; | 2 | use ra_db::{CrateId, Cancelable, FileId}; |
3 | use ra_syntax::{ast, SyntaxNode}; | 3 | use ra_syntax::{ast, TreePtr, SyntaxNode}; |
4 | 4 | ||
5 | use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope}; | 5 | use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope}; |
6 | 6 | ||
@@ -36,8 +36,8 @@ pub struct Module { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | pub enum ModuleSource { | 38 | pub enum ModuleSource { |
39 | SourceFile(ast::SourceFileNode), | 39 | SourceFile(TreePtr<ast::SourceFile>), |
40 | Module(ast::ModuleNode), | 40 | Module(TreePtr<ast::Module>), |
41 | } | 41 | } |
42 | 42 | ||
43 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] | 43 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] |
@@ -66,7 +66,7 @@ impl Module { | |||
66 | pub fn declaration_source( | 66 | pub fn declaration_source( |
67 | &self, | 67 | &self, |
68 | db: &impl HirDatabase, | 68 | db: &impl HirDatabase, |
69 | ) -> Cancelable<Option<(FileId, ast::ModuleNode)>> { | 69 | ) -> Cancelable<Option<(FileId, TreePtr<ast::Module>)>> { |
70 | self.declaration_source_impl(db) | 70 | self.declaration_source_impl(db) |
71 | } | 71 | } |
72 | 72 | ||
@@ -104,7 +104,10 @@ impl Module { | |||
104 | pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable<PerNs<DefId>> { | 104 | pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable<PerNs<DefId>> { |
105 | self.resolve_path_impl(db, path) | 105 | self.resolve_path_impl(db, path) |
106 | } | 106 | } |
107 | pub fn problems(&self, db: &impl HirDatabase) -> Cancelable<Vec<(SyntaxNode, Problem)>> { | 107 | pub fn problems( |
108 | &self, | ||
109 | db: &impl HirDatabase, | ||
110 | ) -> Cancelable<Vec<(TreePtr<SyntaxNode>, Problem)>> { | ||
108 | self.problems_impl(db) | 111 | self.problems_impl(db) |
109 | } | 112 | } |
110 | } | 113 | } |
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index eb35779f1..0d22c9dbe 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use ra_db::{Cancelable, SourceRootId, FileId}; | 1 | use ra_db::{Cancelable, SourceRootId, FileId}; |
2 | use ra_syntax::{ast, SyntaxNode, AstNode}; | 2 | use ra_syntax::{ast, SyntaxNode, AstNode, TreePtr}; |
3 | 3 | ||
4 | use crate::{ | 4 | use crate::{ |
5 | Module, ModuleSource, Problem, | 5 | Module, ModuleSource, Problem, |
@@ -43,12 +43,11 @@ impl Module { | |||
43 | let loc = self.def_id.loc(db); | 43 | let loc = self.def_id.loc(db); |
44 | let file_id = loc.source_item_id.file_id.as_original_file(); | 44 | let file_id = loc.source_item_id.file_id.as_original_file(); |
45 | let syntax_node = db.file_item(loc.source_item_id); | 45 | let syntax_node = db.file_item(loc.source_item_id); |
46 | let syntax_node = syntax_node.borrowed(); | 46 | let module_source = if let Some(source_file) = ast::SourceFile::cast(&syntax_node) { |
47 | let module_source = if let Some(source_file) = ast::SourceFile::cast(syntax_node) { | 47 | ModuleSource::SourceFile(source_file.to_owned()) |
48 | ModuleSource::SourceFile(source_file.owned()) | ||
49 | } else { | 48 | } else { |
50 | let module = ast::Module::cast(syntax_node).unwrap(); | 49 | let module = ast::Module::cast(&syntax_node).unwrap(); |
51 | ModuleSource::Module(module.owned()) | 50 | ModuleSource::Module(module.to_owned()) |
52 | }; | 51 | }; |
53 | Ok((file_id, module_source)) | 52 | Ok((file_id, module_source)) |
54 | } | 53 | } |
@@ -56,7 +55,7 @@ impl Module { | |||
56 | pub fn declaration_source_impl( | 55 | pub fn declaration_source_impl( |
57 | &self, | 56 | &self, |
58 | db: &impl HirDatabase, | 57 | db: &impl HirDatabase, |
59 | ) -> Cancelable<Option<(FileId, ast::ModuleNode)>> { | 58 | ) -> Cancelable<Option<(FileId, TreePtr<ast::Module>)>> { |
60 | let loc = self.def_id.loc(db); | 59 | let loc = self.def_id.loc(db); |
61 | let module_tree = db.module_tree(loc.source_root_id)?; | 60 | let module_tree = db.module_tree(loc.source_root_id)?; |
62 | let link = ctry!(loc.module_id.parent_link(&module_tree)); | 61 | let link = ctry!(loc.module_id.parent_link(&module_tree)); |
@@ -146,7 +145,10 @@ impl Module { | |||
146 | } | 145 | } |
147 | Ok(curr_per_ns) | 146 | Ok(curr_per_ns) |
148 | } | 147 | } |
149 | pub fn problems_impl(&self, db: &impl HirDatabase) -> Cancelable<Vec<(SyntaxNode, Problem)>> { | 148 | pub fn problems_impl( |
149 | &self, | ||
150 | db: &impl HirDatabase, | ||
151 | ) -> Cancelable<Vec<(TreePtr<SyntaxNode>, Problem)>> { | ||
150 | let loc = self.def_id.loc(db); | 152 | let loc = self.def_id.loc(db); |
151 | let module_tree = db.module_tree(loc.source_root_id)?; | 153 | let module_tree = db.module_tree(loc.source_root_id)?; |
152 | Ok(loc.module_id.problems(&module_tree, db)) | 154 | Ok(loc.module_id.problems(&module_tree, db)) |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 04249400b..03e65387d 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_syntax::{SyntaxNode, SourceFileNode}; | 3 | use ra_syntax::{SyntaxNode, TreePtr, SourceFile}; |
4 | use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, Cancelable}; | 4 | use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, Cancelable}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
@@ -22,7 +22,7 @@ pub trait HirDatabase: SyntaxDatabase | |||
22 | + AsRef<LocationIntener<DefLoc, DefId>> | 22 | + AsRef<LocationIntener<DefLoc, DefId>> |
23 | + AsRef<LocationIntener<MacroCallLoc, MacroCallId>> | 23 | + AsRef<LocationIntener<MacroCallLoc, MacroCallId>> |
24 | { | 24 | { |
25 | fn hir_source_file(file_id: HirFileId) -> SourceFileNode { | 25 | fn hir_source_file(file_id: HirFileId) -> TreePtr<SourceFile> { |
26 | type HirSourceFileQuery; | 26 | type HirSourceFileQuery; |
27 | use fn HirFileId::hir_source_file; | 27 | use fn HirFileId::hir_source_file; |
28 | } | 28 | } |
@@ -66,7 +66,7 @@ pub trait HirDatabase: SyntaxDatabase | |||
66 | use fn query_definitions::file_items; | 66 | use fn query_definitions::file_items; |
67 | } | 67 | } |
68 | 68 | ||
69 | fn file_item(source_item_id: SourceItemId) -> SyntaxNode { | 69 | fn file_item(source_item_id: SourceItemId) -> TreePtr<SyntaxNode> { |
70 | type FileItemQuery; | 70 | type FileItemQuery; |
71 | use fn query_definitions::file_item; | 71 | use fn query_definitions::file_item; |
72 | } | 72 | } |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index b0063cad2..4c54449ef 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -77,7 +77,7 @@ impl BodySyntaxMapping { | |||
77 | pub fn syntax_expr(&self, ptr: LocalSyntaxPtr) -> Option<ExprId> { | 77 | pub fn syntax_expr(&self, ptr: LocalSyntaxPtr) -> Option<ExprId> { |
78 | self.expr_syntax_mapping.get(&ptr).cloned() | 78 | self.expr_syntax_mapping.get(&ptr).cloned() |
79 | } | 79 | } |
80 | pub fn node_expr(&self, node: ast::Expr) -> Option<ExprId> { | 80 | pub fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> { |
81 | self.expr_syntax_mapping | 81 | self.expr_syntax_mapping |
82 | .get(&LocalSyntaxPtr::new(node.syntax())) | 82 | .get(&LocalSyntaxPtr::new(node.syntax())) |
83 | .cloned() | 83 | .cloned() |
@@ -88,7 +88,7 @@ impl BodySyntaxMapping { | |||
88 | pub fn syntax_pat(&self, ptr: LocalSyntaxPtr) -> Option<PatId> { | 88 | pub fn syntax_pat(&self, ptr: LocalSyntaxPtr) -> Option<PatId> { |
89 | self.pat_syntax_mapping.get(&ptr).cloned() | 89 | self.pat_syntax_mapping.get(&ptr).cloned() |
90 | } | 90 | } |
91 | pub fn node_pat(&self, node: ast::Pat) -> Option<PatId> { | 91 | pub fn node_pat(&self, node: &ast::Pat) -> Option<PatId> { |
92 | self.pat_syntax_mapping | 92 | self.pat_syntax_mapping |
93 | .get(&LocalSyntaxPtr::new(node.syntax())) | 93 | .get(&LocalSyntaxPtr::new(node.syntax())) |
94 | .cloned() | 94 | .cloned() |
@@ -373,10 +373,10 @@ impl ExprCollector { | |||
373 | self.exprs.alloc(block) | 373 | self.exprs.alloc(block) |
374 | } | 374 | } |
375 | 375 | ||
376 | fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { | 376 | fn collect_expr(&mut self, expr: &ast::Expr) -> ExprId { |
377 | let syntax_ptr = LocalSyntaxPtr::new(expr.syntax()); | 377 | let syntax_ptr = LocalSyntaxPtr::new(expr.syntax()); |
378 | match expr { | 378 | match expr.kind() { |
379 | ast::Expr::IfExpr(e) => { | 379 | ast::ExprKind::IfExpr(e) => { |
380 | if let Some(pat) = e.condition().and_then(|c| c.pat()) { | 380 | if let Some(pat) = e.condition().and_then(|c| c.pat()) { |
381 | // if let -- desugar to match | 381 | // if let -- desugar to match |
382 | let pat = self.collect_pat(pat); | 382 | let pat = self.collect_pat(pat); |
@@ -419,12 +419,12 @@ impl ExprCollector { | |||
419 | ) | 419 | ) |
420 | } | 420 | } |
421 | } | 421 | } |
422 | ast::Expr::BlockExpr(e) => self.collect_block_opt(e.block()), | 422 | ast::ExprKind::BlockExpr(e) => self.collect_block_opt(e.block()), |
423 | ast::Expr::LoopExpr(e) => { | 423 | ast::ExprKind::LoopExpr(e) => { |
424 | let body = self.collect_block_opt(e.loop_body()); | 424 | let body = self.collect_block_opt(e.loop_body()); |
425 | self.alloc_expr(Expr::Loop { body }, syntax_ptr) | 425 | self.alloc_expr(Expr::Loop { body }, syntax_ptr) |
426 | } | 426 | } |
427 | ast::Expr::WhileExpr(e) => { | 427 | ast::ExprKind::WhileExpr(e) => { |
428 | let condition = if let Some(condition) = e.condition() { | 428 | let condition = if let Some(condition) = e.condition() { |
429 | if condition.pat().is_none() { | 429 | if condition.pat().is_none() { |
430 | self.collect_expr_opt(condition.expr()) | 430 | self.collect_expr_opt(condition.expr()) |
@@ -438,7 +438,7 @@ impl ExprCollector { | |||
438 | let body = self.collect_block_opt(e.loop_body()); | 438 | let body = self.collect_block_opt(e.loop_body()); |
439 | self.alloc_expr(Expr::While { condition, body }, syntax_ptr) | 439 | self.alloc_expr(Expr::While { condition, body }, syntax_ptr) |
440 | } | 440 | } |
441 | ast::Expr::ForExpr(e) => { | 441 | ast::ExprKind::ForExpr(e) => { |
442 | let iterable = self.collect_expr_opt(e.iterable()); | 442 | let iterable = self.collect_expr_opt(e.iterable()); |
443 | let pat = self.collect_pat_opt(e.pat()); | 443 | let pat = self.collect_pat_opt(e.pat()); |
444 | let body = self.collect_block_opt(e.loop_body()); | 444 | let body = self.collect_block_opt(e.loop_body()); |
@@ -451,7 +451,7 @@ impl ExprCollector { | |||
451 | syntax_ptr, | 451 | syntax_ptr, |
452 | ) | 452 | ) |
453 | } | 453 | } |
454 | ast::Expr::CallExpr(e) => { | 454 | ast::ExprKind::CallExpr(e) => { |
455 | let callee = self.collect_expr_opt(e.expr()); | 455 | let callee = self.collect_expr_opt(e.expr()); |
456 | let args = if let Some(arg_list) = e.arg_list() { | 456 | let args = if let Some(arg_list) = e.arg_list() { |
457 | arg_list.args().map(|e| self.collect_expr(e)).collect() | 457 | arg_list.args().map(|e| self.collect_expr(e)).collect() |
@@ -460,7 +460,7 @@ impl ExprCollector { | |||
460 | }; | 460 | }; |
461 | self.alloc_expr(Expr::Call { callee, args }, syntax_ptr) | 461 | self.alloc_expr(Expr::Call { callee, args }, syntax_ptr) |
462 | } | 462 | } |
463 | ast::Expr::MethodCallExpr(e) => { | 463 | ast::ExprKind::MethodCallExpr(e) => { |
464 | let receiver = self.collect_expr_opt(e.expr()); | 464 | let receiver = self.collect_expr_opt(e.expr()); |
465 | let args = if let Some(arg_list) = e.arg_list() { | 465 | let args = if let Some(arg_list) = e.arg_list() { |
466 | arg_list.args().map(|e| self.collect_expr(e)).collect() | 466 | arg_list.args().map(|e| self.collect_expr(e)).collect() |
@@ -480,7 +480,7 @@ impl ExprCollector { | |||
480 | syntax_ptr, | 480 | syntax_ptr, |
481 | ) | 481 | ) |
482 | } | 482 | } |
483 | ast::Expr::MatchExpr(e) => { | 483 | ast::ExprKind::MatchExpr(e) => { |
484 | let expr = self.collect_expr_opt(e.expr()); | 484 | let expr = self.collect_expr_opt(e.expr()); |
485 | let arms = if let Some(match_arm_list) = e.match_arm_list() { | 485 | let arms = if let Some(match_arm_list) = e.match_arm_list() { |
486 | match_arm_list | 486 | match_arm_list |
@@ -495,7 +495,7 @@ impl ExprCollector { | |||
495 | }; | 495 | }; |
496 | self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr) | 496 | self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr) |
497 | } | 497 | } |
498 | ast::Expr::PathExpr(e) => { | 498 | ast::ExprKind::PathExpr(e) => { |
499 | let path = e | 499 | let path = e |
500 | .path() | 500 | .path() |
501 | .and_then(Path::from_ast) | 501 | .and_then(Path::from_ast) |
@@ -503,25 +503,25 @@ impl ExprCollector { | |||
503 | .unwrap_or(Expr::Missing); | 503 | .unwrap_or(Expr::Missing); |
504 | self.alloc_expr(path, syntax_ptr) | 504 | self.alloc_expr(path, syntax_ptr) |
505 | } | 505 | } |
506 | ast::Expr::ContinueExpr(_e) => { | 506 | ast::ExprKind::ContinueExpr(_e) => { |
507 | // TODO: labels | 507 | // TODO: labels |
508 | self.alloc_expr(Expr::Continue, syntax_ptr) | 508 | self.alloc_expr(Expr::Continue, syntax_ptr) |
509 | } | 509 | } |
510 | ast::Expr::BreakExpr(e) => { | 510 | ast::ExprKind::BreakExpr(e) => { |
511 | let expr = e.expr().map(|e| self.collect_expr(e)); | 511 | let expr = e.expr().map(|e| self.collect_expr(e)); |
512 | self.alloc_expr(Expr::Break { expr }, syntax_ptr) | 512 | self.alloc_expr(Expr::Break { expr }, syntax_ptr) |
513 | } | 513 | } |
514 | ast::Expr::ParenExpr(e) => { | 514 | ast::ExprKind::ParenExpr(e) => { |
515 | let inner = self.collect_expr_opt(e.expr()); | 515 | let inner = self.collect_expr_opt(e.expr()); |
516 | // make the paren expr point to the inner expression as well | 516 | // make the paren expr point to the inner expression as well |
517 | self.expr_syntax_mapping.insert(syntax_ptr, inner); | 517 | self.expr_syntax_mapping.insert(syntax_ptr, inner); |
518 | inner | 518 | inner |
519 | } | 519 | } |
520 | ast::Expr::ReturnExpr(e) => { | 520 | ast::ExprKind::ReturnExpr(e) => { |
521 | let expr = e.expr().map(|e| self.collect_expr(e)); | 521 | let expr = e.expr().map(|e| self.collect_expr(e)); |
522 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) | 522 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) |
523 | } | 523 | } |
524 | ast::Expr::StructLit(e) => { | 524 | ast::ExprKind::StructLit(e) => { |
525 | let path = e.path().and_then(Path::from_ast); | 525 | let path = e.path().and_then(Path::from_ast); |
526 | let fields = if let Some(nfl) = e.named_field_list() { | 526 | let fields = if let Some(nfl) = e.named_field_list() { |
527 | nfl.fields() | 527 | nfl.fields() |
@@ -558,7 +558,7 @@ impl ExprCollector { | |||
558 | syntax_ptr, | 558 | syntax_ptr, |
559 | ) | 559 | ) |
560 | } | 560 | } |
561 | ast::Expr::FieldExpr(e) => { | 561 | ast::ExprKind::FieldExpr(e) => { |
562 | let expr = self.collect_expr_opt(e.expr()); | 562 | let expr = self.collect_expr_opt(e.expr()); |
563 | let name = e | 563 | let name = e |
564 | .name_ref() | 564 | .name_ref() |
@@ -566,26 +566,26 @@ impl ExprCollector { | |||
566 | .unwrap_or_else(Name::missing); | 566 | .unwrap_or_else(Name::missing); |
567 | self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) | 567 | self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) |
568 | } | 568 | } |
569 | ast::Expr::TryExpr(e) => { | 569 | ast::ExprKind::TryExpr(e) => { |
570 | let expr = self.collect_expr_opt(e.expr()); | 570 | let expr = self.collect_expr_opt(e.expr()); |
571 | self.alloc_expr(Expr::Try { expr }, syntax_ptr) | 571 | self.alloc_expr(Expr::Try { expr }, syntax_ptr) |
572 | } | 572 | } |
573 | ast::Expr::CastExpr(e) => { | 573 | ast::ExprKind::CastExpr(e) => { |
574 | let expr = self.collect_expr_opt(e.expr()); | 574 | let expr = self.collect_expr_opt(e.expr()); |
575 | let type_ref = TypeRef::from_ast_opt(e.type_ref()); | 575 | let type_ref = TypeRef::from_ast_opt(e.type_ref()); |
576 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) | 576 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) |
577 | } | 577 | } |
578 | ast::Expr::RefExpr(e) => { | 578 | ast::ExprKind::RefExpr(e) => { |
579 | let expr = self.collect_expr_opt(e.expr()); | 579 | let expr = self.collect_expr_opt(e.expr()); |
580 | let mutability = Mutability::from_mutable(e.is_mut()); | 580 | let mutability = Mutability::from_mutable(e.is_mut()); |
581 | self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) | 581 | self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) |
582 | } | 582 | } |
583 | ast::Expr::PrefixExpr(e) => { | 583 | ast::ExprKind::PrefixExpr(e) => { |
584 | let expr = self.collect_expr_opt(e.expr()); | 584 | let expr = self.collect_expr_opt(e.expr()); |
585 | let op = e.op(); | 585 | let op = e.op(); |
586 | self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr) | 586 | self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr) |
587 | } | 587 | } |
588 | ast::Expr::LambdaExpr(e) => { | 588 | ast::ExprKind::LambdaExpr(e) => { |
589 | let mut args = Vec::new(); | 589 | let mut args = Vec::new(); |
590 | let mut arg_types = Vec::new(); | 590 | let mut arg_types = Vec::new(); |
591 | if let Some(pl) = e.param_list() { | 591 | if let Some(pl) = e.param_list() { |
@@ -606,7 +606,7 @@ impl ExprCollector { | |||
606 | syntax_ptr, | 606 | syntax_ptr, |
607 | ) | 607 | ) |
608 | } | 608 | } |
609 | ast::Expr::BinExpr(e) => { | 609 | ast::ExprKind::BinExpr(e) => { |
610 | let lhs = self.collect_expr_opt(e.lhs()); | 610 | let lhs = self.collect_expr_opt(e.lhs()); |
611 | let rhs = self.collect_expr_opt(e.rhs()); | 611 | let rhs = self.collect_expr_opt(e.rhs()); |
612 | let op = e.op(); | 612 | let op = e.op(); |
@@ -614,16 +614,16 @@ impl ExprCollector { | |||
614 | } | 614 | } |
615 | 615 | ||
616 | // TODO implement HIR for these: | 616 | // TODO implement HIR for these: |
617 | ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 617 | ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
618 | ast::Expr::IndexExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 618 | ast::ExprKind::IndexExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
619 | ast::Expr::TupleExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 619 | ast::ExprKind::TupleExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
620 | ast::Expr::ArrayExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 620 | ast::ExprKind::ArrayExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
621 | ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 621 | ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
622 | ast::Expr::Literal(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), | 622 | ast::ExprKind::Literal(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), |
623 | } | 623 | } |
624 | } | 624 | } |
625 | 625 | ||
626 | fn collect_expr_opt(&mut self, expr: Option<ast::Expr>) -> ExprId { | 626 | fn collect_expr_opt(&mut self, expr: Option<&ast::Expr>) -> ExprId { |
627 | if let Some(expr) = expr { | 627 | if let Some(expr) = expr { |
628 | self.collect_expr(expr) | 628 | self.collect_expr(expr) |
629 | } else { | 629 | } else { |
@@ -631,11 +631,11 @@ impl ExprCollector { | |||
631 | } | 631 | } |
632 | } | 632 | } |
633 | 633 | ||
634 | fn collect_block(&mut self, block: ast::Block) -> ExprId { | 634 | fn collect_block(&mut self, block: &ast::Block) -> ExprId { |
635 | let statements = block | 635 | let statements = block |
636 | .statements() | 636 | .statements() |
637 | .map(|s| match s { | 637 | .map(|s| match s.kind() { |
638 | ast::Stmt::LetStmt(stmt) => { | 638 | ast::StmtKind::LetStmt(stmt) => { |
639 | let pat = self.collect_pat_opt(stmt.pat()); | 639 | let pat = self.collect_pat_opt(stmt.pat()); |
640 | let type_ref = stmt.type_ref().map(TypeRef::from_ast); | 640 | let type_ref = stmt.type_ref().map(TypeRef::from_ast); |
641 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); | 641 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); |
@@ -645,7 +645,9 @@ impl ExprCollector { | |||
645 | initializer, | 645 | initializer, |
646 | } | 646 | } |
647 | } | 647 | } |
648 | ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())), | 648 | ast::StmtKind::ExprStmt(stmt) => { |
649 | Statement::Expr(self.collect_expr_opt(stmt.expr())) | ||
650 | } | ||
649 | }) | 651 | }) |
650 | .collect(); | 652 | .collect(); |
651 | let tail = block.expr().map(|e| self.collect_expr(e)); | 653 | let tail = block.expr().map(|e| self.collect_expr(e)); |
@@ -655,7 +657,7 @@ impl ExprCollector { | |||
655 | ) | 657 | ) |
656 | } | 658 | } |
657 | 659 | ||
658 | fn collect_block_opt(&mut self, block: Option<ast::Block>) -> ExprId { | 660 | fn collect_block_opt(&mut self, block: Option<&ast::Block>) -> ExprId { |
659 | if let Some(block) = block { | 661 | if let Some(block) = block { |
660 | self.collect_block(block) | 662 | self.collect_block(block) |
661 | } else { | 663 | } else { |
@@ -663,17 +665,17 @@ impl ExprCollector { | |||
663 | } | 665 | } |
664 | } | 666 | } |
665 | 667 | ||
666 | fn collect_pat(&mut self, pat: ast::Pat) -> PatId { | 668 | fn collect_pat(&mut self, pat: &ast::Pat) -> PatId { |
667 | let syntax_ptr = LocalSyntaxPtr::new(pat.syntax()); | 669 | let syntax_ptr = LocalSyntaxPtr::new(pat.syntax()); |
668 | match pat { | 670 | match pat.kind() { |
669 | ast::Pat::BindPat(bp) => { | 671 | ast::PatKind::BindPat(bp) => { |
670 | let name = bp | 672 | let name = bp |
671 | .name() | 673 | .name() |
672 | .map(|nr| nr.as_name()) | 674 | .map(|nr| nr.as_name()) |
673 | .unwrap_or_else(Name::missing); | 675 | .unwrap_or_else(Name::missing); |
674 | self.alloc_pat(Pat::Bind { name }, syntax_ptr) | 676 | self.alloc_pat(Pat::Bind { name }, syntax_ptr) |
675 | } | 677 | } |
676 | ast::Pat::TupleStructPat(p) => { | 678 | ast::PatKind::TupleStructPat(p) => { |
677 | let path = p.path().and_then(Path::from_ast); | 679 | let path = p.path().and_then(Path::from_ast); |
678 | let args = p.args().map(|p| self.collect_pat(p)).collect(); | 680 | let args = p.args().map(|p| self.collect_pat(p)).collect(); |
679 | self.alloc_pat(Pat::TupleStruct { path, args }, syntax_ptr) | 681 | self.alloc_pat(Pat::TupleStruct { path, args }, syntax_ptr) |
@@ -685,7 +687,7 @@ impl ExprCollector { | |||
685 | } | 687 | } |
686 | } | 688 | } |
687 | 689 | ||
688 | fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId { | 690 | fn collect_pat_opt(&mut self, pat: Option<&ast::Pat>) -> PatId { |
689 | if let Some(pat) = pat { | 691 | if let Some(pat) = pat { |
690 | self.collect_pat(pat) | 692 | self.collect_pat(pat) |
691 | } else { | 693 | } else { |
@@ -710,7 +712,7 @@ impl ExprCollector { | |||
710 | } | 712 | } |
711 | } | 713 | } |
712 | 714 | ||
713 | pub(crate) fn collect_fn_body_syntax(node: ast::FnDef) -> BodySyntaxMapping { | 715 | pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping { |
714 | let mut collector = ExprCollector::new(); | 716 | let mut collector = ExprCollector::new(); |
715 | 717 | ||
716 | let args = if let Some(param_list) = node.param_list() { | 718 | let args = if let Some(param_list) = node.param_list() { |
@@ -758,9 +760,7 @@ pub(crate) fn body_syntax_mapping( | |||
758 | let body_syntax_mapping = match def { | 760 | let body_syntax_mapping = match def { |
759 | Def::Function(f) => { | 761 | Def::Function(f) => { |
760 | let node = f.syntax(db); | 762 | let node = f.syntax(db); |
761 | let node = node.borrowed(); | 763 | collect_fn_body_syntax(&node) |
762 | |||
763 | collect_fn_body_syntax(node) | ||
764 | } | 764 | } |
765 | // TODO: consts, etc. | 765 | // TODO: consts, etc. |
766 | _ => panic!("Trying to get body for item type without body"), | 766 | _ => panic!("Trying to get body for item type without body"), |
diff --git a/crates/ra_hir/src/function.rs b/crates/ra_hir/src/function.rs index 4627be071..81b790c5f 100644 --- a/crates/ra_hir/src/function.rs +++ b/crates/ra_hir/src/function.rs | |||
@@ -7,7 +7,7 @@ use std::{ | |||
7 | 7 | ||
8 | use ra_db::Cancelable; | 8 | use ra_db::Cancelable; |
9 | use ra_syntax::{ | 9 | use ra_syntax::{ |
10 | TextRange, TextUnit, | 10 | TextRange, TextUnit, TreePtr, |
11 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, | 11 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, |
12 | }; | 12 | }; |
13 | 13 | ||
@@ -29,11 +29,11 @@ impl Function { | |||
29 | self.def_id | 29 | self.def_id |
30 | } | 30 | } |
31 | 31 | ||
32 | pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode { | 32 | pub fn syntax(&self, db: &impl HirDatabase) -> TreePtr<ast::FnDef> { |
33 | let def_loc = self.def_id.loc(db); | 33 | let def_loc = self.def_id.loc(db); |
34 | assert!(def_loc.kind == DefKind::Function); | 34 | assert!(def_loc.kind == DefKind::Function); |
35 | let syntax = db.file_item(def_loc.source_item_id); | 35 | let syntax = db.file_item(def_loc.source_item_id); |
36 | ast::FnDef::cast(syntax.borrowed()).unwrap().owned() | 36 | ast::FnDef::cast(&syntax).unwrap().to_owned() |
37 | } | 37 | } |
38 | 38 | ||
39 | pub fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> { | 39 | pub fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> { |
@@ -59,7 +59,7 @@ impl Function { | |||
59 | 59 | ||
60 | pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> { | 60 | pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> { |
61 | let syntax = self.syntax(db); | 61 | let syntax = self.syntax(db); |
62 | FnSignatureInfo::new(syntax.borrowed()) | 62 | FnSignatureInfo::new(&syntax) |
63 | } | 63 | } |
64 | 64 | ||
65 | pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> { | 65 | pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> { |
@@ -99,8 +99,7 @@ impl FnSignature { | |||
99 | 99 | ||
100 | pub(crate) fn fn_signature(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> { | 100 | pub(crate) fn fn_signature(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> { |
101 | let func = Function::new(def_id); | 101 | let func = Function::new(def_id); |
102 | let syntax = func.syntax(db); | 102 | let node = func.syntax(db); |
103 | let node = syntax.borrowed(); | ||
104 | let mut args = Vec::new(); | 103 | let mut args = Vec::new(); |
105 | if let Some(param_list) = node.param_list() { | 104 | if let Some(param_list) = node.param_list() { |
106 | if let Some(self_param) = param_list.self_param() { | 105 | if let Some(self_param) = param_list.self_param() { |
@@ -144,7 +143,7 @@ pub struct FnSignatureInfo { | |||
144 | } | 143 | } |
145 | 144 | ||
146 | impl FnSignatureInfo { | 145 | impl FnSignatureInfo { |
147 | fn new(node: ast::FnDef) -> Option<Self> { | 146 | fn new(node: &ast::FnDef) -> Option<Self> { |
148 | let name = node.name()?.text().to_string(); | 147 | let name = node.name()?.text().to_string(); |
149 | 148 | ||
150 | let mut doc = None; | 149 | let mut doc = None; |
@@ -207,7 +206,7 @@ impl FnSignatureInfo { | |||
207 | }) | 206 | }) |
208 | } | 207 | } |
209 | 208 | ||
210 | fn extract_doc_comments(node: ast::FnDef) -> Option<(TextRange, String)> { | 209 | fn extract_doc_comments(node: &ast::FnDef) -> Option<(TextRange, String)> { |
211 | if node.doc_comments().count() == 0 { | 210 | if node.doc_comments().count() == 0 { |
212 | return None; | 211 | return None; |
213 | } | 212 | } |
@@ -227,7 +226,7 @@ impl FnSignatureInfo { | |||
227 | Some((range, comment_text)) | 226 | Some((range, comment_text)) |
228 | } | 227 | } |
229 | 228 | ||
230 | fn param_list(node: ast::FnDef) -> Vec<String> { | 229 | fn param_list(node: &ast::FnDef) -> Vec<String> { |
231 | let mut res = vec![]; | 230 | let mut res = vec![]; |
232 | if let Some(param_list) = node.param_list() { | 231 | if let Some(param_list) = node.param_list() { |
233 | if let Some(self_param) = param_list.self_param() { | 232 | if let Some(self_param) = param_list.self_param() { |
diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs index 0a12f0b35..699784f71 100644 --- a/crates/ra_hir/src/function/scope.rs +++ b/crates/ra_hir/src/function/scope.rs | |||
@@ -3,7 +3,7 @@ use std::sync::Arc; | |||
3 | use rustc_hash::{FxHashMap, FxHashSet}; | 3 | use rustc_hash::{FxHashMap, FxHashSet}; |
4 | 4 | ||
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | AstNode, SyntaxNodeRef, TextUnit, TextRange, | 6 | AstNode, SyntaxNode, TextUnit, TextRange, |
7 | algo::generate, | 7 | algo::generate, |
8 | ast, | 8 | ast, |
9 | }; | 9 | }; |
@@ -127,7 +127,7 @@ impl ScopeEntryWithSyntax { | |||
127 | } | 127 | } |
128 | 128 | ||
129 | impl ScopesWithSyntaxMapping { | 129 | impl ScopesWithSyntaxMapping { |
130 | pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a { | 130 | pub fn scope_chain<'a>(&'a self, node: &SyntaxNode) -> impl Iterator<Item = ScopeId> + 'a { |
131 | generate(self.scope_for(node), move |&scope| { | 131 | generate(self.scope_for(node), move |&scope| { |
132 | self.scopes.scopes[scope].parent | 132 | self.scopes.scopes[scope].parent |
133 | }) | 133 | }) |
@@ -178,7 +178,7 @@ impl ScopesWithSyntaxMapping { | |||
178 | .unwrap_or(original_scope) | 178 | .unwrap_or(original_scope) |
179 | } | 179 | } |
180 | 180 | ||
181 | pub fn resolve_local_name(&self, name_ref: ast::NameRef) -> Option<ScopeEntryWithSyntax> { | 181 | pub fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> { |
182 | let mut shadowed = FxHashSet::default(); | 182 | let mut shadowed = FxHashSet::default(); |
183 | let name = name_ref.as_name(); | 183 | let name = name_ref.as_name(); |
184 | let ret = self | 184 | let ret = self |
@@ -195,7 +195,7 @@ impl ScopesWithSyntaxMapping { | |||
195 | }) | 195 | }) |
196 | } | 196 | } |
197 | 197 | ||
198 | pub fn find_all_refs(&self, pat: ast::BindPat) -> Vec<ReferenceDescriptor> { | 198 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { |
199 | let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); | 199 | let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); |
200 | let name_ptr = LocalSyntaxPtr::new(pat.syntax()); | 200 | let name_ptr = LocalSyntaxPtr::new(pat.syntax()); |
201 | fn_def | 201 | fn_def |
@@ -213,7 +213,7 @@ impl ScopesWithSyntaxMapping { | |||
213 | .collect() | 213 | .collect() |
214 | } | 214 | } |
215 | 215 | ||
216 | fn scope_for(&self, node: SyntaxNodeRef) -> Option<ScopeId> { | 216 | fn scope_for(&self, node: &SyntaxNode) -> Option<ScopeId> { |
217 | node.ancestors() | 217 | node.ancestors() |
218 | .map(LocalSyntaxPtr::new) | 218 | .map(LocalSyntaxPtr::new) |
219 | .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) | 219 | .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) |
@@ -309,7 +309,7 @@ pub struct ReferenceDescriptor { | |||
309 | #[cfg(test)] | 309 | #[cfg(test)] |
310 | mod tests { | 310 | mod tests { |
311 | use ra_editor::find_node_at_offset; | 311 | use ra_editor::find_node_at_offset; |
312 | use ra_syntax::SourceFileNode; | 312 | use ra_syntax::SourceFile; |
313 | use test_utils::{extract_offset, assert_eq_text}; | 313 | use test_utils::{extract_offset, assert_eq_text}; |
314 | 314 | ||
315 | use crate::expr; | 315 | use crate::expr; |
@@ -326,9 +326,9 @@ mod tests { | |||
326 | buf.push_str(&code[off..]); | 326 | buf.push_str(&code[off..]); |
327 | buf | 327 | buf |
328 | }; | 328 | }; |
329 | let file = SourceFileNode::parse(&code); | 329 | let file = SourceFile::parse(&code); |
330 | let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); | 330 | let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); |
331 | let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); | 331 | let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); |
332 | let body_hir = expr::collect_fn_body_syntax(fn_def); | 332 | let body_hir = expr::collect_fn_body_syntax(fn_def); |
333 | let scopes = FnScopes::new(Arc::clone(body_hir.body())); | 333 | let scopes = FnScopes::new(Arc::clone(body_hir.body())); |
334 | let scopes = ScopesWithSyntaxMapping { | 334 | let scopes = ScopesWithSyntaxMapping { |
@@ -422,9 +422,9 @@ mod tests { | |||
422 | 422 | ||
423 | fn do_check_local_name(code: &str, expected_offset: u32) { | 423 | fn do_check_local_name(code: &str, expected_offset: u32) { |
424 | let (off, code) = extract_offset(code); | 424 | let (off, code) = extract_offset(code); |
425 | let file = SourceFileNode::parse(&code); | 425 | let file = SourceFile::parse(&code); |
426 | let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); | 426 | let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); |
427 | let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); | 427 | let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); |
428 | 428 | ||
429 | let body_hir = expr::collect_fn_body_syntax(fn_def); | 429 | let body_hir = expr::collect_fn_body_syntax(fn_def); |
430 | let scopes = FnScopes::new(Arc::clone(body_hir.body())); | 430 | let scopes = FnScopes::new(Arc::clone(body_hir.body())); |
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index c7391ee05..730a3e542 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; | 1 | use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; |
2 | use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast}; | 2 | use ra_syntax::{TreePtr, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; |
3 | use ra_arena::{Arena, RawId, impl_arena_id}; | 3 | use ra_arena::{Arena, RawId, impl_arena_id}; |
4 | 4 | ||
5 | use crate::{HirDatabase, PerNs, ModuleId, Def, Function, Struct, Enum, ImplBlock, Crate}; | 5 | use crate::{HirDatabase, PerNs, ModuleId, Def, Function, Struct, Enum, ImplBlock, Crate}; |
@@ -55,7 +55,10 @@ impl HirFileId { | |||
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | pub(crate) fn hir_source_file(db: &impl HirDatabase, file_id: HirFileId) -> SourceFileNode { | 58 | pub(crate) fn hir_source_file( |
59 | db: &impl HirDatabase, | ||
60 | file_id: HirFileId, | ||
61 | ) -> TreePtr<SourceFile> { | ||
59 | match file_id.0 { | 62 | match file_id.0 { |
60 | HirFileIdRepr::File(file_id) => db.source_file(file_id), | 63 | HirFileIdRepr::File(file_id) => db.source_file(file_id), |
61 | HirFileIdRepr::Macro(m) => { | 64 | HirFileIdRepr::Macro(m) => { |
@@ -63,7 +66,7 @@ impl HirFileId { | |||
63 | return exp.file(); | 66 | return exp.file(); |
64 | } | 67 | } |
65 | // returning an empty string looks fishy... | 68 | // returning an empty string looks fishy... |
66 | SourceFileNode::parse("") | 69 | SourceFile::parse("") |
67 | } | 70 | } |
68 | } | 71 | } |
69 | } | 72 | } |
@@ -233,11 +236,11 @@ pub struct SourceItemId { | |||
233 | #[derive(Debug, PartialEq, Eq)] | 236 | #[derive(Debug, PartialEq, Eq)] |
234 | pub struct SourceFileItems { | 237 | pub struct SourceFileItems { |
235 | file_id: HirFileId, | 238 | file_id: HirFileId, |
236 | arena: Arena<SourceFileItemId, SyntaxNode>, | 239 | arena: Arena<SourceFileItemId, TreePtr<SyntaxNode>>, |
237 | } | 240 | } |
238 | 241 | ||
239 | impl SourceFileItems { | 242 | impl SourceFileItems { |
240 | pub(crate) fn new(file_id: HirFileId, source_file: SourceFile) -> SourceFileItems { | 243 | pub(crate) fn new(file_id: HirFileId, source_file: &SourceFile) -> SourceFileItems { |
241 | let mut res = SourceFileItems { | 244 | let mut res = SourceFileItems { |
242 | file_id, | 245 | file_id, |
243 | arena: Arena::default(), | 246 | arena: Arena::default(), |
@@ -246,20 +249,20 @@ impl SourceFileItems { | |||
246 | res | 249 | res |
247 | } | 250 | } |
248 | 251 | ||
249 | fn init(&mut self, source_file: SourceFile) { | 252 | fn init(&mut self, source_file: &SourceFile) { |
250 | source_file.syntax().descendants().for_each(|it| { | 253 | source_file.syntax().descendants().for_each(|it| { |
251 | if let Some(module_item) = ast::ModuleItem::cast(it) { | 254 | if let Some(module_item) = ast::ModuleItem::cast(it) { |
252 | self.alloc(module_item.syntax().owned()); | 255 | self.alloc(module_item.syntax().to_owned()); |
253 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { | 256 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { |
254 | self.alloc(macro_call.syntax().owned()); | 257 | self.alloc(macro_call.syntax().to_owned()); |
255 | } | 258 | } |
256 | }); | 259 | }); |
257 | } | 260 | } |
258 | 261 | ||
259 | fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId { | 262 | fn alloc(&mut self, item: TreePtr<SyntaxNode>) -> SourceFileItemId { |
260 | self.arena.alloc(item) | 263 | self.arena.alloc(item) |
261 | } | 264 | } |
262 | pub(crate) fn id_of(&self, file_id: HirFileId, item: SyntaxNodeRef) -> SourceFileItemId { | 265 | pub(crate) fn id_of(&self, file_id: HirFileId, item: &SyntaxNode) -> SourceFileItemId { |
263 | assert_eq!( | 266 | assert_eq!( |
264 | self.file_id, file_id, | 267 | self.file_id, file_id, |
265 | "SourceFileItems: wrong file, expected {:?}, got {:?}", | 268 | "SourceFileItems: wrong file, expected {:?}, got {:?}", |
@@ -267,8 +270,8 @@ impl SourceFileItems { | |||
267 | ); | 270 | ); |
268 | self.id_of_unchecked(item) | 271 | self.id_of_unchecked(item) |
269 | } | 272 | } |
270 | pub(crate) fn id_of_unchecked(&self, item: SyntaxNodeRef) -> SourceFileItemId { | 273 | pub(crate) fn id_of_unchecked(&self, item: &SyntaxNode) -> SourceFileItemId { |
271 | if let Some((id, _)) = self.arena.iter().find(|(_id, i)| i.borrowed() == item) { | 274 | if let Some((id, _)) = self.arena.iter().find(|(_id, i)| *i == item) { |
272 | return id; | 275 | return id; |
273 | } | 276 | } |
274 | // This should not happen. Let's try to give a sensible diagnostics. | 277 | // This should not happen. Let's try to give a sensible diagnostics. |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 7ce8d17e6..bb0ad84e4 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -62,7 +62,7 @@ impl ImplData { | |||
62 | db: &impl AsRef<LocationIntener<DefLoc, DefId>>, | 62 | db: &impl AsRef<LocationIntener<DefLoc, DefId>>, |
63 | file_items: &SourceFileItems, | 63 | file_items: &SourceFileItems, |
64 | module: &Module, | 64 | module: &Module, |
65 | node: ast::ImplBlock, | 65 | node: &ast::ImplBlock, |
66 | ) -> Self { | 66 | ) -> Self { |
67 | let target_trait = node.target_type().map(TypeRef::from_ast); | 67 | let target_trait = node.target_type().map(TypeRef::from_ast); |
68 | let target_type = TypeRef::from_ast_opt(node.target_type()); | 68 | let target_type = TypeRef::from_ast_opt(node.target_type()); |
@@ -71,10 +71,10 @@ impl ImplData { | |||
71 | item_list | 71 | item_list |
72 | .impl_items() | 72 | .impl_items() |
73 | .map(|item_node| { | 73 | .map(|item_node| { |
74 | let kind = match item_node { | 74 | let kind = match item_node.kind() { |
75 | ast::ImplItem::FnDef(..) => DefKind::Function, | 75 | ast::ImplItemKind::FnDef(..) => DefKind::Function, |
76 | ast::ImplItem::ConstDef(..) => DefKind::Item, | 76 | ast::ImplItemKind::ConstDef(..) => DefKind::Item, |
77 | ast::ImplItem::TypeDef(..) => DefKind::Item, | 77 | ast::ImplItemKind::TypeDef(..) => DefKind::Item, |
78 | }; | 78 | }; |
79 | let item_id = file_items.id_of_unchecked(item_node.syntax()); | 79 | let item_id = file_items.id_of_unchecked(item_node.syntax()); |
80 | let source_item_id = SourceItemId { | 80 | let source_item_id = SourceItemId { |
@@ -87,10 +87,10 @@ impl ImplData { | |||
87 | ..module_loc | 87 | ..module_loc |
88 | }; | 88 | }; |
89 | let def_id = def_loc.id(db); | 89 | let def_id = def_loc.id(db); |
90 | match item_node { | 90 | match item_node.kind() { |
91 | ast::ImplItem::FnDef(..) => ImplItem::Method(Function::new(def_id)), | 91 | ast::ImplItemKind::FnDef(..) => ImplItem::Method(Function::new(def_id)), |
92 | ast::ImplItem::ConstDef(..) => ImplItem::Const(def_id), | 92 | ast::ImplItemKind::ConstDef(..) => ImplItem::Const(def_id), |
93 | ast::ImplItem::TypeDef(..) => ImplItem::Type(def_id), | 93 | ast::ImplItemKind::TypeDef(..) => ImplItem::Type(def_id), |
94 | } | 94 | } |
95 | }) | 95 | }) |
96 | .collect() | 96 | .collect() |
@@ -152,8 +152,8 @@ impl ModuleImplBlocks { | |||
152 | fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { | 152 | fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { |
153 | let (file_id, module_source) = module.defenition_source(db)?; | 153 | let (file_id, module_source) = module.defenition_source(db)?; |
154 | let node = match &module_source { | 154 | let node = match &module_source { |
155 | ModuleSource::SourceFile(node) => node.borrowed().syntax(), | 155 | ModuleSource::SourceFile(node) => node.syntax(), |
156 | ModuleSource::Module(node) => node.borrowed().syntax(), | 156 | ModuleSource::Module(node) => node.syntax(), |
157 | }; | 157 | }; |
158 | 158 | ||
159 | let source_file_items = db.file_items(file_id.into()); | 159 | let source_file_items = db.file_items(file_id.into()); |
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index 1b378c977..eb1c86091 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs | |||
@@ -11,7 +11,7 @@ use std::sync::Arc; | |||
11 | 11 | ||
12 | use ra_db::LocalSyntaxPtr; | 12 | use ra_db::LocalSyntaxPtr; |
13 | use ra_syntax::{ | 13 | use ra_syntax::{ |
14 | TextRange, TextUnit, SourceFileNode, AstNode, SyntaxNode, | 14 | TextRange, TextUnit, SourceFile, AstNode, SyntaxNode, TreePtr, |
15 | ast::{self, NameOwner}, | 15 | ast::{self, NameOwner}, |
16 | }; | 16 | }; |
17 | 17 | ||
@@ -28,14 +28,14 @@ pub enum MacroDef { | |||
28 | impl MacroDef { | 28 | impl MacroDef { |
29 | /// Expands macro call, returning the expansion and offset to be used to | 29 | /// Expands macro call, returning the expansion and offset to be used to |
30 | /// convert ranges between expansion and original source. | 30 | /// convert ranges between expansion and original source. |
31 | pub fn ast_expand(macro_call: ast::MacroCall) -> Option<(TextUnit, MacroExpansion)> { | 31 | pub fn ast_expand(macro_call: &ast::MacroCall) -> Option<(TextUnit, MacroExpansion)> { |
32 | let (def, input) = MacroDef::from_call(macro_call)?; | 32 | let (def, input) = MacroDef::from_call(macro_call)?; |
33 | let exp = def.expand(input)?; | 33 | let exp = def.expand(input)?; |
34 | let off = macro_call.token_tree()?.syntax().range().start(); | 34 | let off = macro_call.token_tree()?.syntax().range().start(); |
35 | Some((off, exp)) | 35 | Some((off, exp)) |
36 | } | 36 | } |
37 | 37 | ||
38 | fn from_call(macro_call: ast::MacroCall) -> Option<(MacroDef, MacroInput)> { | 38 | fn from_call(macro_call: &ast::MacroCall) -> Option<(MacroDef, MacroInput)> { |
39 | let def = { | 39 | let def = { |
40 | let path = macro_call.path()?; | 40 | let path = macro_call.path()?; |
41 | let name_ref = path.segment()?.name_ref()?; | 41 | let name_ref = path.segment()?.name_ref()?; |
@@ -77,7 +77,7 @@ impl MacroDef { | |||
77 | }}", | 77 | }}", |
78 | input.text | 78 | input.text |
79 | ); | 79 | ); |
80 | let file = SourceFileNode::parse(&text); | 80 | let file = SourceFile::parse(&text); |
81 | let match_expr = file.syntax().descendants().find_map(ast::MatchExpr::cast)?; | 81 | let match_expr = file.syntax().descendants().find_map(ast::MatchExpr::cast)?; |
82 | let match_arg = match_expr.expr()?; | 82 | let match_arg = match_expr.expr()?; |
83 | let ptr = LocalSyntaxPtr::new(match_arg.syntax()); | 83 | let ptr = LocalSyntaxPtr::new(match_arg.syntax()); |
@@ -92,7 +92,7 @@ impl MacroDef { | |||
92 | } | 92 | } |
93 | fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> { | 93 | fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> { |
94 | let text = format!(r"fn dummy() {{ {}; }}", input.text); | 94 | let text = format!(r"fn dummy() {{ {}; }}", input.text); |
95 | let file = SourceFileNode::parse(&text); | 95 | let file = SourceFile::parse(&text); |
96 | let array_expr = file.syntax().descendants().find_map(ast::ArrayExpr::cast)?; | 96 | let array_expr = file.syntax().descendants().find_map(ast::ArrayExpr::cast)?; |
97 | let ptr = LocalSyntaxPtr::new(array_expr.syntax()); | 97 | let ptr = LocalSyntaxPtr::new(array_expr.syntax()); |
98 | let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text)); | 98 | let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text)); |
@@ -116,7 +116,7 @@ impl MacroDef { | |||
116 | } | 116 | } |
117 | let src_range = TextRange::offset_len((pos as u32).into(), TextUnit::of_str(&trait_name)); | 117 | let src_range = TextRange::offset_len((pos as u32).into(), TextUnit::of_str(&trait_name)); |
118 | let text = format!(r"trait {} {{ }}", trait_name); | 118 | let text = format!(r"trait {} {{ }}", trait_name); |
119 | let file = SourceFileNode::parse(&text); | 119 | let file = SourceFile::parse(&text); |
120 | let trait_def = file.syntax().descendants().find_map(ast::TraitDef::cast)?; | 120 | let trait_def = file.syntax().descendants().find_map(ast::TraitDef::cast)?; |
121 | let name = trait_def.name()?; | 121 | let name = trait_def.name()?; |
122 | let ptr = LocalSyntaxPtr::new(trait_def.syntax()); | 122 | let ptr = LocalSyntaxPtr::new(trait_def.syntax()); |
@@ -152,11 +152,11 @@ pub struct MacroExpansion { | |||
152 | impl MacroExpansion { | 152 | impl MacroExpansion { |
153 | // FIXME: does not really make sense, macro expansion is not neccessary a | 153 | // FIXME: does not really make sense, macro expansion is not neccessary a |
154 | // whole file. See `MacroExpansion::ptr` as well. | 154 | // whole file. See `MacroExpansion::ptr` as well. |
155 | pub(crate) fn file(&self) -> SourceFileNode { | 155 | pub(crate) fn file(&self) -> TreePtr<SourceFile> { |
156 | SourceFileNode::parse(&self.text) | 156 | SourceFile::parse(&self.text) |
157 | } | 157 | } |
158 | 158 | ||
159 | pub fn syntax(&self) -> SyntaxNode { | 159 | pub fn syntax(&self) -> TreePtr<SyntaxNode> { |
160 | self.ptr.resolve(&self.file()) | 160 | self.ptr.resolve(&self.file()) |
161 | } | 161 | } |
162 | /// Maps range in the source code to the range in the expanded code. | 162 | /// Maps range in the source code to the range in the expanded code. |
@@ -191,8 +191,7 @@ pub(crate) fn expand_macro_invocation( | |||
191 | ) -> Option<Arc<MacroExpansion>> { | 191 | ) -> Option<Arc<MacroExpansion>> { |
192 | let loc = invoc.loc(db); | 192 | let loc = invoc.loc(db); |
193 | let syntax = db.file_item(loc.source_item_id); | 193 | let syntax = db.file_item(loc.source_item_id); |
194 | let syntax = syntax.borrowed(); | 194 | let macro_call = ast::MacroCall::cast(&syntax).unwrap(); |
195 | let macro_call = ast::MacroCall::cast(syntax).unwrap(); | ||
196 | 195 | ||
197 | let (def, input) = MacroDef::from_call(macro_call)?; | 196 | let (def, input) = MacroDef::from_call(macro_call)?; |
198 | def.expand(input).map(Arc::new) | 197 | def.expand(input).map(Arc::new) |
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index c7a442319..91aab5c74 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs | |||
@@ -5,9 +5,9 @@ use arrayvec::ArrayVec; | |||
5 | use relative_path::RelativePathBuf; | 5 | use relative_path::RelativePathBuf; |
6 | use ra_db::{FileId, SourceRootId, Cancelable, SourceRoot}; | 6 | use ra_db::{FileId, SourceRootId, Cancelable, SourceRoot}; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | SyntaxNode, TreePtr, | ||
8 | algo::generate, | 9 | algo::generate, |
9 | ast::{self, AstNode, NameOwner}, | 10 | ast::{self, AstNode, NameOwner}, |
10 | SyntaxNode, | ||
11 | }; | 11 | }; |
12 | use ra_arena::{Arena, RawId, impl_arena_id}; | 12 | use ra_arena::{Arena, RawId, impl_arena_id}; |
13 | 13 | ||
@@ -19,12 +19,11 @@ impl ModuleSource { | |||
19 | source_item_id: SourceItemId, | 19 | source_item_id: SourceItemId, |
20 | ) -> ModuleSource { | 20 | ) -> ModuleSource { |
21 | let module_syntax = db.file_item(source_item_id); | 21 | let module_syntax = db.file_item(source_item_id); |
22 | let module_syntax = module_syntax.borrowed(); | 22 | if let Some(source_file) = ast::SourceFile::cast(&module_syntax) { |
23 | if let Some(source_file) = ast::SourceFile::cast(module_syntax) { | 23 | ModuleSource::SourceFile(source_file.to_owned()) |
24 | ModuleSource::SourceFile(source_file.owned()) | 24 | } else if let Some(module) = ast::Module::cast(&module_syntax) { |
25 | } else if let Some(module) = ast::Module::cast(module_syntax) { | ||
26 | assert!(module.item_list().is_some(), "expected inline module"); | 25 | assert!(module.item_list().is_some(), "expected inline module"); |
27 | ModuleSource::Module(module.owned()) | 26 | ModuleSource::Module(module.to_owned()) |
28 | } else { | 27 | } else { |
29 | panic!("expected file or inline module") | 28 | panic!("expected file or inline module") |
30 | } | 29 | } |
@@ -49,19 +48,18 @@ impl Submodule { | |||
49 | let module_source = ModuleSource::from_source_item_id(db, source); | 48 | let module_source = ModuleSource::from_source_item_id(db, source); |
50 | let submodules = match module_source { | 49 | let submodules = match module_source { |
51 | ModuleSource::SourceFile(source_file) => { | 50 | ModuleSource::SourceFile(source_file) => { |
52 | collect_submodules(file_id, &file_items, source_file.borrowed()) | 51 | collect_submodules(file_id, &file_items, &*source_file) |
53 | } | 52 | } |
54 | ModuleSource::Module(module) => { | 53 | ModuleSource::Module(module) => { |
55 | let module = module.borrowed(); | ||
56 | collect_submodules(file_id, &file_items, module.item_list().unwrap()) | 54 | collect_submodules(file_id, &file_items, module.item_list().unwrap()) |
57 | } | 55 | } |
58 | }; | 56 | }; |
59 | return Ok(Arc::new(submodules)); | 57 | return Ok(Arc::new(submodules)); |
60 | 58 | ||
61 | fn collect_submodules<'a>( | 59 | fn collect_submodules( |
62 | file_id: HirFileId, | 60 | file_id: HirFileId, |
63 | file_items: &SourceFileItems, | 61 | file_items: &SourceFileItems, |
64 | root: impl ast::ModuleItemOwner<'a>, | 62 | root: &impl ast::ModuleItemOwner, |
65 | ) -> Vec<Submodule> { | 63 | ) -> Vec<Submodule> { |
66 | modules(root) | 64 | modules(root) |
67 | .map(|(name, m)| Submodule { | 65 | .map(|(name, m)| Submodule { |
@@ -120,8 +118,8 @@ impl ModuleTree { | |||
120 | source_root: SourceRootId, | 118 | source_root: SourceRootId, |
121 | ) -> Cancelable<Arc<ModuleTree>> { | 119 | ) -> Cancelable<Arc<ModuleTree>> { |
122 | db.check_canceled()?; | 120 | db.check_canceled()?; |
123 | let res = create_module_tree(db, source_root)?; | 121 | let res = create_module_tree(db, source_root); |
124 | Ok(Arc::new(res)) | 122 | Ok(Arc::new(res?)) |
125 | } | 123 | } |
126 | 124 | ||
127 | pub(crate) fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a { | 125 | pub(crate) fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a { |
@@ -172,14 +170,14 @@ impl ModuleId { | |||
172 | self, | 170 | self, |
173 | tree: &ModuleTree, | 171 | tree: &ModuleTree, |
174 | db: &impl HirDatabase, | 172 | db: &impl HirDatabase, |
175 | ) -> Vec<(SyntaxNode, Problem)> { | 173 | ) -> Vec<(TreePtr<SyntaxNode>, Problem)> { |
176 | tree.mods[self] | 174 | tree.mods[self] |
177 | .children | 175 | .children |
178 | .iter() | 176 | .iter() |
179 | .filter_map(|&link| { | 177 | .filter_map(|&link| { |
180 | let p = tree.links[link].problem.clone()?; | 178 | let p = tree.links[link].problem.clone()?; |
181 | let s = link.source(tree, db); | 179 | let s = link.source(tree, db); |
182 | let s = s.borrowed().name().unwrap().syntax().owned(); | 180 | let s = s.name().unwrap().syntax().to_owned(); |
183 | Some((s, p)) | 181 | Some((s, p)) |
184 | }) | 182 | }) |
185 | .collect() | 183 | .collect() |
@@ -193,11 +191,9 @@ impl LinkId { | |||
193 | pub(crate) fn name(self, tree: &ModuleTree) -> &Name { | 191 | pub(crate) fn name(self, tree: &ModuleTree) -> &Name { |
194 | &tree.links[self].name | 192 | &tree.links[self].name |
195 | } | 193 | } |
196 | pub(crate) fn source(self, tree: &ModuleTree, db: &impl HirDatabase) -> ast::ModuleNode { | 194 | pub(crate) fn source(self, tree: &ModuleTree, db: &impl HirDatabase) -> TreePtr<ast::Module> { |
197 | let syntax_node = db.file_item(tree.links[self].source); | 195 | let syntax_node = db.file_item(tree.links[self].source); |
198 | ast::ModuleNode::cast(syntax_node.borrowed()) | 196 | ast::Module::cast(&syntax_node).unwrap().to_owned() |
199 | .unwrap() | ||
200 | .owned() | ||
201 | } | 197 | } |
202 | } | 198 | } |
203 | 199 | ||
@@ -213,12 +209,10 @@ impl ModuleTree { | |||
213 | } | 209 | } |
214 | } | 210 | } |
215 | 211 | ||
216 | fn modules<'a>( | 212 | fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator<Item = (Name, &ast::Module)> { |
217 | root: impl ast::ModuleItemOwner<'a>, | ||
218 | ) -> impl Iterator<Item = (Name, ast::Module<'a>)> { | ||
219 | root.items() | 213 | root.items() |
220 | .filter_map(|item| match item { | 214 | .filter_map(|item| match item.kind() { |
221 | ast::ModuleItem::Module(m) => Some(m), | 215 | ast::ModuleItemKind::Module(m) => Some(m), |
222 | _ => None, | 216 | _ => None, |
223 | }) | 217 | }) |
224 | .filter_map(|module| { | 218 | .filter_map(|module| { |
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs index 599285346..dee1c9c5c 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir/src/name.rs | |||
@@ -74,13 +74,13 @@ pub(crate) trait AsName { | |||
74 | fn as_name(&self) -> Name; | 74 | fn as_name(&self) -> Name; |
75 | } | 75 | } |
76 | 76 | ||
77 | impl AsName for ast::NameRef<'_> { | 77 | impl AsName for ast::NameRef { |
78 | fn as_name(&self) -> Name { | 78 | fn as_name(&self) -> Name { |
79 | Name::new(self.text()) | 79 | Name::new(self.text()) |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | impl AsName for ast::Name<'_> { | 83 | impl AsName for ast::Name { |
84 | fn as_name(&self) -> Name { | 84 | fn as_name(&self) -> Name { |
85 | Name::new(self.text()) | 85 | Name::new(self.text()) |
86 | } | 86 | } |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 9a412bc82..749fd604e 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -103,7 +103,7 @@ impl NamedImport { | |||
103 | item_id: Some(self.file_item_id), | 103 | item_id: Some(self.file_item_id), |
104 | }; | 104 | }; |
105 | let syntax = db.file_item(source_item_id); | 105 | let syntax = db.file_item(source_item_id); |
106 | let offset = syntax.borrowed().range().start(); | 106 | let offset = syntax.range().start(); |
107 | self.relative_range + offset | 107 | self.relative_range + offset |
108 | } | 108 | } |
109 | } | 109 | } |
@@ -215,45 +215,45 @@ impl InputModuleItems { | |||
215 | &mut self, | 215 | &mut self, |
216 | file_id: HirFileId, | 216 | file_id: HirFileId, |
217 | file_items: &SourceFileItems, | 217 | file_items: &SourceFileItems, |
218 | item: ast::ModuleItem, | 218 | item: &ast::ModuleItem, |
219 | ) -> Option<()> { | 219 | ) -> Option<()> { |
220 | match item { | 220 | match item.kind() { |
221 | ast::ModuleItem::StructDef(it) => { | 221 | ast::ModuleItemKind::StructDef(it) => { |
222 | self.items.push(ModuleItem::new(file_id, file_items, it)?) | 222 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
223 | } | 223 | } |
224 | ast::ModuleItem::EnumDef(it) => { | 224 | ast::ModuleItemKind::EnumDef(it) => { |
225 | self.items.push(ModuleItem::new(file_id, file_items, it)?) | 225 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
226 | } | 226 | } |
227 | ast::ModuleItem::FnDef(it) => { | 227 | ast::ModuleItemKind::FnDef(it) => { |
228 | self.items.push(ModuleItem::new(file_id, file_items, it)?) | 228 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
229 | } | 229 | } |
230 | ast::ModuleItem::TraitDef(it) => { | 230 | ast::ModuleItemKind::TraitDef(it) => { |
231 | self.items.push(ModuleItem::new(file_id, file_items, it)?) | 231 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
232 | } | 232 | } |
233 | ast::ModuleItem::TypeDef(it) => { | 233 | ast::ModuleItemKind::TypeDef(it) => { |
234 | self.items.push(ModuleItem::new(file_id, file_items, it)?) | 234 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
235 | } | 235 | } |
236 | ast::ModuleItem::ImplBlock(_) => { | 236 | ast::ModuleItemKind::ImplBlock(_) => { |
237 | // impls don't define items | 237 | // impls don't define items |
238 | } | 238 | } |
239 | ast::ModuleItem::UseItem(it) => self.add_use_item(file_items, it), | 239 | ast::ModuleItemKind::UseItem(it) => self.add_use_item(file_items, it), |
240 | ast::ModuleItem::ExternCrateItem(_) => { | 240 | ast::ModuleItemKind::ExternCrateItem(_) => { |
241 | // TODO | 241 | // TODO |
242 | } | 242 | } |
243 | ast::ModuleItem::ConstDef(it) => { | 243 | ast::ModuleItemKind::ConstDef(it) => { |
244 | self.items.push(ModuleItem::new(file_id, file_items, it)?) | 244 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
245 | } | 245 | } |
246 | ast::ModuleItem::StaticDef(it) => { | 246 | ast::ModuleItemKind::StaticDef(it) => { |
247 | self.items.push(ModuleItem::new(file_id, file_items, it)?) | 247 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
248 | } | 248 | } |
249 | ast::ModuleItem::Module(it) => { | 249 | ast::ModuleItemKind::Module(it) => { |
250 | self.items.push(ModuleItem::new(file_id, file_items, it)?) | 250 | self.items.push(ModuleItem::new(file_id, file_items, it)?) |
251 | } | 251 | } |
252 | } | 252 | } |
253 | Some(()) | 253 | Some(()) |
254 | } | 254 | } |
255 | 255 | ||
256 | fn add_use_item(&mut self, file_items: &SourceFileItems, item: ast::UseItem) { | 256 | fn add_use_item(&mut self, file_items: &SourceFileItems, item: &ast::UseItem) { |
257 | let file_item_id = file_items.id_of_unchecked(item.syntax()); | 257 | let file_item_id = file_items.id_of_unchecked(item.syntax()); |
258 | let start_offset = item.syntax().range().start(); | 258 | let start_offset = item.syntax().range().start(); |
259 | Path::expand_use_item(item, |path, range| { | 259 | Path::expand_use_item(item, |path, range| { |
@@ -270,10 +270,10 @@ impl InputModuleItems { | |||
270 | } | 270 | } |
271 | 271 | ||
272 | impl ModuleItem { | 272 | impl ModuleItem { |
273 | fn new<'a>( | 273 | fn new( |
274 | file_id: HirFileId, | 274 | file_id: HirFileId, |
275 | file_items: &SourceFileItems, | 275 | file_items: &SourceFileItems, |
276 | item: impl ast::NameOwner<'a>, | 276 | item: &impl ast::NameOwner, |
277 | ) -> Option<ModuleItem> { | 277 | ) -> Option<ModuleItem> { |
278 | let name = item.name()?.as_name(); | 278 | let name = item.name()?.as_name(); |
279 | let kind = item.syntax().kind(); | 279 | let kind = item.syntax().kind(); |
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index dcf4cf8b6..6f0b0da97 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs | |||
@@ -18,14 +18,14 @@ pub enum PathKind { | |||
18 | 18 | ||
19 | impl Path { | 19 | impl Path { |
20 | /// Calls `cb` with all paths, represented by this use item. | 20 | /// Calls `cb` with all paths, represented by this use item. |
21 | pub fn expand_use_item(item: ast::UseItem, mut cb: impl FnMut(Path, Option<TextRange>)) { | 21 | pub fn expand_use_item(item: &ast::UseItem, mut cb: impl FnMut(Path, Option<TextRange>)) { |
22 | if let Some(tree) = item.use_tree() { | 22 | if let Some(tree) = item.use_tree() { |
23 | expand_use_tree(None, tree, &mut cb); | 23 | expand_use_tree(None, tree, &mut cb); |
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | /// Converts an `ast::Path` to `Path`. Works with use trees. | 27 | /// Converts an `ast::Path` to `Path`. Works with use trees. |
28 | pub fn from_ast(mut path: ast::Path) -> Option<Path> { | 28 | pub fn from_ast(mut path: &ast::Path) -> Option<Path> { |
29 | let mut kind = PathKind::Plain; | 29 | let mut kind = PathKind::Plain; |
30 | let mut segments = Vec::new(); | 30 | let mut segments = Vec::new(); |
31 | loop { | 31 | loop { |
@@ -53,7 +53,7 @@ impl Path { | |||
53 | segments.reverse(); | 53 | segments.reverse(); |
54 | return Some(Path { kind, segments }); | 54 | return Some(Path { kind, segments }); |
55 | 55 | ||
56 | fn qualifier(path: ast::Path) -> Option<ast::Path> { | 56 | fn qualifier(path: &ast::Path) -> Option<&ast::Path> { |
57 | if let Some(q) = path.qualifier() { | 57 | if let Some(q) = path.qualifier() { |
58 | return Some(q); | 58 | return Some(q); |
59 | } | 59 | } |
@@ -66,7 +66,7 @@ impl Path { | |||
66 | } | 66 | } |
67 | 67 | ||
68 | /// Converts an `ast::NameRef` into a single-identifier `Path`. | 68 | /// Converts an `ast::NameRef` into a single-identifier `Path`. |
69 | pub fn from_name_ref(name_ref: ast::NameRef) -> Path { | 69 | pub fn from_name_ref(name_ref: &ast::NameRef) -> Path { |
70 | name_ref.as_name().into() | 70 | name_ref.as_name().into() |
71 | } | 71 | } |
72 | 72 | ||
@@ -100,7 +100,7 @@ impl From<Name> for Path { | |||
100 | 100 | ||
101 | fn expand_use_tree( | 101 | fn expand_use_tree( |
102 | prefix: Option<Path>, | 102 | prefix: Option<Path>, |
103 | tree: ast::UseTree, | 103 | tree: &ast::UseTree, |
104 | cb: &mut impl FnMut(Path, Option<TextRange>), | 104 | cb: &mut impl FnMut(Path, Option<TextRange>), |
105 | ) { | 105 | ) { |
106 | if let Some(use_tree_list) = tree.use_tree_list() { | 106 | if let Some(use_tree_list) = tree.use_tree_list() { |
@@ -146,7 +146,7 @@ fn expand_use_tree( | |||
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | fn convert_path(prefix: Option<Path>, path: ast::Path) -> Option<Path> { | 149 | fn convert_path(prefix: Option<Path>, path: &ast::Path) -> Option<Path> { |
150 | let prefix = if let Some(qual) = path.qualifier() { | 150 | let prefix = if let Some(qual) = path.qualifier() { |
151 | Some(convert_path(prefix, qual)?) | 151 | Some(convert_path(prefix, qual)?) |
152 | } else { | 152 | } else { |
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 8f2c40669..380ea5410 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -5,7 +5,7 @@ use std::{ | |||
5 | 5 | ||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | AstNode, SyntaxNode, | 8 | AstNode, SyntaxNode, TreePtr, |
9 | ast::{self, ModuleItemOwner} | 9 | ast::{self, ModuleItemOwner} |
10 | }; | 10 | }; |
11 | use ra_db::{SourceRootId, Cancelable,}; | 11 | use ra_db::{SourceRootId, Cancelable,}; |
@@ -31,30 +31,34 @@ pub(super) fn struct_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ar | |||
31 | assert!(def_loc.kind == DefKind::Struct); | 31 | assert!(def_loc.kind == DefKind::Struct); |
32 | let syntax = db.file_item(def_loc.source_item_id); | 32 | let syntax = db.file_item(def_loc.source_item_id); |
33 | let struct_def = | 33 | let struct_def = |
34 | ast::StructDef::cast(syntax.borrowed()).expect("struct def should point to StructDef node"); | 34 | ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node"); |
35 | Ok(Arc::new(StructData::new(struct_def.borrowed()))) | 35 | Ok(Arc::new(StructData::new(struct_def))) |
36 | } | 36 | } |
37 | 37 | ||
38 | pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<EnumData>> { | 38 | pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<EnumData>> { |
39 | let def_loc = def_id.loc(db); | 39 | let def_loc = def_id.loc(db); |
40 | assert!(def_loc.kind == DefKind::Enum); | 40 | assert!(def_loc.kind == DefKind::Enum); |
41 | let syntax = db.file_item(def_loc.source_item_id); | 41 | let syntax = db.file_item(def_loc.source_item_id); |
42 | let enum_def = | 42 | let enum_def = ast::EnumDef::cast(&syntax).expect("enum def should point to EnumDef node"); |
43 | ast::EnumDef::cast(syntax.borrowed()).expect("enum def should point to EnumDef node"); | 43 | Ok(Arc::new(EnumData::new(enum_def))) |
44 | Ok(Arc::new(EnumData::new(enum_def.borrowed()))) | ||
45 | } | 44 | } |
46 | 45 | ||
47 | pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { | 46 | pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { |
48 | let source_file = db.hir_source_file(file_id); | 47 | let source_file = db.hir_source_file(file_id); |
49 | let source_file = source_file.borrowed(); | 48 | let res = SourceFileItems::new(file_id, &source_file); |
50 | let res = SourceFileItems::new(file_id, source_file); | ||
51 | Arc::new(res) | 49 | Arc::new(res) |
52 | } | 50 | } |
53 | 51 | ||
54 | pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { | 52 | pub(super) fn file_item( |
53 | db: &impl HirDatabase, | ||
54 | source_item_id: SourceItemId, | ||
55 | ) -> TreePtr<SyntaxNode> { | ||
55 | match source_item_id.item_id { | 56 | match source_item_id.item_id { |
56 | Some(id) => db.file_items(source_item_id.file_id)[id].clone(), | 57 | Some(id) => db.file_items(source_item_id.file_id)[id].to_owned(), |
57 | None => db.hir_source_file(source_item_id.file_id).syntax().owned(), | 58 | None => db |
59 | .hir_source_file(source_item_id.file_id) | ||
60 | .syntax() | ||
61 | .to_owned(), | ||
58 | } | 62 | } |
59 | } | 63 | } |
60 | 64 | ||
@@ -88,7 +92,7 @@ pub(super) fn input_module_items( | |||
88 | let file_id = HirFileId::from(id); | 92 | let file_id = HirFileId::from(id); |
89 | let file_items = db.file_items(file_id); | 93 | let file_items = db.file_items(file_id); |
90 | //FIXME: expand recursively | 94 | //FIXME: expand recursively |
91 | for item in db.hir_source_file(file_id).borrowed().items() { | 95 | for item in db.hir_source_file(file_id).items() { |
92 | acc.add_item(file_id, &file_items, item); | 96 | acc.add_item(file_id, &file_items, item); |
93 | } | 97 | } |
94 | } | 98 | } |
@@ -98,9 +102,9 @@ pub(super) fn input_module_items( | |||
98 | 102 | ||
99 | let mut res = InputModuleItems::default(); | 103 | let mut res = InputModuleItems::default(); |
100 | match source { | 104 | match source { |
101 | ModuleSource::SourceFile(it) => fill(&mut res, &mut it.borrowed().items_with_macros()), | 105 | ModuleSource::SourceFile(it) => fill(&mut res, &mut it.items_with_macros()), |
102 | ModuleSource::Module(it) => { | 106 | ModuleSource::Module(it) => { |
103 | if let Some(item_list) = it.borrowed().item_list() { | 107 | if let Some(item_list) = it.item_list() { |
104 | fill(&mut res, &mut item_list.items_with_macros()) | 108 | fill(&mut res, &mut item_list.items_with_macros()) |
105 | } | 109 | } |
106 | } | 110 | } |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 4c14650c0..82675c0e4 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -8,7 +8,7 @@ | |||
8 | use ra_db::{FileId, FilePosition, Cancelable}; | 8 | use ra_db::{FileId, FilePosition, Cancelable}; |
9 | use ra_editor::find_node_at_offset; | 9 | use ra_editor::find_node_at_offset; |
10 | use ra_syntax::{ | 10 | use ra_syntax::{ |
11 | SmolStr, TextRange, SyntaxNodeRef, | 11 | SmolStr, TextRange, SyntaxNode, |
12 | ast::{self, AstNode, NameOwner}, | 12 | ast::{self, AstNode, NameOwner}, |
13 | }; | 13 | }; |
14 | 14 | ||
@@ -30,7 +30,7 @@ pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable | |||
30 | pub fn module_from_declaration( | 30 | pub fn module_from_declaration( |
31 | db: &impl HirDatabase, | 31 | db: &impl HirDatabase, |
32 | file_id: FileId, | 32 | file_id: FileId, |
33 | decl: ast::Module, | 33 | decl: &ast::Module, |
34 | ) -> Cancelable<Option<Module>> { | 34 | ) -> Cancelable<Option<Module>> { |
35 | let parent_module = module_from_file_id(db, file_id)?; | 35 | let parent_module = module_from_file_id(db, file_id)?; |
36 | let child_name = decl.name(); | 36 | let child_name = decl.name(); |
@@ -60,7 +60,7 @@ pub fn module_from_position( | |||
60 | fn module_from_inline( | 60 | fn module_from_inline( |
61 | db: &impl HirDatabase, | 61 | db: &impl HirDatabase, |
62 | file_id: FileId, | 62 | file_id: FileId, |
63 | module: ast::Module, | 63 | module: &ast::Module, |
64 | ) -> Cancelable<Option<Module>> { | 64 | ) -> Cancelable<Option<Module>> { |
65 | assert!(!module.has_semi()); | 65 | assert!(!module.has_semi()); |
66 | let file_id = file_id.into(); | 66 | let file_id = file_id.into(); |
@@ -77,7 +77,7 @@ fn module_from_inline( | |||
77 | pub fn module_from_child_node( | 77 | pub fn module_from_child_node( |
78 | db: &impl HirDatabase, | 78 | db: &impl HirDatabase, |
79 | file_id: FileId, | 79 | file_id: FileId, |
80 | child: SyntaxNodeRef, | 80 | child: &SyntaxNode, |
81 | ) -> Cancelable<Option<Module>> { | 81 | ) -> Cancelable<Option<Module>> { |
82 | if let Some(m) = child | 82 | if let Some(m) = child |
83 | .ancestors() | 83 | .ancestors() |
@@ -112,7 +112,7 @@ pub fn function_from_position( | |||
112 | pub fn function_from_source( | 112 | pub fn function_from_source( |
113 | db: &impl HirDatabase, | 113 | db: &impl HirDatabase, |
114 | file_id: FileId, | 114 | file_id: FileId, |
115 | fn_def: ast::FnDef, | 115 | fn_def: &ast::FnDef, |
116 | ) -> Cancelable<Option<Function>> { | 116 | ) -> Cancelable<Option<Function>> { |
117 | let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?); | 117 | let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?); |
118 | let res = function_from_module(db, &module, fn_def); | 118 | let res = function_from_module(db, &module, fn_def); |
@@ -122,7 +122,7 @@ pub fn function_from_source( | |||
122 | pub fn function_from_module( | 122 | pub fn function_from_module( |
123 | db: &impl HirDatabase, | 123 | db: &impl HirDatabase, |
124 | module: &Module, | 124 | module: &Module, |
125 | fn_def: ast::FnDef, | 125 | fn_def: &ast::FnDef, |
126 | ) -> Function { | 126 | ) -> Function { |
127 | let loc = module.def_id.loc(db); | 127 | let loc = module.def_id.loc(db); |
128 | let file_id = loc.source_item_id.file_id; | 128 | let file_id = loc.source_item_id.file_id; |
@@ -144,7 +144,7 @@ pub fn function_from_module( | |||
144 | pub fn function_from_child_node( | 144 | pub fn function_from_child_node( |
145 | db: &impl HirDatabase, | 145 | db: &impl HirDatabase, |
146 | file_id: FileId, | 146 | file_id: FileId, |
147 | node: SyntaxNodeRef, | 147 | node: &SyntaxNode, |
148 | ) -> Cancelable<Option<Function>> { | 148 | ) -> Cancelable<Option<Function>> { |
149 | let fn_def = ctry!(node.ancestors().find_map(ast::FnDef::cast)); | 149 | let fn_def = ctry!(node.ancestors().find_map(ast::FnDef::cast)); |
150 | function_from_source(db, file_id, fn_def) | 150 | function_from_source(db, file_id, fn_def) |
@@ -170,8 +170,7 @@ pub fn macro_symbols( | |||
170 | if let Some(exp) = db.expand_macro_invocation(macro_call_id) { | 170 | if let Some(exp) = db.expand_macro_invocation(macro_call_id) { |
171 | let loc = macro_call_id.loc(db); | 171 | let loc = macro_call_id.loc(db); |
172 | let syntax = db.file_item(loc.source_item_id); | 172 | let syntax = db.file_item(loc.source_item_id); |
173 | let syntax = syntax.borrowed(); | 173 | let macro_call = ast::MacroCall::cast(&syntax).unwrap(); |
174 | let macro_call = ast::MacroCall::cast(syntax).unwrap(); | ||
175 | let off = macro_call.token_tree().unwrap().syntax().range().start(); | 174 | let off = macro_call.token_tree().unwrap().syntax().range().start(); |
176 | let file = exp.file(); | 175 | let file = exp.file(); |
177 | for trait_def in file.syntax().descendants().filter_map(ast::TraitDef::cast) { | 176 | for trait_def in file.syntax().descendants().filter_map(ast::TraitDef::cast) { |
diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir/src/type_ref.rs index 859f330c2..c9db4e0a5 100644 --- a/crates/ra_hir/src/type_ref.rs +++ b/crates/ra_hir/src/type_ref.rs | |||
@@ -56,9 +56,9 @@ pub enum TypeRef { | |||
56 | 56 | ||
57 | impl TypeRef { | 57 | impl TypeRef { |
58 | /// Converts an `ast::TypeRef` to a `hir::TypeRef`. | 58 | /// Converts an `ast::TypeRef` to a `hir::TypeRef`. |
59 | pub(crate) fn from_ast(node: ast::TypeRef) -> Self { | 59 | pub(crate) fn from_ast(node: &ast::TypeRef) -> Self { |
60 | use ra_syntax::ast::TypeRef::*; | 60 | use ra_syntax::ast::TypeRefKind::*; |
61 | match node { | 61 | match node.kind() { |
62 | ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), | 62 | ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), |
63 | TupleType(inner) => TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()), | 63 | TupleType(inner) => TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()), |
64 | NeverType(..) => TypeRef::Never, | 64 | NeverType(..) => TypeRef::Never, |
@@ -100,7 +100,7 @@ impl TypeRef { | |||
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | pub(crate) fn from_ast_opt(node: Option<ast::TypeRef>) -> Self { | 103 | pub(crate) fn from_ast_opt(node: Option<&ast::TypeRef>) -> Self { |
104 | if let Some(node) = node { | 104 | if let Some(node) = node { |
105 | TypeRef::from_ast(node) | 105 | TypeRef::from_ast(node) |
106 | } else { | 106 | } else { |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 51f134e8a..99f15354f 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -11,7 +11,7 @@ use languageserver_types::{ | |||
11 | use ra_analysis::{ | 11 | use ra_analysis::{ |
12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, | 12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, |
13 | }; | 13 | }; |
14 | use ra_syntax::{text_utils::intersect, TextUnit}; | 14 | use ra_syntax::{text_utils::intersect, TextUnit, AstNode}; |
15 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 15 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
16 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
17 | use serde_json::to_value; | 17 | use serde_json::to_value; |
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index fd6966d4a..eea0e251a 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -13,7 +13,7 @@ unicode-xid = "0.1.0" | |||
13 | itertools = "0.8.0" | 13 | itertools = "0.8.0" |
14 | drop_bomb = "0.1.4" | 14 | drop_bomb = "0.1.4" |
15 | parking_lot = "0.7.0" | 15 | parking_lot = "0.7.0" |
16 | rowan = "0.1.2" | 16 | rowan = "0.2.0" |
17 | text_unit = "0.1.5" | 17 | text_unit = "0.1.5" |
18 | ra_text_edit = { path = "../ra_text_edit" } | 18 | ra_text_edit = { path = "../ra_text_edit" } |
19 | 19 | ||
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index 4b3548ea9..13f50d2ef 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -1,19 +1,23 @@ | |||
1 | pub mod visit; | 1 | pub mod visit; |
2 | 2 | ||
3 | use crate::{SyntaxNode, SyntaxNodeRef, TextRange, TextUnit}; | 3 | use rowan::TransparentNewType; |
4 | |||
5 | use crate::{SyntaxNode, TextRange, TextUnit}; | ||
4 | 6 | ||
5 | pub use rowan::LeafAtOffset; | 7 | pub use rowan::LeafAtOffset; |
6 | 8 | ||
7 | pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset<SyntaxNodeRef> { | 9 | pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset<&SyntaxNode> { |
8 | match node.0.leaf_at_offset(offset) { | 10 | match node.0.leaf_at_offset(offset) { |
9 | LeafAtOffset::None => LeafAtOffset::None, | 11 | LeafAtOffset::None => LeafAtOffset::None, |
10 | LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode(n)), | 12 | LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode::from_repr(n)), |
11 | LeafAtOffset::Between(l, r) => LeafAtOffset::Between(SyntaxNode(l), SyntaxNode(r)), | 13 | LeafAtOffset::Between(l, r) => { |
14 | LeafAtOffset::Between(SyntaxNode::from_repr(l), SyntaxNode::from_repr(r)) | ||
15 | } | ||
12 | } | 16 | } |
13 | } | 17 | } |
14 | 18 | ||
15 | pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { | 19 | pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { |
16 | SyntaxNode(root.0.covering_node(range)) | 20 | SyntaxNode::from_repr(root.0.covering_node(range)) |
17 | } | 21 | } |
18 | 22 | ||
19 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { | 23 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { |
diff --git a/crates/ra_syntax/src/algo/visit.rs b/crates/ra_syntax/src/algo/visit.rs index c021f464c..38f21594c 100644 --- a/crates/ra_syntax/src/algo/visit.rs +++ b/crates/ra_syntax/src/algo/visit.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{AstNode, SyntaxNodeRef}; | 1 | use crate::{AstNode, SyntaxNode}; |
2 | 2 | ||
3 | use std::marker::PhantomData; | 3 | use std::marker::PhantomData; |
4 | 4 | ||
@@ -15,11 +15,11 @@ pub fn visitor_ctx<'a, T, C>(ctx: C) -> impl VisitorCtx<'a, Output = T, Ctx = C> | |||
15 | 15 | ||
16 | pub trait Visitor<'a>: Sized { | 16 | pub trait Visitor<'a>: Sized { |
17 | type Output; | 17 | type Output; |
18 | fn accept(self, node: SyntaxNodeRef<'a>) -> Option<Self::Output>; | 18 | fn accept(self, node: &'a SyntaxNode) -> Option<Self::Output>; |
19 | fn visit<N, F>(self, f: F) -> Vis<Self, N, F> | 19 | fn visit<N, F>(self, f: F) -> Vis<Self, N, F> |
20 | where | 20 | where |
21 | N: AstNode<'a>, | 21 | N: AstNode + 'a, |
22 | F: FnOnce(N) -> Self::Output, | 22 | F: FnOnce(&'a N) -> Self::Output, |
23 | { | 23 | { |
24 | Vis { | 24 | Vis { |
25 | inner: self, | 25 | inner: self, |
@@ -32,11 +32,11 @@ pub trait Visitor<'a>: Sized { | |||
32 | pub trait VisitorCtx<'a>: Sized { | 32 | pub trait VisitorCtx<'a>: Sized { |
33 | type Output; | 33 | type Output; |
34 | type Ctx; | 34 | type Ctx; |
35 | fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx>; | 35 | fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx>; |
36 | fn visit<N, F>(self, f: F) -> VisCtx<Self, N, F> | 36 | fn visit<N, F>(self, f: F) -> VisCtx<Self, N, F> |
37 | where | 37 | where |
38 | N: AstNode<'a>, | 38 | N: AstNode + 'a, |
39 | F: FnOnce(N, Self::Ctx) -> Self::Output, | 39 | F: FnOnce(&'a N, Self::Ctx) -> Self::Output, |
40 | { | 40 | { |
41 | VisCtx { | 41 | VisCtx { |
42 | inner: self, | 42 | inner: self, |
@@ -54,7 +54,7 @@ struct EmptyVisitor<T> { | |||
54 | impl<'a, T> Visitor<'a> for EmptyVisitor<T> { | 54 | impl<'a, T> Visitor<'a> for EmptyVisitor<T> { |
55 | type Output = T; | 55 | type Output = T; |
56 | 56 | ||
57 | fn accept(self, _node: SyntaxNodeRef<'a>) -> Option<T> { | 57 | fn accept(self, _node: &'a SyntaxNode) -> Option<T> { |
58 | None | 58 | None |
59 | } | 59 | } |
60 | } | 60 | } |
@@ -69,7 +69,7 @@ impl<'a, T, C> VisitorCtx<'a> for EmptyVisitorCtx<T, C> { | |||
69 | type Output = T; | 69 | type Output = T; |
70 | type Ctx = C; | 70 | type Ctx = C; |
71 | 71 | ||
72 | fn accept(self, _node: SyntaxNodeRef<'a>) -> Result<T, C> { | 72 | fn accept(self, _node: &'a SyntaxNode) -> Result<T, C> { |
73 | Err(self.ctx) | 73 | Err(self.ctx) |
74 | } | 74 | } |
75 | } | 75 | } |
@@ -84,12 +84,12 @@ pub struct Vis<V, N, F> { | |||
84 | impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> | 84 | impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> |
85 | where | 85 | where |
86 | V: Visitor<'a>, | 86 | V: Visitor<'a>, |
87 | N: AstNode<'a>, | 87 | N: AstNode + 'a, |
88 | F: FnOnce(N) -> <V as Visitor<'a>>::Output, | 88 | F: FnOnce(&'a N) -> <V as Visitor<'a>>::Output, |
89 | { | 89 | { |
90 | type Output = <V as Visitor<'a>>::Output; | 90 | type Output = <V as Visitor<'a>>::Output; |
91 | 91 | ||
92 | fn accept(self, node: SyntaxNodeRef<'a>) -> Option<Self::Output> { | 92 | fn accept(self, node: &'a SyntaxNode) -> Option<Self::Output> { |
93 | let Vis { inner, f, .. } = self; | 93 | let Vis { inner, f, .. } = self; |
94 | inner.accept(node).or_else(|| N::cast(node).map(f)) | 94 | inner.accept(node).or_else(|| N::cast(node).map(f)) |
95 | } | 95 | } |
@@ -105,13 +105,13 @@ pub struct VisCtx<V, N, F> { | |||
105 | impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> | 105 | impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> |
106 | where | 106 | where |
107 | V: VisitorCtx<'a>, | 107 | V: VisitorCtx<'a>, |
108 | N: AstNode<'a>, | 108 | N: AstNode + 'a, |
109 | F: FnOnce(N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output, | 109 | F: FnOnce(&'a N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output, |
110 | { | 110 | { |
111 | type Output = <V as VisitorCtx<'a>>::Output; | 111 | type Output = <V as VisitorCtx<'a>>::Output; |
112 | type Ctx = <V as VisitorCtx<'a>>::Ctx; | 112 | type Ctx = <V as VisitorCtx<'a>>::Ctx; |
113 | 113 | ||
114 | fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx> { | 114 | fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx> { |
115 | let VisCtx { inner, f, .. } = self; | 115 | let VisCtx { inner, f, .. } = self; |
116 | inner.accept(node).or_else(|ctx| match N::cast(node) { | 116 | inner.accept(node).or_else(|ctx| match N::cast(node) { |
117 | None => Err(ctx), | 117 | None => Err(ctx), |
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 9ab59738f..0e303ee98 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -1,119 +1,115 @@ | |||
1 | mod generated; | 1 | mod generated; |
2 | 2 | ||
3 | use std::marker::PhantomData; | 3 | use std::marker::PhantomData; |
4 | use std::string::String as RustString; | ||
5 | 4 | ||
6 | use itertools::Itertools; | 5 | use itertools::Itertools; |
7 | 6 | ||
8 | pub use self::generated::*; | 7 | pub use self::generated::*; |
9 | use crate::{ | 8 | use crate::{ |
10 | yellow::{RefRoot, SyntaxNodeChildren}, | 9 | yellow::{SyntaxNode, SyntaxNodeChildren, TreePtr, RaTypes}, |
11 | SmolStr, | 10 | SmolStr, |
12 | SyntaxKind::*, | 11 | SyntaxKind::*, |
13 | SyntaxNodeRef, | ||
14 | }; | 12 | }; |
15 | 13 | ||
16 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The | 14 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The |
17 | /// conversion itself has zero runtime cost: ast and syntax nodes have exactly | 15 | /// conversion itself has zero runtime cost: ast and syntax nodes have exactly |
18 | /// the same representation: a pointer to the tree root and a pointer to the | 16 | /// the same representation: a pointer to the tree root and a pointer to the |
19 | /// node itself. | 17 | /// node itself. |
20 | pub trait AstNode<'a>: Clone + Copy + 'a { | 18 | pub trait AstNode: rowan::TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>> { |
21 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> | 19 | fn cast(syntax: &SyntaxNode) -> Option<&Self> |
22 | where | 20 | where |
23 | Self: Sized; | 21 | Self: Sized; |
24 | fn syntax(self) -> SyntaxNodeRef<'a>; | 22 | fn syntax(&self) -> &SyntaxNode; |
23 | fn to_owned(&self) -> TreePtr<Self>; | ||
25 | } | 24 | } |
26 | 25 | ||
27 | pub trait NameOwner<'a>: AstNode<'a> { | 26 | pub trait NameOwner: AstNode { |
28 | fn name(self) -> Option<Name<'a>> { | 27 | fn name(&self) -> Option<&Name> { |
29 | child_opt(self) | 28 | child_opt(self) |
30 | } | 29 | } |
31 | } | 30 | } |
32 | 31 | ||
33 | pub trait VisibilityOwner<'a>: AstNode<'a> { | 32 | pub trait VisibilityOwner: AstNode { |
34 | fn visibility(self) -> Option<Visibility<'a>> { | 33 | fn visibility(&self) -> Option<&Visibility> { |
35 | child_opt(self) | 34 | child_opt(self) |
36 | } | 35 | } |
37 | } | 36 | } |
38 | 37 | ||
39 | pub trait LoopBodyOwner<'a>: AstNode<'a> { | 38 | pub trait LoopBodyOwner: AstNode { |
40 | fn loop_body(self) -> Option<Block<'a>> { | 39 | fn loop_body(&self) -> Option<&Block> { |
41 | child_opt(self) | 40 | child_opt(self) |
42 | } | 41 | } |
43 | } | 42 | } |
44 | 43 | ||
45 | pub trait ArgListOwner<'a>: AstNode<'a> { | 44 | pub trait ArgListOwner: AstNode { |
46 | fn arg_list(self) -> Option<ArgList<'a>> { | 45 | fn arg_list(&self) -> Option<&ArgList> { |
47 | child_opt(self) | 46 | child_opt(self) |
48 | } | 47 | } |
49 | } | 48 | } |
50 | 49 | ||
51 | pub trait FnDefOwner<'a>: AstNode<'a> { | 50 | pub trait FnDefOwner: AstNode { |
52 | fn functions(self) -> AstChildren<'a, FnDef<'a>> { | 51 | fn functions(&self) -> AstChildren<FnDef> { |
53 | children(self) | 52 | children(self) |
54 | } | 53 | } |
55 | } | 54 | } |
56 | 55 | ||
57 | // ModuleItem | ||
58 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 56 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
59 | pub enum ItemOrMacro<'a> { | 57 | pub enum ItemOrMacro<'a> { |
60 | Item(ModuleItem<'a>), | 58 | Item(&'a ModuleItem), |
61 | Macro(MacroCall<'a>), | 59 | Macro(&'a MacroCall), |
62 | } | 60 | } |
63 | 61 | ||
64 | impl<'a> AstNode<'a> for ItemOrMacro<'a> { | 62 | pub trait ModuleItemOwner: AstNode { |
65 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 63 | fn items(&self) -> AstChildren<ModuleItem> { |
66 | let res = if let Some(item) = ModuleItem::cast(syntax) { | 64 | children(self) |
67 | ItemOrMacro::Item(item) | ||
68 | } else if let Some(macro_call) = MacroCall::cast(syntax) { | ||
69 | ItemOrMacro::Macro(macro_call) | ||
70 | } else { | ||
71 | return None; | ||
72 | }; | ||
73 | Some(res) | ||
74 | } | 65 | } |
75 | fn syntax(self) -> SyntaxNodeRef<'a> { | 66 | fn items_with_macros(&self) -> ItemOrMacroIter { |
76 | match self { | 67 | ItemOrMacroIter(self.syntax().children()) |
77 | ItemOrMacro::Item(it) => it.syntax(), | ||
78 | ItemOrMacro::Macro(it) => it.syntax(), | ||
79 | } | ||
80 | } | 68 | } |
81 | } | 69 | } |
82 | 70 | ||
83 | pub trait ModuleItemOwner<'a>: AstNode<'a> { | 71 | #[derive(Debug)] |
84 | fn items(self) -> AstChildren<'a, ModuleItem<'a>> { | 72 | pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>); |
85 | children(self) | ||
86 | } | ||
87 | 73 | ||
88 | fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> { | 74 | impl<'a> Iterator for ItemOrMacroIter<'a> { |
89 | children(self) | 75 | type Item = ItemOrMacro<'a>; |
76 | fn next(&mut self) -> Option<ItemOrMacro<'a>> { | ||
77 | loop { | ||
78 | let n = self.0.next()?; | ||
79 | if let Some(item) = ModuleItem::cast(n) { | ||
80 | return Some(ItemOrMacro::Item(item)); | ||
81 | } | ||
82 | if let Some(call) = MacroCall::cast(n) { | ||
83 | return Some(ItemOrMacro::Macro(call)); | ||
84 | } | ||
85 | } | ||
90 | } | 86 | } |
91 | } | 87 | } |
92 | 88 | ||
93 | pub trait TypeParamsOwner<'a>: AstNode<'a> { | 89 | pub trait TypeParamsOwner: AstNode { |
94 | fn type_param_list(self) -> Option<TypeParamList<'a>> { | 90 | fn type_param_list(&self) -> Option<&TypeParamList> { |
95 | child_opt(self) | 91 | child_opt(self) |
96 | } | 92 | } |
97 | 93 | ||
98 | fn where_clause(self) -> Option<WhereClause<'a>> { | 94 | fn where_clause(&self) -> Option<&WhereClause> { |
99 | child_opt(self) | 95 | child_opt(self) |
100 | } | 96 | } |
101 | } | 97 | } |
102 | 98 | ||
103 | pub trait AttrsOwner<'a>: AstNode<'a> { | 99 | pub trait AttrsOwner: AstNode { |
104 | fn attrs(self) -> AstChildren<'a, Attr<'a>> { | 100 | fn attrs(&self) -> AstChildren<Attr> { |
105 | children(self) | 101 | children(self) |
106 | } | 102 | } |
107 | } | 103 | } |
108 | 104 | ||
109 | pub trait DocCommentsOwner<'a>: AstNode<'a> { | 105 | pub trait DocCommentsOwner: AstNode { |
110 | fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { | 106 | fn doc_comments(&self) -> AstChildren<Comment> { |
111 | children(self) | 107 | children(self) |
112 | } | 108 | } |
113 | 109 | ||
114 | /// Returns the textual content of a doc comment block as a single string. | 110 | /// Returns the textual content of a doc comment block as a single string. |
115 | /// That is, strips leading `///` and joins lines | 111 | /// That is, strips leading `///` and joins lines |
116 | fn doc_comment_text(self) -> RustString { | 112 | fn doc_comment_text(&self) -> std::string::String { |
117 | self.doc_comments() | 113 | self.doc_comments() |
118 | .filter(|comment| comment.is_doc_comment()) | 114 | .filter(|comment| comment.is_doc_comment()) |
119 | .map(|comment| { | 115 | .map(|comment| { |
@@ -130,13 +126,13 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> { | |||
130 | } | 126 | } |
131 | } | 127 | } |
132 | 128 | ||
133 | impl<'a> FnDef<'a> { | 129 | impl FnDef { |
134 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 130 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
135 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) | 131 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) |
136 | } | 132 | } |
137 | } | 133 | } |
138 | 134 | ||
139 | impl<'a> Attr<'a> { | 135 | impl Attr { |
140 | pub fn as_atom(&self) -> Option<SmolStr> { | 136 | pub fn as_atom(&self) -> Option<SmolStr> { |
141 | let tt = self.value()?; | 137 | let tt = self.value()?; |
142 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; | 138 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; |
@@ -147,7 +143,7 @@ impl<'a> Attr<'a> { | |||
147 | } | 143 | } |
148 | } | 144 | } |
149 | 145 | ||
150 | pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> { | 146 | pub fn as_call(&self) -> Option<(SmolStr, &TokenTree)> { |
151 | let tt = self.value()?; | 147 | let tt = self.value()?; |
152 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; | 148 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; |
153 | let args = TokenTree::cast(args)?; | 149 | let args = TokenTree::cast(args)?; |
@@ -159,37 +155,37 @@ impl<'a> Attr<'a> { | |||
159 | } | 155 | } |
160 | } | 156 | } |
161 | 157 | ||
162 | impl<'a> Lifetime<'a> { | 158 | impl Lifetime { |
163 | pub fn text(&self) -> SmolStr { | 159 | pub fn text(&self) -> SmolStr { |
164 | self.syntax().leaf_text().unwrap().clone() | 160 | self.syntax().leaf_text().unwrap().clone() |
165 | } | 161 | } |
166 | } | 162 | } |
167 | 163 | ||
168 | impl<'a> Char<'a> { | 164 | impl Char { |
169 | pub fn text(&self) -> &SmolStr { | 165 | pub fn text(&self) -> &SmolStr { |
170 | &self.syntax().leaf_text().unwrap() | 166 | &self.syntax().leaf_text().unwrap() |
171 | } | 167 | } |
172 | } | 168 | } |
173 | 169 | ||
174 | impl<'a> Byte<'a> { | 170 | impl Byte { |
175 | pub fn text(&self) -> &SmolStr { | 171 | pub fn text(&self) -> &SmolStr { |
176 | &self.syntax().leaf_text().unwrap() | 172 | &self.syntax().leaf_text().unwrap() |
177 | } | 173 | } |
178 | } | 174 | } |
179 | 175 | ||
180 | impl<'a> ByteString<'a> { | 176 | impl ByteString { |
181 | pub fn text(&self) -> &SmolStr { | 177 | pub fn text(&self) -> &SmolStr { |
182 | &self.syntax().leaf_text().unwrap() | 178 | &self.syntax().leaf_text().unwrap() |
183 | } | 179 | } |
184 | } | 180 | } |
185 | 181 | ||
186 | impl<'a> String<'a> { | 182 | impl String { |
187 | pub fn text(&self) -> &SmolStr { | 183 | pub fn text(&self) -> &SmolStr { |
188 | &self.syntax().leaf_text().unwrap() | 184 | &self.syntax().leaf_text().unwrap() |
189 | } | 185 | } |
190 | } | 186 | } |
191 | 187 | ||
192 | impl<'a> Comment<'a> { | 188 | impl Comment { |
193 | pub fn text(&self) -> &SmolStr { | 189 | pub fn text(&self) -> &SmolStr { |
194 | self.syntax().leaf_text().unwrap() | 190 | self.syntax().leaf_text().unwrap() |
195 | } | 191 | } |
@@ -251,7 +247,7 @@ impl CommentFlavor { | |||
251 | } | 247 | } |
252 | } | 248 | } |
253 | 249 | ||
254 | impl<'a> Whitespace<'a> { | 250 | impl Whitespace { |
255 | pub fn text(&self) -> &SmolStr { | 251 | pub fn text(&self) -> &SmolStr { |
256 | &self.syntax().leaf_text().unwrap() | 252 | &self.syntax().leaf_text().unwrap() |
257 | } | 253 | } |
@@ -265,36 +261,36 @@ impl<'a> Whitespace<'a> { | |||
265 | } | 261 | } |
266 | } | 262 | } |
267 | 263 | ||
268 | impl<'a> Name<'a> { | 264 | impl Name { |
269 | pub fn text(&self) -> SmolStr { | 265 | pub fn text(&self) -> SmolStr { |
270 | let ident = self.syntax().first_child().unwrap(); | 266 | let ident = self.syntax().first_child().unwrap(); |
271 | ident.leaf_text().unwrap().clone() | 267 | ident.leaf_text().unwrap().clone() |
272 | } | 268 | } |
273 | } | 269 | } |
274 | 270 | ||
275 | impl<'a> NameRef<'a> { | 271 | impl NameRef { |
276 | pub fn text(&self) -> SmolStr { | 272 | pub fn text(&self) -> SmolStr { |
277 | let ident = self.syntax().first_child().unwrap(); | 273 | let ident = self.syntax().first_child().unwrap(); |
278 | ident.leaf_text().unwrap().clone() | 274 | ident.leaf_text().unwrap().clone() |
279 | } | 275 | } |
280 | } | 276 | } |
281 | 277 | ||
282 | impl<'a> ImplBlock<'a> { | 278 | impl ImplBlock { |
283 | pub fn target_type(self) -> Option<TypeRef<'a>> { | 279 | pub fn target_type(&self) -> Option<&TypeRef> { |
284 | match self.target() { | 280 | match self.target() { |
285 | (Some(t), None) | (_, Some(t)) => Some(t), | 281 | (Some(t), None) | (_, Some(t)) => Some(t), |
286 | _ => None, | 282 | _ => None, |
287 | } | 283 | } |
288 | } | 284 | } |
289 | 285 | ||
290 | pub fn target_trait(self) -> Option<TypeRef<'a>> { | 286 | pub fn target_trait(&self) -> Option<&TypeRef> { |
291 | match self.target() { | 287 | match self.target() { |
292 | (Some(t), Some(_)) => Some(t), | 288 | (Some(t), Some(_)) => Some(t), |
293 | _ => None, | 289 | _ => None, |
294 | } | 290 | } |
295 | } | 291 | } |
296 | 292 | ||
297 | fn target(self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) { | 293 | fn target(&self) -> (Option<&TypeRef>, Option<&TypeRef>) { |
298 | let mut types = children(self); | 294 | let mut types = children(self); |
299 | let first = types.next(); | 295 | let first = types.next(); |
300 | let second = types.next(); | 296 | let second = types.next(); |
@@ -302,8 +298,8 @@ impl<'a> ImplBlock<'a> { | |||
302 | } | 298 | } |
303 | } | 299 | } |
304 | 300 | ||
305 | impl<'a> Module<'a> { | 301 | impl Module { |
306 | pub fn has_semi(self) -> bool { | 302 | pub fn has_semi(&self) -> bool { |
307 | match self.syntax().last_child() { | 303 | match self.syntax().last_child() { |
308 | None => false, | 304 | None => false, |
309 | Some(node) => node.kind() == SEMI, | 305 | Some(node) => node.kind() == SEMI, |
@@ -311,8 +307,8 @@ impl<'a> Module<'a> { | |||
311 | } | 307 | } |
312 | } | 308 | } |
313 | 309 | ||
314 | impl<'a> LetStmt<'a> { | 310 | impl LetStmt { |
315 | pub fn has_semi(self) -> bool { | 311 | pub fn has_semi(&self) -> bool { |
316 | match self.syntax().last_child() { | 312 | match self.syntax().last_child() { |
317 | None => false, | 313 | None => false, |
318 | Some(node) => node.kind() == SEMI, | 314 | Some(node) => node.kind() == SEMI, |
@@ -320,35 +316,35 @@ impl<'a> LetStmt<'a> { | |||
320 | } | 316 | } |
321 | } | 317 | } |
322 | 318 | ||
323 | impl<'a> IfExpr<'a> { | 319 | impl IfExpr { |
324 | pub fn then_branch(self) -> Option<Block<'a>> { | 320 | pub fn then_branch(&self) -> Option<&Block> { |
325 | self.blocks().nth(0) | 321 | self.blocks().nth(0) |
326 | } | 322 | } |
327 | pub fn else_branch(self) -> Option<Block<'a>> { | 323 | pub fn else_branch(&self) -> Option<&Block> { |
328 | self.blocks().nth(1) | 324 | self.blocks().nth(1) |
329 | } | 325 | } |
330 | fn blocks(self) -> AstChildren<'a, Block<'a>> { | 326 | fn blocks(&self) -> AstChildren<Block> { |
331 | children(self) | 327 | children(self) |
332 | } | 328 | } |
333 | } | 329 | } |
334 | 330 | ||
335 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 331 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
336 | pub enum PathSegmentKind<'a> { | 332 | pub enum PathSegmentKind<'a> { |
337 | Name(NameRef<'a>), | 333 | Name(&'a NameRef), |
338 | SelfKw, | 334 | SelfKw, |
339 | SuperKw, | 335 | SuperKw, |
340 | CrateKw, | 336 | CrateKw, |
341 | } | 337 | } |
342 | 338 | ||
343 | impl<'a> PathSegment<'a> { | 339 | impl PathSegment { |
344 | pub fn parent_path(self) -> Path<'a> { | 340 | pub fn parent_path(&self) -> &Path { |
345 | self.syntax() | 341 | self.syntax() |
346 | .parent() | 342 | .parent() |
347 | .and_then(Path::cast) | 343 | .and_then(Path::cast) |
348 | .expect("segments are always nested in paths") | 344 | .expect("segments are always nested in paths") |
349 | } | 345 | } |
350 | 346 | ||
351 | pub fn kind(self) -> Option<PathSegmentKind<'a>> { | 347 | pub fn kind(&self) -> Option<PathSegmentKind> { |
352 | let res = if let Some(name_ref) = self.name_ref() { | 348 | let res = if let Some(name_ref) = self.name_ref() { |
353 | PathSegmentKind::Name(name_ref) | 349 | PathSegmentKind::Name(name_ref) |
354 | } else { | 350 | } else { |
@@ -363,20 +359,20 @@ impl<'a> PathSegment<'a> { | |||
363 | } | 359 | } |
364 | } | 360 | } |
365 | 361 | ||
366 | impl<'a> Path<'a> { | 362 | impl Path { |
367 | pub fn parent_path(self) -> Option<Path<'a>> { | 363 | pub fn parent_path(&self) -> Option<&Path> { |
368 | self.syntax().parent().and_then(Path::cast) | 364 | self.syntax().parent().and_then(Path::cast) |
369 | } | 365 | } |
370 | } | 366 | } |
371 | 367 | ||
372 | impl<'a> UseTree<'a> { | 368 | impl UseTree { |
373 | pub fn has_star(self) -> bool { | 369 | pub fn has_star(&self) -> bool { |
374 | self.syntax().children().any(|it| it.kind() == STAR) | 370 | self.syntax().children().any(|it| it.kind() == STAR) |
375 | } | 371 | } |
376 | } | 372 | } |
377 | 373 | ||
378 | impl<'a> UseTreeList<'a> { | 374 | impl UseTreeList { |
379 | pub fn parent_use_tree(self) -> UseTree<'a> { | 375 | pub fn parent_use_tree(&self) -> &UseTree { |
380 | self.syntax() | 376 | self.syntax() |
381 | .parent() | 377 | .parent() |
382 | .and_then(UseTree::cast) | 378 | .and_then(UseTree::cast) |
@@ -384,22 +380,22 @@ impl<'a> UseTreeList<'a> { | |||
384 | } | 380 | } |
385 | } | 381 | } |
386 | 382 | ||
387 | fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { | 383 | fn child_opt<P: AstNode, C: AstNode>(parent: &P) -> Option<&C> { |
388 | children(parent).next() | 384 | children(parent).next() |
389 | } | 385 | } |
390 | 386 | ||
391 | fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> { | 387 | fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> { |
392 | AstChildren::new(parent.syntax()) | 388 | AstChildren::new(parent.syntax()) |
393 | } | 389 | } |
394 | 390 | ||
395 | #[derive(Debug)] | 391 | #[derive(Debug)] |
396 | pub struct AstChildren<'a, N> { | 392 | pub struct AstChildren<'a, N> { |
397 | inner: SyntaxNodeChildren<RefRoot<'a>>, | 393 | inner: SyntaxNodeChildren<'a>, |
398 | ph: PhantomData<N>, | 394 | ph: PhantomData<N>, |
399 | } | 395 | } |
400 | 396 | ||
401 | impl<'a, N> AstChildren<'a, N> { | 397 | impl<'a, N> AstChildren<'a, N> { |
402 | fn new(parent: SyntaxNodeRef<'a>) -> Self { | 398 | fn new(parent: &'a SyntaxNode) -> Self { |
403 | AstChildren { | 399 | AstChildren { |
404 | inner: parent.children(), | 400 | inner: parent.children(), |
405 | ph: PhantomData, | 401 | ph: PhantomData, |
@@ -407,9 +403,9 @@ impl<'a, N> AstChildren<'a, N> { | |||
407 | } | 403 | } |
408 | } | 404 | } |
409 | 405 | ||
410 | impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | 406 | impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> { |
411 | type Item = N; | 407 | type Item = &'a N; |
412 | fn next(&mut self) -> Option<N> { | 408 | fn next(&mut self) -> Option<&'a N> { |
413 | loop { | 409 | loop { |
414 | if let Some(n) = N::cast(self.inner.next()?) { | 410 | if let Some(n) = N::cast(self.inner.next()?) { |
415 | return Some(n); | 411 | return Some(n); |
@@ -420,13 +416,13 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | |||
420 | 416 | ||
421 | #[derive(Debug, Clone, PartialEq, Eq)] | 417 | #[derive(Debug, Clone, PartialEq, Eq)] |
422 | pub enum StructFlavor<'a> { | 418 | pub enum StructFlavor<'a> { |
423 | Tuple(PosFieldList<'a>), | 419 | Tuple(&'a PosFieldList), |
424 | Named(NamedFieldDefList<'a>), | 420 | Named(&'a NamedFieldDefList), |
425 | Unit, | 421 | Unit, |
426 | } | 422 | } |
427 | 423 | ||
428 | impl<'a> StructFlavor<'a> { | 424 | impl StructFlavor<'_> { |
429 | fn from_node<N: AstNode<'a>>(node: N) -> StructFlavor<'a> { | 425 | fn from_node<N: AstNode>(node: &N) -> StructFlavor { |
430 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { | 426 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { |
431 | StructFlavor::Named(nfdl) | 427 | StructFlavor::Named(nfdl) |
432 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { | 428 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { |
@@ -437,31 +433,31 @@ impl<'a> StructFlavor<'a> { | |||
437 | } | 433 | } |
438 | } | 434 | } |
439 | 435 | ||
440 | impl<'a> StructDef<'a> { | 436 | impl StructDef { |
441 | pub fn flavor(self) -> StructFlavor<'a> { | 437 | pub fn flavor(&self) -> StructFlavor { |
442 | StructFlavor::from_node(self) | 438 | StructFlavor::from_node(self) |
443 | } | 439 | } |
444 | } | 440 | } |
445 | 441 | ||
446 | impl<'a> EnumVariant<'a> { | 442 | impl EnumVariant { |
447 | pub fn flavor(self) -> StructFlavor<'a> { | 443 | pub fn flavor(&self) -> StructFlavor { |
448 | StructFlavor::from_node(self) | 444 | StructFlavor::from_node(self) |
449 | } | 445 | } |
450 | } | 446 | } |
451 | 447 | ||
452 | impl<'a> PointerType<'a> { | 448 | impl PointerType { |
453 | pub fn is_mut(&self) -> bool { | 449 | pub fn is_mut(&self) -> bool { |
454 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 450 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
455 | } | 451 | } |
456 | } | 452 | } |
457 | 453 | ||
458 | impl<'a> ReferenceType<'a> { | 454 | impl ReferenceType { |
459 | pub fn is_mut(&self) -> bool { | 455 | pub fn is_mut(&self) -> bool { |
460 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 456 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
461 | } | 457 | } |
462 | } | 458 | } |
463 | 459 | ||
464 | impl<'a> RefExpr<'a> { | 460 | impl RefExpr { |
465 | pub fn is_mut(&self) -> bool { | 461 | pub fn is_mut(&self) -> bool { |
466 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 462 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
467 | } | 463 | } |
@@ -477,7 +473,7 @@ pub enum PrefixOp { | |||
477 | Neg, | 473 | Neg, |
478 | } | 474 | } |
479 | 475 | ||
480 | impl<'a> PrefixExpr<'a> { | 476 | impl PrefixExpr { |
481 | pub fn op(&self) -> Option<PrefixOp> { | 477 | pub fn op(&self) -> Option<PrefixOp> { |
482 | match self.syntax().first_child()?.kind() { | 478 | match self.syntax().first_child()?.kind() { |
483 | STAR => Some(PrefixOp::Deref), | 479 | STAR => Some(PrefixOp::Deref), |
@@ -552,7 +548,7 @@ pub enum BinOp { | |||
552 | BitXorAssign, | 548 | BitXorAssign, |
553 | } | 549 | } |
554 | 550 | ||
555 | impl<'a> BinExpr<'a> { | 551 | impl BinExpr { |
556 | pub fn op(&self) -> Option<BinOp> { | 552 | pub fn op(&self) -> Option<BinOp> { |
557 | self.syntax() | 553 | self.syntax() |
558 | .children() | 554 | .children() |
@@ -592,15 +588,15 @@ impl<'a> BinExpr<'a> { | |||
592 | .next() | 588 | .next() |
593 | } | 589 | } |
594 | 590 | ||
595 | pub fn lhs(self) -> Option<Expr<'a>> { | 591 | pub fn lhs(&self) -> Option<&Expr> { |
596 | children(self).nth(0) | 592 | children(self).nth(0) |
597 | } | 593 | } |
598 | 594 | ||
599 | pub fn rhs(self) -> Option<Expr<'a>> { | 595 | pub fn rhs(&self) -> Option<&Expr> { |
600 | children(self).nth(1) | 596 | children(self).nth(1) |
601 | } | 597 | } |
602 | 598 | ||
603 | pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) { | 599 | pub fn sub_exprs(&self) -> (Option<&Expr>, Option<&Expr>) { |
604 | let mut children = children(self); | 600 | let mut children = children(self); |
605 | let first = children.next(); | 601 | let first = children.next(); |
606 | let second = children.next(); | 602 | let second = children.next(); |
@@ -618,7 +614,7 @@ pub enum SelfParamFlavor { | |||
618 | MutRef, | 614 | MutRef, |
619 | } | 615 | } |
620 | 616 | ||
621 | impl<'a> SelfParam<'a> { | 617 | impl SelfParam { |
622 | pub fn flavor(&self) -> SelfParamFlavor { | 618 | pub fn flavor(&self) -> SelfParamFlavor { |
623 | let borrowed = self.syntax().children().any(|n| n.kind() == AMP); | 619 | let borrowed = self.syntax().children().any(|n| n.kind() == AMP); |
624 | if borrowed { | 620 | if borrowed { |
@@ -641,7 +637,7 @@ impl<'a> SelfParam<'a> { | |||
641 | 637 | ||
642 | #[test] | 638 | #[test] |
643 | fn test_doc_comment_of_items() { | 639 | fn test_doc_comment_of_items() { |
644 | let file = SourceFileNode::parse( | 640 | let file = SourceFile::parse( |
645 | r#" | 641 | r#" |
646 | //! doc | 642 | //! doc |
647 | // non-doc | 643 | // non-doc |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 24f72393a..5e96ab142 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -9,4648 +9,3387 @@ | |||
9 | 9 | ||
10 | #![cfg_attr(rustfmt, rustfmt_skip)] | 10 | #![cfg_attr(rustfmt, rustfmt_skip)] |
11 | 11 | ||
12 | use std::hash::{Hash, Hasher}; | 12 | use rowan::TransparentNewType; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | ast, | 15 | SyntaxNode, SyntaxKind::*, |
16 | SyntaxNode, SyntaxNodeRef, AstNode, | 16 | yellow::{RaTypes, TreePtr}, |
17 | yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot}, | 17 | ast::{self, AstNode}, |
18 | SyntaxKind::*, | ||
19 | }; | 18 | }; |
20 | 19 | ||
21 | // ArgList | 20 | // ArgList |
22 | #[derive(Debug, Clone, Copy,)] | 21 | #[derive(Debug, PartialEq, Eq, Hash)] |
23 | pub struct ArgListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 22 | #[repr(transparent)] |
24 | pub(crate) syntax: SyntaxNode<R>, | 23 | pub struct ArgList { |
24 | pub(crate) syntax: SyntaxNode, | ||
25 | } | 25 | } |
26 | pub type ArgList<'a> = ArgListNode<RefRoot<'a>>; | 26 | unsafe impl TransparentNewType for ArgList { |
27 | 27 | type Repr = rowan::SyntaxNode<RaTypes>; | |
28 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArgListNode<R1>> for ArgListNode<R2> { | ||
29 | fn eq(&self, other: &ArgListNode<R1>) -> bool { self.syntax == other.syntax } | ||
30 | } | ||
31 | impl<R: TreeRoot<RaTypes>> Eq for ArgListNode<R> {} | ||
32 | impl<R: TreeRoot<RaTypes>> Hash for ArgListNode<R> { | ||
33 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
34 | } | 28 | } |
35 | 29 | ||
36 | impl<'a> AstNode<'a> for ArgList<'a> { | 30 | impl AstNode for ArgList { |
37 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 31 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
38 | match syntax.kind() { | 32 | match syntax.kind() { |
39 | ARG_LIST => Some(ArgList { syntax }), | 33 | ARG_LIST => Some(ArgList::from_repr(syntax.into_repr())), |
40 | _ => None, | 34 | _ => None, |
41 | } | 35 | } |
42 | } | 36 | } |
43 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 37 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
44 | } | 38 | fn to_owned(&self) -> TreePtr<ArgList> { TreePtr::cast(self.syntax.to_owned()) } |
45 | |||
46 | impl<R: TreeRoot<RaTypes>> ArgListNode<R> { | ||
47 | pub fn borrowed(&self) -> ArgList { | ||
48 | ArgListNode { syntax: self.syntax.borrowed() } | ||
49 | } | ||
50 | pub fn owned(&self) -> ArgListNode { | ||
51 | ArgListNode { syntax: self.syntax.owned() } | ||
52 | } | ||
53 | } | 39 | } |
54 | 40 | ||
55 | 41 | ||
56 | impl<'a> ArgList<'a> { | 42 | impl ArgList { |
57 | pub fn args(self) -> impl Iterator<Item = Expr<'a>> + 'a { | 43 | pub fn args(&self) -> impl Iterator<Item = &Expr> { |
58 | super::children(self) | 44 | super::children(self) |
59 | } | 45 | } |
60 | } | 46 | } |
61 | 47 | ||
62 | // ArrayExpr | 48 | // ArrayExpr |
63 | #[derive(Debug, Clone, Copy,)] | 49 | #[derive(Debug, PartialEq, Eq, Hash)] |
64 | pub struct ArrayExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 50 | #[repr(transparent)] |
65 | pub(crate) syntax: SyntaxNode<R>, | 51 | pub struct ArrayExpr { |
52 | pub(crate) syntax: SyntaxNode, | ||
66 | } | 53 | } |
67 | pub type ArrayExpr<'a> = ArrayExprNode<RefRoot<'a>>; | 54 | unsafe impl TransparentNewType for ArrayExpr { |
68 | 55 | type Repr = rowan::SyntaxNode<RaTypes>; | |
69 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayExprNode<R1>> for ArrayExprNode<R2> { | ||
70 | fn eq(&self, other: &ArrayExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
71 | } | ||
72 | impl<R: TreeRoot<RaTypes>> Eq for ArrayExprNode<R> {} | ||
73 | impl<R: TreeRoot<RaTypes>> Hash for ArrayExprNode<R> { | ||
74 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
75 | } | 56 | } |
76 | 57 | ||
77 | impl<'a> AstNode<'a> for ArrayExpr<'a> { | 58 | impl AstNode for ArrayExpr { |
78 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 59 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
79 | match syntax.kind() { | 60 | match syntax.kind() { |
80 | ARRAY_EXPR => Some(ArrayExpr { syntax }), | 61 | ARRAY_EXPR => Some(ArrayExpr::from_repr(syntax.into_repr())), |
81 | _ => None, | 62 | _ => None, |
82 | } | 63 | } |
83 | } | 64 | } |
84 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 65 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
85 | } | 66 | fn to_owned(&self) -> TreePtr<ArrayExpr> { TreePtr::cast(self.syntax.to_owned()) } |
86 | |||
87 | impl<R: TreeRoot<RaTypes>> ArrayExprNode<R> { | ||
88 | pub fn borrowed(&self) -> ArrayExpr { | ||
89 | ArrayExprNode { syntax: self.syntax.borrowed() } | ||
90 | } | ||
91 | pub fn owned(&self) -> ArrayExprNode { | ||
92 | ArrayExprNode { syntax: self.syntax.owned() } | ||
93 | } | ||
94 | } | 67 | } |
95 | 68 | ||
96 | 69 | ||
97 | impl<'a> ArrayExpr<'a> {} | 70 | impl ArrayExpr {} |
98 | 71 | ||
99 | // ArrayType | 72 | // ArrayType |
100 | #[derive(Debug, Clone, Copy,)] | 73 | #[derive(Debug, PartialEq, Eq, Hash)] |
101 | pub struct ArrayTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 74 | #[repr(transparent)] |
102 | pub(crate) syntax: SyntaxNode<R>, | 75 | pub struct ArrayType { |
103 | } | 76 | pub(crate) syntax: SyntaxNode, |
104 | pub type ArrayType<'a> = ArrayTypeNode<RefRoot<'a>>; | ||
105 | |||
106 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayTypeNode<R1>> for ArrayTypeNode<R2> { | ||
107 | fn eq(&self, other: &ArrayTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
108 | } | 77 | } |
109 | impl<R: TreeRoot<RaTypes>> Eq for ArrayTypeNode<R> {} | 78 | unsafe impl TransparentNewType for ArrayType { |
110 | impl<R: TreeRoot<RaTypes>> Hash for ArrayTypeNode<R> { | 79 | type Repr = rowan::SyntaxNode<RaTypes>; |
111 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
112 | } | 80 | } |
113 | 81 | ||
114 | impl<'a> AstNode<'a> for ArrayType<'a> { | 82 | impl AstNode for ArrayType { |
115 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 83 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
116 | match syntax.kind() { | 84 | match syntax.kind() { |
117 | ARRAY_TYPE => Some(ArrayType { syntax }), | 85 | ARRAY_TYPE => Some(ArrayType::from_repr(syntax.into_repr())), |
118 | _ => None, | 86 | _ => None, |
119 | } | 87 | } |
120 | } | 88 | } |
121 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 89 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
90 | fn to_owned(&self) -> TreePtr<ArrayType> { TreePtr::cast(self.syntax.to_owned()) } | ||
122 | } | 91 | } |
123 | 92 | ||
124 | impl<R: TreeRoot<RaTypes>> ArrayTypeNode<R> { | ||
125 | pub fn borrowed(&self) -> ArrayType { | ||
126 | ArrayTypeNode { syntax: self.syntax.borrowed() } | ||
127 | } | ||
128 | pub fn owned(&self) -> ArrayTypeNode { | ||
129 | ArrayTypeNode { syntax: self.syntax.owned() } | ||
130 | } | ||
131 | } | ||
132 | 93 | ||
133 | 94 | impl ArrayType { | |
134 | impl<'a> ArrayType<'a> { | 95 | pub fn type_ref(&self) -> Option<&TypeRef> { |
135 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
136 | super::child_opt(self) | 96 | super::child_opt(self) |
137 | } | 97 | } |
138 | 98 | ||
139 | pub fn expr(self) -> Option<Expr<'a>> { | 99 | pub fn expr(&self) -> Option<&Expr> { |
140 | super::child_opt(self) | 100 | super::child_opt(self) |
141 | } | 101 | } |
142 | } | 102 | } |
143 | 103 | ||
144 | // Attr | 104 | // Attr |
145 | #[derive(Debug, Clone, Copy,)] | 105 | #[derive(Debug, PartialEq, Eq, Hash)] |
146 | pub struct AttrNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 106 | #[repr(transparent)] |
147 | pub(crate) syntax: SyntaxNode<R>, | 107 | pub struct Attr { |
148 | } | 108 | pub(crate) syntax: SyntaxNode, |
149 | pub type Attr<'a> = AttrNode<RefRoot<'a>>; | ||
150 | |||
151 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<AttrNode<R1>> for AttrNode<R2> { | ||
152 | fn eq(&self, other: &AttrNode<R1>) -> bool { self.syntax == other.syntax } | ||
153 | } | 109 | } |
154 | impl<R: TreeRoot<RaTypes>> Eq for AttrNode<R> {} | 110 | unsafe impl TransparentNewType for Attr { |
155 | impl<R: TreeRoot<RaTypes>> Hash for AttrNode<R> { | 111 | type Repr = rowan::SyntaxNode<RaTypes>; |
156 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
157 | } | 112 | } |
158 | 113 | ||
159 | impl<'a> AstNode<'a> for Attr<'a> { | 114 | impl AstNode for Attr { |
160 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 115 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
161 | match syntax.kind() { | 116 | match syntax.kind() { |
162 | ATTR => Some(Attr { syntax }), | 117 | ATTR => Some(Attr::from_repr(syntax.into_repr())), |
163 | _ => None, | 118 | _ => None, |
164 | } | 119 | } |
165 | } | 120 | } |
166 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 121 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
167 | } | 122 | fn to_owned(&self) -> TreePtr<Attr> { TreePtr::cast(self.syntax.to_owned()) } |
168 | |||
169 | impl<R: TreeRoot<RaTypes>> AttrNode<R> { | ||
170 | pub fn borrowed(&self) -> Attr { | ||
171 | AttrNode { syntax: self.syntax.borrowed() } | ||
172 | } | ||
173 | pub fn owned(&self) -> AttrNode { | ||
174 | AttrNode { syntax: self.syntax.owned() } | ||
175 | } | ||
176 | } | 123 | } |
177 | 124 | ||
178 | 125 | ||
179 | impl<'a> Attr<'a> { | 126 | impl Attr { |
180 | pub fn value(self) -> Option<TokenTree<'a>> { | 127 | pub fn value(&self) -> Option<&TokenTree> { |
181 | super::child_opt(self) | 128 | super::child_opt(self) |
182 | } | 129 | } |
183 | } | 130 | } |
184 | 131 | ||
185 | // BinExpr | 132 | // BinExpr |
186 | #[derive(Debug, Clone, Copy,)] | 133 | #[derive(Debug, PartialEq, Eq, Hash)] |
187 | pub struct BinExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 134 | #[repr(transparent)] |
188 | pub(crate) syntax: SyntaxNode<R>, | 135 | pub struct BinExpr { |
189 | } | 136 | pub(crate) syntax: SyntaxNode, |
190 | pub type BinExpr<'a> = BinExprNode<RefRoot<'a>>; | ||
191 | |||
192 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BinExprNode<R1>> for BinExprNode<R2> { | ||
193 | fn eq(&self, other: &BinExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
194 | } | 137 | } |
195 | impl<R: TreeRoot<RaTypes>> Eq for BinExprNode<R> {} | 138 | unsafe impl TransparentNewType for BinExpr { |
196 | impl<R: TreeRoot<RaTypes>> Hash for BinExprNode<R> { | 139 | type Repr = rowan::SyntaxNode<RaTypes>; |
197 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
198 | } | 140 | } |
199 | 141 | ||
200 | impl<'a> AstNode<'a> for BinExpr<'a> { | 142 | impl AstNode for BinExpr { |
201 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 143 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
202 | match syntax.kind() { | 144 | match syntax.kind() { |
203 | BIN_EXPR => Some(BinExpr { syntax }), | 145 | BIN_EXPR => Some(BinExpr::from_repr(syntax.into_repr())), |
204 | _ => None, | 146 | _ => None, |
205 | } | 147 | } |
206 | } | 148 | } |
207 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 149 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
208 | } | 150 | fn to_owned(&self) -> TreePtr<BinExpr> { TreePtr::cast(self.syntax.to_owned()) } |
209 | |||
210 | impl<R: TreeRoot<RaTypes>> BinExprNode<R> { | ||
211 | pub fn borrowed(&self) -> BinExpr { | ||
212 | BinExprNode { syntax: self.syntax.borrowed() } | ||
213 | } | ||
214 | pub fn owned(&self) -> BinExprNode { | ||
215 | BinExprNode { syntax: self.syntax.owned() } | ||
216 | } | ||
217 | } | 151 | } |
218 | 152 | ||
219 | 153 | ||
220 | impl<'a> BinExpr<'a> {} | 154 | impl BinExpr {} |
221 | 155 | ||
222 | // BindPat | 156 | // BindPat |
223 | #[derive(Debug, Clone, Copy,)] | 157 | #[derive(Debug, PartialEq, Eq, Hash)] |
224 | pub struct BindPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 158 | #[repr(transparent)] |
225 | pub(crate) syntax: SyntaxNode<R>, | 159 | pub struct BindPat { |
160 | pub(crate) syntax: SyntaxNode, | ||
226 | } | 161 | } |
227 | pub type BindPat<'a> = BindPatNode<RefRoot<'a>>; | 162 | unsafe impl TransparentNewType for BindPat { |
228 | 163 | type Repr = rowan::SyntaxNode<RaTypes>; | |
229 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BindPatNode<R1>> for BindPatNode<R2> { | ||
230 | fn eq(&self, other: &BindPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
231 | } | ||
232 | impl<R: TreeRoot<RaTypes>> Eq for BindPatNode<R> {} | ||
233 | impl<R: TreeRoot<RaTypes>> Hash for BindPatNode<R> { | ||
234 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
235 | } | 164 | } |
236 | 165 | ||
237 | impl<'a> AstNode<'a> for BindPat<'a> { | 166 | impl AstNode for BindPat { |
238 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 167 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
239 | match syntax.kind() { | 168 | match syntax.kind() { |
240 | BIND_PAT => Some(BindPat { syntax }), | 169 | BIND_PAT => Some(BindPat::from_repr(syntax.into_repr())), |
241 | _ => None, | 170 | _ => None, |
242 | } | 171 | } |
243 | } | 172 | } |
244 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 173 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
245 | } | 174 | fn to_owned(&self) -> TreePtr<BindPat> { TreePtr::cast(self.syntax.to_owned()) } |
246 | |||
247 | impl<R: TreeRoot<RaTypes>> BindPatNode<R> { | ||
248 | pub fn borrowed(&self) -> BindPat { | ||
249 | BindPatNode { syntax: self.syntax.borrowed() } | ||
250 | } | ||
251 | pub fn owned(&self) -> BindPatNode { | ||
252 | BindPatNode { syntax: self.syntax.owned() } | ||
253 | } | ||
254 | } | 175 | } |
255 | 176 | ||
256 | 177 | ||
257 | impl<'a> ast::NameOwner<'a> for BindPat<'a> {} | 178 | impl ast::NameOwner for BindPat {} |
258 | impl<'a> BindPat<'a> {} | 179 | impl BindPat {} |
259 | 180 | ||
260 | // Block | 181 | // Block |
261 | #[derive(Debug, Clone, Copy,)] | 182 | #[derive(Debug, PartialEq, Eq, Hash)] |
262 | pub struct BlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 183 | #[repr(transparent)] |
263 | pub(crate) syntax: SyntaxNode<R>, | 184 | pub struct Block { |
264 | } | 185 | pub(crate) syntax: SyntaxNode, |
265 | pub type Block<'a> = BlockNode<RefRoot<'a>>; | ||
266 | |||
267 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockNode<R1>> for BlockNode<R2> { | ||
268 | fn eq(&self, other: &BlockNode<R1>) -> bool { self.syntax == other.syntax } | ||
269 | } | 186 | } |
270 | impl<R: TreeRoot<RaTypes>> Eq for BlockNode<R> {} | 187 | unsafe impl TransparentNewType for Block { |
271 | impl<R: TreeRoot<RaTypes>> Hash for BlockNode<R> { | 188 | type Repr = rowan::SyntaxNode<RaTypes>; |
272 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
273 | } | 189 | } |
274 | 190 | ||
275 | impl<'a> AstNode<'a> for Block<'a> { | 191 | impl AstNode for Block { |
276 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 192 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
277 | match syntax.kind() { | 193 | match syntax.kind() { |
278 | BLOCK => Some(Block { syntax }), | 194 | BLOCK => Some(Block::from_repr(syntax.into_repr())), |
279 | _ => None, | 195 | _ => None, |
280 | } | 196 | } |
281 | } | 197 | } |
282 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 198 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
199 | fn to_owned(&self) -> TreePtr<Block> { TreePtr::cast(self.syntax.to_owned()) } | ||
283 | } | 200 | } |
284 | 201 | ||
285 | impl<R: TreeRoot<RaTypes>> BlockNode<R> { | ||
286 | pub fn borrowed(&self) -> Block { | ||
287 | BlockNode { syntax: self.syntax.borrowed() } | ||
288 | } | ||
289 | pub fn owned(&self) -> BlockNode { | ||
290 | BlockNode { syntax: self.syntax.owned() } | ||
291 | } | ||
292 | } | ||
293 | 202 | ||
294 | 203 | impl Block { | |
295 | impl<'a> Block<'a> { | 204 | pub fn statements(&self) -> impl Iterator<Item = &Stmt> { |
296 | pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a { | ||
297 | super::children(self) | 205 | super::children(self) |
298 | } | 206 | } |
299 | 207 | ||
300 | pub fn expr(self) -> Option<Expr<'a>> { | 208 | pub fn expr(&self) -> Option<&Expr> { |
301 | super::child_opt(self) | 209 | super::child_opt(self) |
302 | } | 210 | } |
303 | } | 211 | } |
304 | 212 | ||
305 | // BlockExpr | 213 | // BlockExpr |
306 | #[derive(Debug, Clone, Copy,)] | 214 | #[derive(Debug, PartialEq, Eq, Hash)] |
307 | pub struct BlockExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 215 | #[repr(transparent)] |
308 | pub(crate) syntax: SyntaxNode<R>, | 216 | pub struct BlockExpr { |
217 | pub(crate) syntax: SyntaxNode, | ||
309 | } | 218 | } |
310 | pub type BlockExpr<'a> = BlockExprNode<RefRoot<'a>>; | 219 | unsafe impl TransparentNewType for BlockExpr { |
311 | 220 | type Repr = rowan::SyntaxNode<RaTypes>; | |
312 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockExprNode<R1>> for BlockExprNode<R2> { | ||
313 | fn eq(&self, other: &BlockExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
314 | } | ||
315 | impl<R: TreeRoot<RaTypes>> Eq for BlockExprNode<R> {} | ||
316 | impl<R: TreeRoot<RaTypes>> Hash for BlockExprNode<R> { | ||
317 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
318 | } | 221 | } |
319 | 222 | ||
320 | impl<'a> AstNode<'a> for BlockExpr<'a> { | 223 | impl AstNode for BlockExpr { |
321 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 224 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
322 | match syntax.kind() { | 225 | match syntax.kind() { |
323 | BLOCK_EXPR => Some(BlockExpr { syntax }), | 226 | BLOCK_EXPR => Some(BlockExpr::from_repr(syntax.into_repr())), |
324 | _ => None, | 227 | _ => None, |
325 | } | 228 | } |
326 | } | 229 | } |
327 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 230 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
328 | } | 231 | fn to_owned(&self) -> TreePtr<BlockExpr> { TreePtr::cast(self.syntax.to_owned()) } |
329 | |||
330 | impl<R: TreeRoot<RaTypes>> BlockExprNode<R> { | ||
331 | pub fn borrowed(&self) -> BlockExpr { | ||
332 | BlockExprNode { syntax: self.syntax.borrowed() } | ||
333 | } | ||
334 | pub fn owned(&self) -> BlockExprNode { | ||
335 | BlockExprNode { syntax: self.syntax.owned() } | ||
336 | } | ||
337 | } | 232 | } |
338 | 233 | ||
339 | 234 | ||
340 | impl<'a> BlockExpr<'a> { | 235 | impl BlockExpr { |
341 | pub fn block(self) -> Option<Block<'a>> { | 236 | pub fn block(&self) -> Option<&Block> { |
342 | super::child_opt(self) | 237 | super::child_opt(self) |
343 | } | 238 | } |
344 | } | 239 | } |
345 | 240 | ||
346 | // BreakExpr | 241 | // BreakExpr |
347 | #[derive(Debug, Clone, Copy,)] | 242 | #[derive(Debug, PartialEq, Eq, Hash)] |
348 | pub struct BreakExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 243 | #[repr(transparent)] |
349 | pub(crate) syntax: SyntaxNode<R>, | 244 | pub struct BreakExpr { |
245 | pub(crate) syntax: SyntaxNode, | ||
350 | } | 246 | } |
351 | pub type BreakExpr<'a> = BreakExprNode<RefRoot<'a>>; | 247 | unsafe impl TransparentNewType for BreakExpr { |
352 | 248 | type Repr = rowan::SyntaxNode<RaTypes>; | |
353 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BreakExprNode<R1>> for BreakExprNode<R2> { | ||
354 | fn eq(&self, other: &BreakExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
355 | } | ||
356 | impl<R: TreeRoot<RaTypes>> Eq for BreakExprNode<R> {} | ||
357 | impl<R: TreeRoot<RaTypes>> Hash for BreakExprNode<R> { | ||
358 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
359 | } | 249 | } |
360 | 250 | ||
361 | impl<'a> AstNode<'a> for BreakExpr<'a> { | 251 | impl AstNode for BreakExpr { |
362 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 252 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
363 | match syntax.kind() { | 253 | match syntax.kind() { |
364 | BREAK_EXPR => Some(BreakExpr { syntax }), | 254 | BREAK_EXPR => Some(BreakExpr::from_repr(syntax.into_repr())), |
365 | _ => None, | 255 | _ => None, |
366 | } | 256 | } |
367 | } | 257 | } |
368 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 258 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
369 | } | 259 | fn to_owned(&self) -> TreePtr<BreakExpr> { TreePtr::cast(self.syntax.to_owned()) } |
370 | |||
371 | impl<R: TreeRoot<RaTypes>> BreakExprNode<R> { | ||
372 | pub fn borrowed(&self) -> BreakExpr { | ||
373 | BreakExprNode { syntax: self.syntax.borrowed() } | ||
374 | } | ||
375 | pub fn owned(&self) -> BreakExprNode { | ||
376 | BreakExprNode { syntax: self.syntax.owned() } | ||
377 | } | ||
378 | } | 260 | } |
379 | 261 | ||
380 | 262 | ||
381 | impl<'a> BreakExpr<'a> { | 263 | impl BreakExpr { |
382 | pub fn expr(self) -> Option<Expr<'a>> { | 264 | pub fn expr(&self) -> Option<&Expr> { |
383 | super::child_opt(self) | 265 | super::child_opt(self) |
384 | } | 266 | } |
385 | } | 267 | } |
386 | 268 | ||
387 | // Byte | 269 | // Byte |
388 | #[derive(Debug, Clone, Copy,)] | 270 | #[derive(Debug, PartialEq, Eq, Hash)] |
389 | pub struct ByteNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 271 | #[repr(transparent)] |
390 | pub(crate) syntax: SyntaxNode<R>, | 272 | pub struct Byte { |
273 | pub(crate) syntax: SyntaxNode, | ||
391 | } | 274 | } |
392 | pub type Byte<'a> = ByteNode<RefRoot<'a>>; | 275 | unsafe impl TransparentNewType for Byte { |
393 | 276 | type Repr = rowan::SyntaxNode<RaTypes>; | |
394 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteNode<R1>> for ByteNode<R2> { | ||
395 | fn eq(&self, other: &ByteNode<R1>) -> bool { self.syntax == other.syntax } | ||
396 | } | ||
397 | impl<R: TreeRoot<RaTypes>> Eq for ByteNode<R> {} | ||
398 | impl<R: TreeRoot<RaTypes>> Hash for ByteNode<R> { | ||
399 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
400 | } | 277 | } |
401 | 278 | ||
402 | impl<'a> AstNode<'a> for Byte<'a> { | 279 | impl AstNode for Byte { |
403 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 280 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
404 | match syntax.kind() { | 281 | match syntax.kind() { |
405 | BYTE => Some(Byte { syntax }), | 282 | BYTE => Some(Byte::from_repr(syntax.into_repr())), |
406 | _ => None, | 283 | _ => None, |
407 | } | 284 | } |
408 | } | 285 | } |
409 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 286 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
410 | } | 287 | fn to_owned(&self) -> TreePtr<Byte> { TreePtr::cast(self.syntax.to_owned()) } |
411 | |||
412 | impl<R: TreeRoot<RaTypes>> ByteNode<R> { | ||
413 | pub fn borrowed(&self) -> Byte { | ||
414 | ByteNode { syntax: self.syntax.borrowed() } | ||
415 | } | ||
416 | pub fn owned(&self) -> ByteNode { | ||
417 | ByteNode { syntax: self.syntax.owned() } | ||
418 | } | ||
419 | } | 288 | } |
420 | 289 | ||
421 | 290 | ||
422 | impl<'a> Byte<'a> {} | 291 | impl Byte {} |
423 | 292 | ||
424 | // ByteString | 293 | // ByteString |
425 | #[derive(Debug, Clone, Copy,)] | 294 | #[derive(Debug, PartialEq, Eq, Hash)] |
426 | pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 295 | #[repr(transparent)] |
427 | pub(crate) syntax: SyntaxNode<R>, | 296 | pub struct ByteString { |
428 | } | 297 | pub(crate) syntax: SyntaxNode, |
429 | pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>; | ||
430 | |||
431 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteStringNode<R1>> for ByteStringNode<R2> { | ||
432 | fn eq(&self, other: &ByteStringNode<R1>) -> bool { self.syntax == other.syntax } | ||
433 | } | 298 | } |
434 | impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {} | 299 | unsafe impl TransparentNewType for ByteString { |
435 | impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> { | 300 | type Repr = rowan::SyntaxNode<RaTypes>; |
436 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
437 | } | 301 | } |
438 | 302 | ||
439 | impl<'a> AstNode<'a> for ByteString<'a> { | 303 | impl AstNode for ByteString { |
440 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 304 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
441 | match syntax.kind() { | 305 | match syntax.kind() { |
442 | BYTE_STRING => Some(ByteString { syntax }), | 306 | BYTE_STRING => Some(ByteString::from_repr(syntax.into_repr())), |
443 | _ => None, | 307 | _ => None, |
444 | } | 308 | } |
445 | } | 309 | } |
446 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 310 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
447 | } | 311 | fn to_owned(&self) -> TreePtr<ByteString> { TreePtr::cast(self.syntax.to_owned()) } |
448 | |||
449 | impl<R: TreeRoot<RaTypes>> ByteStringNode<R> { | ||
450 | pub fn borrowed(&self) -> ByteString { | ||
451 | ByteStringNode { syntax: self.syntax.borrowed() } | ||
452 | } | ||
453 | pub fn owned(&self) -> ByteStringNode { | ||
454 | ByteStringNode { syntax: self.syntax.owned() } | ||
455 | } | ||
456 | } | 312 | } |
457 | 313 | ||
458 | 314 | ||
459 | impl<'a> ByteString<'a> {} | 315 | impl ByteString {} |
460 | 316 | ||
461 | // CallExpr | 317 | // CallExpr |
462 | #[derive(Debug, Clone, Copy,)] | 318 | #[derive(Debug, PartialEq, Eq, Hash)] |
463 | pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 319 | #[repr(transparent)] |
464 | pub(crate) syntax: SyntaxNode<R>, | 320 | pub struct CallExpr { |
465 | } | 321 | pub(crate) syntax: SyntaxNode, |
466 | pub type CallExpr<'a> = CallExprNode<RefRoot<'a>>; | ||
467 | |||
468 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CallExprNode<R1>> for CallExprNode<R2> { | ||
469 | fn eq(&self, other: &CallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
470 | } | 322 | } |
471 | impl<R: TreeRoot<RaTypes>> Eq for CallExprNode<R> {} | 323 | unsafe impl TransparentNewType for CallExpr { |
472 | impl<R: TreeRoot<RaTypes>> Hash for CallExprNode<R> { | 324 | type Repr = rowan::SyntaxNode<RaTypes>; |
473 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
474 | } | 325 | } |
475 | 326 | ||
476 | impl<'a> AstNode<'a> for CallExpr<'a> { | 327 | impl AstNode for CallExpr { |
477 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 328 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
478 | match syntax.kind() { | 329 | match syntax.kind() { |
479 | CALL_EXPR => Some(CallExpr { syntax }), | 330 | CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())), |
480 | _ => None, | 331 | _ => None, |
481 | } | 332 | } |
482 | } | 333 | } |
483 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 334 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
484 | } | 335 | fn to_owned(&self) -> TreePtr<CallExpr> { TreePtr::cast(self.syntax.to_owned()) } |
485 | |||
486 | impl<R: TreeRoot<RaTypes>> CallExprNode<R> { | ||
487 | pub fn borrowed(&self) -> CallExpr { | ||
488 | CallExprNode { syntax: self.syntax.borrowed() } | ||
489 | } | ||
490 | pub fn owned(&self) -> CallExprNode { | ||
491 | CallExprNode { syntax: self.syntax.owned() } | ||
492 | } | ||
493 | } | 336 | } |
494 | 337 | ||
495 | 338 | ||
496 | impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} | 339 | impl ast::ArgListOwner for CallExpr {} |
497 | impl<'a> CallExpr<'a> { | 340 | impl CallExpr { |
498 | pub fn expr(self) -> Option<Expr<'a>> { | 341 | pub fn expr(&self) -> Option<&Expr> { |
499 | super::child_opt(self) | 342 | super::child_opt(self) |
500 | } | 343 | } |
501 | } | 344 | } |
502 | 345 | ||
503 | // CastExpr | 346 | // CastExpr |
504 | #[derive(Debug, Clone, Copy,)] | 347 | #[derive(Debug, PartialEq, Eq, Hash)] |
505 | pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 348 | #[repr(transparent)] |
506 | pub(crate) syntax: SyntaxNode<R>, | 349 | pub struct CastExpr { |
350 | pub(crate) syntax: SyntaxNode, | ||
507 | } | 351 | } |
508 | pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; | 352 | unsafe impl TransparentNewType for CastExpr { |
509 | 353 | type Repr = rowan::SyntaxNode<RaTypes>; | |
510 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CastExprNode<R1>> for CastExprNode<R2> { | ||
511 | fn eq(&self, other: &CastExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
512 | } | ||
513 | impl<R: TreeRoot<RaTypes>> Eq for CastExprNode<R> {} | ||
514 | impl<R: TreeRoot<RaTypes>> Hash for CastExprNode<R> { | ||
515 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
516 | } | 354 | } |
517 | 355 | ||
518 | impl<'a> AstNode<'a> for CastExpr<'a> { | 356 | impl AstNode for CastExpr { |
519 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 357 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
520 | match syntax.kind() { | 358 | match syntax.kind() { |
521 | CAST_EXPR => Some(CastExpr { syntax }), | 359 | CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())), |
522 | _ => None, | 360 | _ => None, |
523 | } | 361 | } |
524 | } | 362 | } |
525 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 363 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
526 | } | 364 | fn to_owned(&self) -> TreePtr<CastExpr> { TreePtr::cast(self.syntax.to_owned()) } |
527 | |||
528 | impl<R: TreeRoot<RaTypes>> CastExprNode<R> { | ||
529 | pub fn borrowed(&self) -> CastExpr { | ||
530 | CastExprNode { syntax: self.syntax.borrowed() } | ||
531 | } | ||
532 | pub fn owned(&self) -> CastExprNode { | ||
533 | CastExprNode { syntax: self.syntax.owned() } | ||
534 | } | ||
535 | } | 365 | } |
536 | 366 | ||
537 | 367 | ||
538 | impl<'a> CastExpr<'a> { | 368 | impl CastExpr { |
539 | pub fn expr(self) -> Option<Expr<'a>> { | 369 | pub fn expr(&self) -> Option<&Expr> { |
540 | super::child_opt(self) | 370 | super::child_opt(self) |
541 | } | 371 | } |
542 | 372 | ||
543 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 373 | pub fn type_ref(&self) -> Option<&TypeRef> { |
544 | super::child_opt(self) | 374 | super::child_opt(self) |
545 | } | 375 | } |
546 | } | 376 | } |
547 | 377 | ||
548 | // Char | 378 | // Char |
549 | #[derive(Debug, Clone, Copy,)] | 379 | #[derive(Debug, PartialEq, Eq, Hash)] |
550 | pub struct CharNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 380 | #[repr(transparent)] |
551 | pub(crate) syntax: SyntaxNode<R>, | 381 | pub struct Char { |
552 | } | 382 | pub(crate) syntax: SyntaxNode, |
553 | pub type Char<'a> = CharNode<RefRoot<'a>>; | ||
554 | |||
555 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CharNode<R1>> for CharNode<R2> { | ||
556 | fn eq(&self, other: &CharNode<R1>) -> bool { self.syntax == other.syntax } | ||
557 | } | 383 | } |
558 | impl<R: TreeRoot<RaTypes>> Eq for CharNode<R> {} | 384 | unsafe impl TransparentNewType for Char { |
559 | impl<R: TreeRoot<RaTypes>> Hash for CharNode<R> { | 385 | type Repr = rowan::SyntaxNode<RaTypes>; |
560 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
561 | } | 386 | } |
562 | 387 | ||
563 | impl<'a> AstNode<'a> for Char<'a> { | 388 | impl AstNode for Char { |
564 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 389 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
565 | match syntax.kind() { | 390 | match syntax.kind() { |
566 | CHAR => Some(Char { syntax }), | 391 | CHAR => Some(Char::from_repr(syntax.into_repr())), |
567 | _ => None, | 392 | _ => None, |
568 | } | 393 | } |
569 | } | 394 | } |
570 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 395 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
396 | fn to_owned(&self) -> TreePtr<Char> { TreePtr::cast(self.syntax.to_owned()) } | ||
571 | } | 397 | } |
572 | 398 | ||
573 | impl<R: TreeRoot<RaTypes>> CharNode<R> { | ||
574 | pub fn borrowed(&self) -> Char { | ||
575 | CharNode { syntax: self.syntax.borrowed() } | ||
576 | } | ||
577 | pub fn owned(&self) -> CharNode { | ||
578 | CharNode { syntax: self.syntax.owned() } | ||
579 | } | ||
580 | } | ||
581 | 399 | ||
582 | 400 | impl Char {} | |
583 | impl<'a> Char<'a> {} | ||
584 | 401 | ||
585 | // Comment | 402 | // Comment |
586 | #[derive(Debug, Clone, Copy,)] | 403 | #[derive(Debug, PartialEq, Eq, Hash)] |
587 | pub struct CommentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 404 | #[repr(transparent)] |
588 | pub(crate) syntax: SyntaxNode<R>, | 405 | pub struct Comment { |
589 | } | 406 | pub(crate) syntax: SyntaxNode, |
590 | pub type Comment<'a> = CommentNode<RefRoot<'a>>; | ||
591 | |||
592 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CommentNode<R1>> for CommentNode<R2> { | ||
593 | fn eq(&self, other: &CommentNode<R1>) -> bool { self.syntax == other.syntax } | ||
594 | } | 407 | } |
595 | impl<R: TreeRoot<RaTypes>> Eq for CommentNode<R> {} | 408 | unsafe impl TransparentNewType for Comment { |
596 | impl<R: TreeRoot<RaTypes>> Hash for CommentNode<R> { | 409 | type Repr = rowan::SyntaxNode<RaTypes>; |
597 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
598 | } | 410 | } |
599 | 411 | ||
600 | impl<'a> AstNode<'a> for Comment<'a> { | 412 | impl AstNode for Comment { |
601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 413 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
602 | match syntax.kind() { | 414 | match syntax.kind() { |
603 | COMMENT => Some(Comment { syntax }), | 415 | COMMENT => Some(Comment::from_repr(syntax.into_repr())), |
604 | _ => None, | 416 | _ => None, |
605 | } | 417 | } |
606 | } | 418 | } |
607 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 419 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
608 | } | 420 | fn to_owned(&self) -> TreePtr<Comment> { TreePtr::cast(self.syntax.to_owned()) } |
609 | |||
610 | impl<R: TreeRoot<RaTypes>> CommentNode<R> { | ||
611 | pub fn borrowed(&self) -> Comment { | ||
612 | CommentNode { syntax: self.syntax.borrowed() } | ||
613 | } | ||
614 | pub fn owned(&self) -> CommentNode { | ||
615 | CommentNode { syntax: self.syntax.owned() } | ||
616 | } | ||
617 | } | 421 | } |
618 | 422 | ||
619 | 423 | ||
620 | impl<'a> Comment<'a> {} | 424 | impl Comment {} |
621 | 425 | ||
622 | // Condition | 426 | // Condition |
623 | #[derive(Debug, Clone, Copy,)] | 427 | #[derive(Debug, PartialEq, Eq, Hash)] |
624 | pub struct ConditionNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 428 | #[repr(transparent)] |
625 | pub(crate) syntax: SyntaxNode<R>, | 429 | pub struct Condition { |
430 | pub(crate) syntax: SyntaxNode, | ||
626 | } | 431 | } |
627 | pub type Condition<'a> = ConditionNode<RefRoot<'a>>; | 432 | unsafe impl TransparentNewType for Condition { |
628 | 433 | type Repr = rowan::SyntaxNode<RaTypes>; | |
629 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConditionNode<R1>> for ConditionNode<R2> { | ||
630 | fn eq(&self, other: &ConditionNode<R1>) -> bool { self.syntax == other.syntax } | ||
631 | } | ||
632 | impl<R: TreeRoot<RaTypes>> Eq for ConditionNode<R> {} | ||
633 | impl<R: TreeRoot<RaTypes>> Hash for ConditionNode<R> { | ||
634 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
635 | } | 434 | } |
636 | 435 | ||
637 | impl<'a> AstNode<'a> for Condition<'a> { | 436 | impl AstNode for Condition { |
638 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 437 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
639 | match syntax.kind() { | 438 | match syntax.kind() { |
640 | CONDITION => Some(Condition { syntax }), | 439 | CONDITION => Some(Condition::from_repr(syntax.into_repr())), |
641 | _ => None, | 440 | _ => None, |
642 | } | 441 | } |
643 | } | 442 | } |
644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 443 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
645 | } | 444 | fn to_owned(&self) -> TreePtr<Condition> { TreePtr::cast(self.syntax.to_owned()) } |
646 | |||
647 | impl<R: TreeRoot<RaTypes>> ConditionNode<R> { | ||
648 | pub fn borrowed(&self) -> Condition { | ||
649 | ConditionNode { syntax: self.syntax.borrowed() } | ||
650 | } | ||
651 | pub fn owned(&self) -> ConditionNode { | ||
652 | ConditionNode { syntax: self.syntax.owned() } | ||
653 | } | ||
654 | } | 445 | } |
655 | 446 | ||
656 | 447 | ||
657 | impl<'a> Condition<'a> { | 448 | impl Condition { |
658 | pub fn pat(self) -> Option<Pat<'a>> { | 449 | pub fn pat(&self) -> Option<&Pat> { |
659 | super::child_opt(self) | 450 | super::child_opt(self) |
660 | } | 451 | } |
661 | 452 | ||
662 | pub fn expr(self) -> Option<Expr<'a>> { | 453 | pub fn expr(&self) -> Option<&Expr> { |
663 | super::child_opt(self) | 454 | super::child_opt(self) |
664 | } | 455 | } |
665 | } | 456 | } |
666 | 457 | ||
667 | // ConstDef | 458 | // ConstDef |
668 | #[derive(Debug, Clone, Copy,)] | 459 | #[derive(Debug, PartialEq, Eq, Hash)] |
669 | pub struct ConstDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 460 | #[repr(transparent)] |
670 | pub(crate) syntax: SyntaxNode<R>, | 461 | pub struct ConstDef { |
462 | pub(crate) syntax: SyntaxNode, | ||
671 | } | 463 | } |
672 | pub type ConstDef<'a> = ConstDefNode<RefRoot<'a>>; | 464 | unsafe impl TransparentNewType for ConstDef { |
673 | 465 | type Repr = rowan::SyntaxNode<RaTypes>; | |
674 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConstDefNode<R1>> for ConstDefNode<R2> { | ||
675 | fn eq(&self, other: &ConstDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
676 | } | ||
677 | impl<R: TreeRoot<RaTypes>> Eq for ConstDefNode<R> {} | ||
678 | impl<R: TreeRoot<RaTypes>> Hash for ConstDefNode<R> { | ||
679 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
680 | } | 466 | } |
681 | 467 | ||
682 | impl<'a> AstNode<'a> for ConstDef<'a> { | 468 | impl AstNode for ConstDef { |
683 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 469 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
684 | match syntax.kind() { | 470 | match syntax.kind() { |
685 | CONST_DEF => Some(ConstDef { syntax }), | 471 | CONST_DEF => Some(ConstDef::from_repr(syntax.into_repr())), |
686 | _ => None, | 472 | _ => None, |
687 | } | 473 | } |
688 | } | 474 | } |
689 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 475 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
690 | } | 476 | fn to_owned(&self) -> TreePtr<ConstDef> { TreePtr::cast(self.syntax.to_owned()) } |
691 | |||
692 | impl<R: TreeRoot<RaTypes>> ConstDefNode<R> { | ||
693 | pub fn borrowed(&self) -> ConstDef { | ||
694 | ConstDefNode { syntax: self.syntax.borrowed() } | ||
695 | } | ||
696 | pub fn owned(&self) -> ConstDefNode { | ||
697 | ConstDefNode { syntax: self.syntax.owned() } | ||
698 | } | ||
699 | } | 477 | } |
700 | 478 | ||
701 | 479 | ||
702 | impl<'a> ast::VisibilityOwner<'a> for ConstDef<'a> {} | 480 | impl ast::VisibilityOwner for ConstDef {} |
703 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} | 481 | impl ast::NameOwner for ConstDef {} |
704 | impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} | 482 | impl ast::TypeParamsOwner for ConstDef {} |
705 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} | 483 | impl ast::AttrsOwner for ConstDef {} |
706 | impl<'a> ast::DocCommentsOwner<'a> for ConstDef<'a> {} | 484 | impl ast::DocCommentsOwner for ConstDef {} |
707 | impl<'a> ConstDef<'a> {} | 485 | impl ConstDef {} |
708 | 486 | ||
709 | // ContinueExpr | 487 | // ContinueExpr |
710 | #[derive(Debug, Clone, Copy,)] | 488 | #[derive(Debug, PartialEq, Eq, Hash)] |
711 | pub struct ContinueExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 489 | #[repr(transparent)] |
712 | pub(crate) syntax: SyntaxNode<R>, | 490 | pub struct ContinueExpr { |
491 | pub(crate) syntax: SyntaxNode, | ||
713 | } | 492 | } |
714 | pub type ContinueExpr<'a> = ContinueExprNode<RefRoot<'a>>; | 493 | unsafe impl TransparentNewType for ContinueExpr { |
715 | 494 | type Repr = rowan::SyntaxNode<RaTypes>; | |
716 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ContinueExprNode<R1>> for ContinueExprNode<R2> { | ||
717 | fn eq(&self, other: &ContinueExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
718 | } | ||
719 | impl<R: TreeRoot<RaTypes>> Eq for ContinueExprNode<R> {} | ||
720 | impl<R: TreeRoot<RaTypes>> Hash for ContinueExprNode<R> { | ||
721 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
722 | } | 495 | } |
723 | 496 | ||
724 | impl<'a> AstNode<'a> for ContinueExpr<'a> { | 497 | impl AstNode for ContinueExpr { |
725 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 498 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
726 | match syntax.kind() { | 499 | match syntax.kind() { |
727 | CONTINUE_EXPR => Some(ContinueExpr { syntax }), | 500 | CONTINUE_EXPR => Some(ContinueExpr::from_repr(syntax.into_repr())), |
728 | _ => None, | 501 | _ => None, |
729 | } | 502 | } |
730 | } | 503 | } |
731 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 504 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
505 | fn to_owned(&self) -> TreePtr<ContinueExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
732 | } | 506 | } |
733 | 507 | ||
734 | impl<R: TreeRoot<RaTypes>> ContinueExprNode<R> { | ||
735 | pub fn borrowed(&self) -> ContinueExpr { | ||
736 | ContinueExprNode { syntax: self.syntax.borrowed() } | ||
737 | } | ||
738 | pub fn owned(&self) -> ContinueExprNode { | ||
739 | ContinueExprNode { syntax: self.syntax.owned() } | ||
740 | } | ||
741 | } | ||
742 | 508 | ||
743 | 509 | impl ContinueExpr {} | |
744 | impl<'a> ContinueExpr<'a> {} | ||
745 | 510 | ||
746 | // DynTraitType | 511 | // DynTraitType |
747 | #[derive(Debug, Clone, Copy,)] | 512 | #[derive(Debug, PartialEq, Eq, Hash)] |
748 | pub struct DynTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 513 | #[repr(transparent)] |
749 | pub(crate) syntax: SyntaxNode<R>, | 514 | pub struct DynTraitType { |
750 | } | 515 | pub(crate) syntax: SyntaxNode, |
751 | pub type DynTraitType<'a> = DynTraitTypeNode<RefRoot<'a>>; | ||
752 | |||
753 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<DynTraitTypeNode<R1>> for DynTraitTypeNode<R2> { | ||
754 | fn eq(&self, other: &DynTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
755 | } | 516 | } |
756 | impl<R: TreeRoot<RaTypes>> Eq for DynTraitTypeNode<R> {} | 517 | unsafe impl TransparentNewType for DynTraitType { |
757 | impl<R: TreeRoot<RaTypes>> Hash for DynTraitTypeNode<R> { | 518 | type Repr = rowan::SyntaxNode<RaTypes>; |
758 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
759 | } | 519 | } |
760 | 520 | ||
761 | impl<'a> AstNode<'a> for DynTraitType<'a> { | 521 | impl AstNode for DynTraitType { |
762 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 522 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
763 | match syntax.kind() { | 523 | match syntax.kind() { |
764 | DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), | 524 | DYN_TRAIT_TYPE => Some(DynTraitType::from_repr(syntax.into_repr())), |
765 | _ => None, | 525 | _ => None, |
766 | } | 526 | } |
767 | } | 527 | } |
768 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 528 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
529 | fn to_owned(&self) -> TreePtr<DynTraitType> { TreePtr::cast(self.syntax.to_owned()) } | ||
769 | } | 530 | } |
770 | 531 | ||
771 | impl<R: TreeRoot<RaTypes>> DynTraitTypeNode<R> { | ||
772 | pub fn borrowed(&self) -> DynTraitType { | ||
773 | DynTraitTypeNode { syntax: self.syntax.borrowed() } | ||
774 | } | ||
775 | pub fn owned(&self) -> DynTraitTypeNode { | ||
776 | DynTraitTypeNode { syntax: self.syntax.owned() } | ||
777 | } | ||
778 | } | ||
779 | 532 | ||
780 | 533 | impl DynTraitType {} | |
781 | impl<'a> DynTraitType<'a> {} | ||
782 | 534 | ||
783 | // EnumDef | 535 | // EnumDef |
784 | #[derive(Debug, Clone, Copy,)] | 536 | #[derive(Debug, PartialEq, Eq, Hash)] |
785 | pub struct EnumDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 537 | #[repr(transparent)] |
786 | pub(crate) syntax: SyntaxNode<R>, | 538 | pub struct EnumDef { |
787 | } | 539 | pub(crate) syntax: SyntaxNode, |
788 | pub type EnumDef<'a> = EnumDefNode<RefRoot<'a>>; | ||
789 | |||
790 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumDefNode<R1>> for EnumDefNode<R2> { | ||
791 | fn eq(&self, other: &EnumDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
792 | } | 540 | } |
793 | impl<R: TreeRoot<RaTypes>> Eq for EnumDefNode<R> {} | 541 | unsafe impl TransparentNewType for EnumDef { |
794 | impl<R: TreeRoot<RaTypes>> Hash for EnumDefNode<R> { | 542 | type Repr = rowan::SyntaxNode<RaTypes>; |
795 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
796 | } | 543 | } |
797 | 544 | ||
798 | impl<'a> AstNode<'a> for EnumDef<'a> { | 545 | impl AstNode for EnumDef { |
799 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 546 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
800 | match syntax.kind() { | 547 | match syntax.kind() { |
801 | ENUM_DEF => Some(EnumDef { syntax }), | 548 | ENUM_DEF => Some(EnumDef::from_repr(syntax.into_repr())), |
802 | _ => None, | 549 | _ => None, |
803 | } | 550 | } |
804 | } | 551 | } |
805 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 552 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
806 | } | 553 | fn to_owned(&self) -> TreePtr<EnumDef> { TreePtr::cast(self.syntax.to_owned()) } |
807 | |||
808 | impl<R: TreeRoot<RaTypes>> EnumDefNode<R> { | ||
809 | pub fn borrowed(&self) -> EnumDef { | ||
810 | EnumDefNode { syntax: self.syntax.borrowed() } | ||
811 | } | ||
812 | pub fn owned(&self) -> EnumDefNode { | ||
813 | EnumDefNode { syntax: self.syntax.owned() } | ||
814 | } | ||
815 | } | 554 | } |
816 | 555 | ||
817 | 556 | ||
818 | impl<'a> ast::VisibilityOwner<'a> for EnumDef<'a> {} | 557 | impl ast::VisibilityOwner for EnumDef {} |
819 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} | 558 | impl ast::NameOwner for EnumDef {} |
820 | impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} | 559 | impl ast::TypeParamsOwner for EnumDef {} |
821 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} | 560 | impl ast::AttrsOwner for EnumDef {} |
822 | impl<'a> ast::DocCommentsOwner<'a> for EnumDef<'a> {} | 561 | impl ast::DocCommentsOwner for EnumDef {} |
823 | impl<'a> EnumDef<'a> { | 562 | impl EnumDef { |
824 | pub fn variant_list(self) -> Option<EnumVariantList<'a>> { | 563 | pub fn variant_list(&self) -> Option<&EnumVariantList> { |
825 | super::child_opt(self) | 564 | super::child_opt(self) |
826 | } | 565 | } |
827 | } | 566 | } |
828 | 567 | ||
829 | // EnumVariant | 568 | // EnumVariant |
830 | #[derive(Debug, Clone, Copy,)] | 569 | #[derive(Debug, PartialEq, Eq, Hash)] |
831 | pub struct EnumVariantNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 570 | #[repr(transparent)] |
832 | pub(crate) syntax: SyntaxNode<R>, | 571 | pub struct EnumVariant { |
572 | pub(crate) syntax: SyntaxNode, | ||
833 | } | 573 | } |
834 | pub type EnumVariant<'a> = EnumVariantNode<RefRoot<'a>>; | 574 | unsafe impl TransparentNewType for EnumVariant { |
835 | 575 | type Repr = rowan::SyntaxNode<RaTypes>; | |
836 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumVariantNode<R1>> for EnumVariantNode<R2> { | ||
837 | fn eq(&self, other: &EnumVariantNode<R1>) -> bool { self.syntax == other.syntax } | ||
838 | } | ||
839 | impl<R: TreeRoot<RaTypes>> Eq for EnumVariantNode<R> {} | ||
840 | impl<R: TreeRoot<RaTypes>> Hash for EnumVariantNode<R> { | ||
841 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
842 | } | 576 | } |
843 | 577 | ||
844 | impl<'a> AstNode<'a> for EnumVariant<'a> { | 578 | impl AstNode for EnumVariant { |
845 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 579 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
846 | match syntax.kind() { | 580 | match syntax.kind() { |
847 | ENUM_VARIANT => Some(EnumVariant { syntax }), | 581 | ENUM_VARIANT => Some(EnumVariant::from_repr(syntax.into_repr())), |
848 | _ => None, | 582 | _ => None, |
849 | } | 583 | } |
850 | } | 584 | } |
851 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 585 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
852 | } | 586 | fn to_owned(&self) -> TreePtr<EnumVariant> { TreePtr::cast(self.syntax.to_owned()) } |
853 | |||
854 | impl<R: TreeRoot<RaTypes>> EnumVariantNode<R> { | ||
855 | pub fn borrowed(&self) -> EnumVariant { | ||
856 | EnumVariantNode { syntax: self.syntax.borrowed() } | ||
857 | } | ||
858 | pub fn owned(&self) -> EnumVariantNode { | ||
859 | EnumVariantNode { syntax: self.syntax.owned() } | ||
860 | } | ||
861 | } | 587 | } |
862 | 588 | ||
863 | 589 | ||
864 | impl<'a> ast::NameOwner<'a> for EnumVariant<'a> {} | 590 | impl ast::NameOwner for EnumVariant {} |
865 | impl<'a> EnumVariant<'a> { | 591 | impl EnumVariant { |
866 | pub fn expr(self) -> Option<Expr<'a>> { | 592 | pub fn expr(&self) -> Option<&Expr> { |
867 | super::child_opt(self) | 593 | super::child_opt(self) |
868 | } | 594 | } |
869 | } | 595 | } |
870 | 596 | ||
871 | // EnumVariantList | 597 | // EnumVariantList |
872 | #[derive(Debug, Clone, Copy,)] | 598 | #[derive(Debug, PartialEq, Eq, Hash)] |
873 | pub struct EnumVariantListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 599 | #[repr(transparent)] |
874 | pub(crate) syntax: SyntaxNode<R>, | 600 | pub struct EnumVariantList { |
875 | } | 601 | pub(crate) syntax: SyntaxNode, |
876 | pub type EnumVariantList<'a> = EnumVariantListNode<RefRoot<'a>>; | ||
877 | |||
878 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumVariantListNode<R1>> for EnumVariantListNode<R2> { | ||
879 | fn eq(&self, other: &EnumVariantListNode<R1>) -> bool { self.syntax == other.syntax } | ||
880 | } | 602 | } |
881 | impl<R: TreeRoot<RaTypes>> Eq for EnumVariantListNode<R> {} | 603 | unsafe impl TransparentNewType for EnumVariantList { |
882 | impl<R: TreeRoot<RaTypes>> Hash for EnumVariantListNode<R> { | 604 | type Repr = rowan::SyntaxNode<RaTypes>; |
883 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
884 | } | 605 | } |
885 | 606 | ||
886 | impl<'a> AstNode<'a> for EnumVariantList<'a> { | 607 | impl AstNode for EnumVariantList { |
887 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 608 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
888 | match syntax.kind() { | 609 | match syntax.kind() { |
889 | ENUM_VARIANT_LIST => Some(EnumVariantList { syntax }), | 610 | ENUM_VARIANT_LIST => Some(EnumVariantList::from_repr(syntax.into_repr())), |
890 | _ => None, | 611 | _ => None, |
891 | } | 612 | } |
892 | } | 613 | } |
893 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 614 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
615 | fn to_owned(&self) -> TreePtr<EnumVariantList> { TreePtr::cast(self.syntax.to_owned()) } | ||
894 | } | 616 | } |
895 | 617 | ||
896 | impl<R: TreeRoot<RaTypes>> EnumVariantListNode<R> { | ||
897 | pub fn borrowed(&self) -> EnumVariantList { | ||
898 | EnumVariantListNode { syntax: self.syntax.borrowed() } | ||
899 | } | ||
900 | pub fn owned(&self) -> EnumVariantListNode { | ||
901 | EnumVariantListNode { syntax: self.syntax.owned() } | ||
902 | } | ||
903 | } | ||
904 | 618 | ||
905 | 619 | impl EnumVariantList { | |
906 | impl<'a> EnumVariantList<'a> { | 620 | pub fn variants(&self) -> impl Iterator<Item = &EnumVariant> { |
907 | pub fn variants(self) -> impl Iterator<Item = EnumVariant<'a>> + 'a { | ||
908 | super::children(self) | 621 | super::children(self) |
909 | } | 622 | } |
910 | } | 623 | } |
911 | 624 | ||
912 | // Expr | 625 | // Expr |
913 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 626 | #[derive(Debug, PartialEq, Eq, Hash)] |
914 | pub enum Expr<'a> { | 627 | #[repr(transparent)] |
915 | TupleExpr(TupleExpr<'a>), | 628 | pub struct Expr { |
916 | ArrayExpr(ArrayExpr<'a>), | 629 | pub(crate) syntax: SyntaxNode, |
917 | ParenExpr(ParenExpr<'a>), | 630 | } |
918 | PathExpr(PathExpr<'a>), | 631 | unsafe impl TransparentNewType for Expr { |
919 | LambdaExpr(LambdaExpr<'a>), | 632 | type Repr = rowan::SyntaxNode<RaTypes>; |
920 | IfExpr(IfExpr<'a>), | ||
921 | LoopExpr(LoopExpr<'a>), | ||
922 | ForExpr(ForExpr<'a>), | ||
923 | WhileExpr(WhileExpr<'a>), | ||
924 | ContinueExpr(ContinueExpr<'a>), | ||
925 | BreakExpr(BreakExpr<'a>), | ||
926 | Label(Label<'a>), | ||
927 | BlockExpr(BlockExpr<'a>), | ||
928 | ReturnExpr(ReturnExpr<'a>), | ||
929 | MatchExpr(MatchExpr<'a>), | ||
930 | StructLit(StructLit<'a>), | ||
931 | CallExpr(CallExpr<'a>), | ||
932 | IndexExpr(IndexExpr<'a>), | ||
933 | MethodCallExpr(MethodCallExpr<'a>), | ||
934 | FieldExpr(FieldExpr<'a>), | ||
935 | TryExpr(TryExpr<'a>), | ||
936 | CastExpr(CastExpr<'a>), | ||
937 | RefExpr(RefExpr<'a>), | ||
938 | PrefixExpr(PrefixExpr<'a>), | ||
939 | RangeExpr(RangeExpr<'a>), | ||
940 | BinExpr(BinExpr<'a>), | ||
941 | Literal(Literal<'a>), | ||
942 | } | ||
943 | |||
944 | impl<'a> AstNode<'a> for Expr<'a> { | ||
945 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
946 | match syntax.kind() { | ||
947 | TUPLE_EXPR => Some(Expr::TupleExpr(TupleExpr { syntax })), | ||
948 | ARRAY_EXPR => Some(Expr::ArrayExpr(ArrayExpr { syntax })), | ||
949 | PAREN_EXPR => Some(Expr::ParenExpr(ParenExpr { syntax })), | ||
950 | PATH_EXPR => Some(Expr::PathExpr(PathExpr { syntax })), | ||
951 | LAMBDA_EXPR => Some(Expr::LambdaExpr(LambdaExpr { syntax })), | ||
952 | IF_EXPR => Some(Expr::IfExpr(IfExpr { syntax })), | ||
953 | LOOP_EXPR => Some(Expr::LoopExpr(LoopExpr { syntax })), | ||
954 | FOR_EXPR => Some(Expr::ForExpr(ForExpr { syntax })), | ||
955 | WHILE_EXPR => Some(Expr::WhileExpr(WhileExpr { syntax })), | ||
956 | CONTINUE_EXPR => Some(Expr::ContinueExpr(ContinueExpr { syntax })), | ||
957 | BREAK_EXPR => Some(Expr::BreakExpr(BreakExpr { syntax })), | ||
958 | LABEL => Some(Expr::Label(Label { syntax })), | ||
959 | BLOCK_EXPR => Some(Expr::BlockExpr(BlockExpr { syntax })), | ||
960 | RETURN_EXPR => Some(Expr::ReturnExpr(ReturnExpr { syntax })), | ||
961 | MATCH_EXPR => Some(Expr::MatchExpr(MatchExpr { syntax })), | ||
962 | STRUCT_LIT => Some(Expr::StructLit(StructLit { syntax })), | ||
963 | CALL_EXPR => Some(Expr::CallExpr(CallExpr { syntax })), | ||
964 | INDEX_EXPR => Some(Expr::IndexExpr(IndexExpr { syntax })), | ||
965 | METHOD_CALL_EXPR => Some(Expr::MethodCallExpr(MethodCallExpr { syntax })), | ||
966 | FIELD_EXPR => Some(Expr::FieldExpr(FieldExpr { syntax })), | ||
967 | TRY_EXPR => Some(Expr::TryExpr(TryExpr { syntax })), | ||
968 | CAST_EXPR => Some(Expr::CastExpr(CastExpr { syntax })), | ||
969 | REF_EXPR => Some(Expr::RefExpr(RefExpr { syntax })), | ||
970 | PREFIX_EXPR => Some(Expr::PrefixExpr(PrefixExpr { syntax })), | ||
971 | RANGE_EXPR => Some(Expr::RangeExpr(RangeExpr { syntax })), | ||
972 | BIN_EXPR => Some(Expr::BinExpr(BinExpr { syntax })), | ||
973 | LITERAL => Some(Expr::Literal(Literal { syntax })), | ||
974 | _ => None, | ||
975 | } | ||
976 | } | ||
977 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
978 | match self { | ||
979 | Expr::TupleExpr(inner) => inner.syntax(), | ||
980 | Expr::ArrayExpr(inner) => inner.syntax(), | ||
981 | Expr::ParenExpr(inner) => inner.syntax(), | ||
982 | Expr::PathExpr(inner) => inner.syntax(), | ||
983 | Expr::LambdaExpr(inner) => inner.syntax(), | ||
984 | Expr::IfExpr(inner) => inner.syntax(), | ||
985 | Expr::LoopExpr(inner) => inner.syntax(), | ||
986 | Expr::ForExpr(inner) => inner.syntax(), | ||
987 | Expr::WhileExpr(inner) => inner.syntax(), | ||
988 | Expr::ContinueExpr(inner) => inner.syntax(), | ||
989 | Expr::BreakExpr(inner) => inner.syntax(), | ||
990 | Expr::Label(inner) => inner.syntax(), | ||
991 | Expr::BlockExpr(inner) => inner.syntax(), | ||
992 | Expr::ReturnExpr(inner) => inner.syntax(), | ||
993 | Expr::MatchExpr(inner) => inner.syntax(), | ||
994 | Expr::StructLit(inner) => inner.syntax(), | ||
995 | Expr::CallExpr(inner) => inner.syntax(), | ||
996 | Expr::IndexExpr(inner) => inner.syntax(), | ||
997 | Expr::MethodCallExpr(inner) => inner.syntax(), | ||
998 | Expr::FieldExpr(inner) => inner.syntax(), | ||
999 | Expr::TryExpr(inner) => inner.syntax(), | ||
1000 | Expr::CastExpr(inner) => inner.syntax(), | ||
1001 | Expr::RefExpr(inner) => inner.syntax(), | ||
1002 | Expr::PrefixExpr(inner) => inner.syntax(), | ||
1003 | Expr::RangeExpr(inner) => inner.syntax(), | ||
1004 | Expr::BinExpr(inner) => inner.syntax(), | ||
1005 | Expr::Literal(inner) => inner.syntax(), | ||
1006 | } | ||
1007 | } | ||
1008 | } | 633 | } |
1009 | 634 | ||
1010 | impl<'a> Expr<'a> {} | 635 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
636 | pub enum ExprKind<'a> { | ||
637 | TupleExpr(&'a TupleExpr), | ||
638 | ArrayExpr(&'a ArrayExpr), | ||
639 | ParenExpr(&'a ParenExpr), | ||
640 | PathExpr(&'a PathExpr), | ||
641 | LambdaExpr(&'a LambdaExpr), | ||
642 | IfExpr(&'a IfExpr), | ||
643 | LoopExpr(&'a LoopExpr), | ||
644 | ForExpr(&'a ForExpr), | ||
645 | WhileExpr(&'a WhileExpr), | ||
646 | ContinueExpr(&'a ContinueExpr), | ||
647 | BreakExpr(&'a BreakExpr), | ||
648 | Label(&'a Label), | ||
649 | BlockExpr(&'a BlockExpr), | ||
650 | ReturnExpr(&'a ReturnExpr), | ||
651 | MatchExpr(&'a MatchExpr), | ||
652 | StructLit(&'a StructLit), | ||
653 | CallExpr(&'a CallExpr), | ||
654 | IndexExpr(&'a IndexExpr), | ||
655 | MethodCallExpr(&'a MethodCallExpr), | ||
656 | FieldExpr(&'a FieldExpr), | ||
657 | TryExpr(&'a TryExpr), | ||
658 | CastExpr(&'a CastExpr), | ||
659 | RefExpr(&'a RefExpr), | ||
660 | PrefixExpr(&'a PrefixExpr), | ||
661 | RangeExpr(&'a RangeExpr), | ||
662 | BinExpr(&'a BinExpr), | ||
663 | Literal(&'a Literal), | ||
664 | } | ||
665 | |||
666 | impl AstNode for Expr { | ||
667 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
668 | match syntax.kind() { | ||
669 | | TUPLE_EXPR | ||
670 | | ARRAY_EXPR | ||
671 | | PAREN_EXPR | ||
672 | | PATH_EXPR | ||
673 | | LAMBDA_EXPR | ||
674 | | IF_EXPR | ||
675 | | LOOP_EXPR | ||
676 | | FOR_EXPR | ||
677 | | WHILE_EXPR | ||
678 | | CONTINUE_EXPR | ||
679 | | BREAK_EXPR | ||
680 | | LABEL | ||
681 | | BLOCK_EXPR | ||
682 | | RETURN_EXPR | ||
683 | | MATCH_EXPR | ||
684 | | STRUCT_LIT | ||
685 | | CALL_EXPR | ||
686 | | INDEX_EXPR | ||
687 | | METHOD_CALL_EXPR | ||
688 | | FIELD_EXPR | ||
689 | | TRY_EXPR | ||
690 | | CAST_EXPR | ||
691 | | REF_EXPR | ||
692 | | PREFIX_EXPR | ||
693 | | RANGE_EXPR | ||
694 | | BIN_EXPR | ||
695 | | LITERAL => Some(Expr::from_repr(syntax.into_repr())), | ||
696 | _ => None, | ||
697 | } | ||
698 | } | ||
699 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
700 | fn to_owned(&self) -> TreePtr<Expr> { TreePtr::cast(self.syntax.to_owned()) } | ||
701 | } | ||
702 | |||
703 | impl Expr { | ||
704 | pub fn kind(&self) -> ExprKind { | ||
705 | match self.syntax.kind() { | ||
706 | TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(&self.syntax).unwrap()), | ||
707 | ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(&self.syntax).unwrap()), | ||
708 | PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(&self.syntax).unwrap()), | ||
709 | PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(&self.syntax).unwrap()), | ||
710 | LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(&self.syntax).unwrap()), | ||
711 | IF_EXPR => ExprKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()), | ||
712 | LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(&self.syntax).unwrap()), | ||
713 | FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(&self.syntax).unwrap()), | ||
714 | WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(&self.syntax).unwrap()), | ||
715 | CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(&self.syntax).unwrap()), | ||
716 | BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(&self.syntax).unwrap()), | ||
717 | LABEL => ExprKind::Label(Label::cast(&self.syntax).unwrap()), | ||
718 | BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(&self.syntax).unwrap()), | ||
719 | RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(&self.syntax).unwrap()), | ||
720 | MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(&self.syntax).unwrap()), | ||
721 | STRUCT_LIT => ExprKind::StructLit(StructLit::cast(&self.syntax).unwrap()), | ||
722 | CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(&self.syntax).unwrap()), | ||
723 | INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(&self.syntax).unwrap()), | ||
724 | METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()), | ||
725 | FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()), | ||
726 | TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()), | ||
727 | CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()), | ||
728 | REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()), | ||
729 | PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()), | ||
730 | RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()), | ||
731 | BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()), | ||
732 | LITERAL => ExprKind::Literal(Literal::cast(&self.syntax).unwrap()), | ||
733 | _ => unreachable!(), | ||
734 | } | ||
735 | } | ||
736 | } | ||
737 | |||
738 | impl Expr {} | ||
1011 | 739 | ||
1012 | // ExprStmt | 740 | // ExprStmt |
1013 | #[derive(Debug, Clone, Copy,)] | 741 | #[derive(Debug, PartialEq, Eq, Hash)] |
1014 | pub struct ExprStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 742 | #[repr(transparent)] |
1015 | pub(crate) syntax: SyntaxNode<R>, | 743 | pub struct ExprStmt { |
744 | pub(crate) syntax: SyntaxNode, | ||
1016 | } | 745 | } |
1017 | pub type ExprStmt<'a> = ExprStmtNode<RefRoot<'a>>; | 746 | unsafe impl TransparentNewType for ExprStmt { |
1018 | 747 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1019 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExprStmtNode<R1>> for ExprStmtNode<R2> { | ||
1020 | fn eq(&self, other: &ExprStmtNode<R1>) -> bool { self.syntax == other.syntax } | ||
1021 | } | ||
1022 | impl<R: TreeRoot<RaTypes>> Eq for ExprStmtNode<R> {} | ||
1023 | impl<R: TreeRoot<RaTypes>> Hash for ExprStmtNode<R> { | ||
1024 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1025 | } | 748 | } |
1026 | 749 | ||
1027 | impl<'a> AstNode<'a> for ExprStmt<'a> { | 750 | impl AstNode for ExprStmt { |
1028 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 751 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1029 | match syntax.kind() { | 752 | match syntax.kind() { |
1030 | EXPR_STMT => Some(ExprStmt { syntax }), | 753 | EXPR_STMT => Some(ExprStmt::from_repr(syntax.into_repr())), |
1031 | _ => None, | 754 | _ => None, |
1032 | } | 755 | } |
1033 | } | 756 | } |
1034 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 757 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1035 | } | 758 | fn to_owned(&self) -> TreePtr<ExprStmt> { TreePtr::cast(self.syntax.to_owned()) } |
1036 | |||
1037 | impl<R: TreeRoot<RaTypes>> ExprStmtNode<R> { | ||
1038 | pub fn borrowed(&self) -> ExprStmt { | ||
1039 | ExprStmtNode { syntax: self.syntax.borrowed() } | ||
1040 | } | ||
1041 | pub fn owned(&self) -> ExprStmtNode { | ||
1042 | ExprStmtNode { syntax: self.syntax.owned() } | ||
1043 | } | ||
1044 | } | 759 | } |
1045 | 760 | ||
1046 | 761 | ||
1047 | impl<'a> ExprStmt<'a> { | 762 | impl ExprStmt { |
1048 | pub fn expr(self) -> Option<Expr<'a>> { | 763 | pub fn expr(&self) -> Option<&Expr> { |
1049 | super::child_opt(self) | 764 | super::child_opt(self) |
1050 | } | 765 | } |
1051 | } | 766 | } |
1052 | 767 | ||
1053 | // ExternCrateItem | 768 | // ExternCrateItem |
1054 | #[derive(Debug, Clone, Copy,)] | 769 | #[derive(Debug, PartialEq, Eq, Hash)] |
1055 | pub struct ExternCrateItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 770 | #[repr(transparent)] |
1056 | pub(crate) syntax: SyntaxNode<R>, | 771 | pub struct ExternCrateItem { |
1057 | } | 772 | pub(crate) syntax: SyntaxNode, |
1058 | pub type ExternCrateItem<'a> = ExternCrateItemNode<RefRoot<'a>>; | ||
1059 | |||
1060 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExternCrateItemNode<R1>> for ExternCrateItemNode<R2> { | ||
1061 | fn eq(&self, other: &ExternCrateItemNode<R1>) -> bool { self.syntax == other.syntax } | ||
1062 | } | 773 | } |
1063 | impl<R: TreeRoot<RaTypes>> Eq for ExternCrateItemNode<R> {} | 774 | unsafe impl TransparentNewType for ExternCrateItem { |
1064 | impl<R: TreeRoot<RaTypes>> Hash for ExternCrateItemNode<R> { | 775 | type Repr = rowan::SyntaxNode<RaTypes>; |
1065 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1066 | } | 776 | } |
1067 | 777 | ||
1068 | impl<'a> AstNode<'a> for ExternCrateItem<'a> { | 778 | impl AstNode for ExternCrateItem { |
1069 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 779 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1070 | match syntax.kind() { | 780 | match syntax.kind() { |
1071 | EXTERN_CRATE_ITEM => Some(ExternCrateItem { syntax }), | 781 | EXTERN_CRATE_ITEM => Some(ExternCrateItem::from_repr(syntax.into_repr())), |
1072 | _ => None, | 782 | _ => None, |
1073 | } | 783 | } |
1074 | } | 784 | } |
1075 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 785 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
786 | fn to_owned(&self) -> TreePtr<ExternCrateItem> { TreePtr::cast(self.syntax.to_owned()) } | ||
1076 | } | 787 | } |
1077 | 788 | ||
1078 | impl<R: TreeRoot<RaTypes>> ExternCrateItemNode<R> { | ||
1079 | pub fn borrowed(&self) -> ExternCrateItem { | ||
1080 | ExternCrateItemNode { syntax: self.syntax.borrowed() } | ||
1081 | } | ||
1082 | pub fn owned(&self) -> ExternCrateItemNode { | ||
1083 | ExternCrateItemNode { syntax: self.syntax.owned() } | ||
1084 | } | ||
1085 | } | ||
1086 | 789 | ||
1087 | 790 | impl ExternCrateItem {} | |
1088 | impl<'a> ExternCrateItem<'a> {} | ||
1089 | 791 | ||
1090 | // FieldExpr | 792 | // FieldExpr |
1091 | #[derive(Debug, Clone, Copy,)] | 793 | #[derive(Debug, PartialEq, Eq, Hash)] |
1092 | pub struct FieldExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 794 | #[repr(transparent)] |
1093 | pub(crate) syntax: SyntaxNode<R>, | 795 | pub struct FieldExpr { |
1094 | } | 796 | pub(crate) syntax: SyntaxNode, |
1095 | pub type FieldExpr<'a> = FieldExprNode<RefRoot<'a>>; | ||
1096 | |||
1097 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldExprNode<R1>> for FieldExprNode<R2> { | ||
1098 | fn eq(&self, other: &FieldExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1099 | } | 797 | } |
1100 | impl<R: TreeRoot<RaTypes>> Eq for FieldExprNode<R> {} | 798 | unsafe impl TransparentNewType for FieldExpr { |
1101 | impl<R: TreeRoot<RaTypes>> Hash for FieldExprNode<R> { | 799 | type Repr = rowan::SyntaxNode<RaTypes>; |
1102 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1103 | } | 800 | } |
1104 | 801 | ||
1105 | impl<'a> AstNode<'a> for FieldExpr<'a> { | 802 | impl AstNode for FieldExpr { |
1106 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 803 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1107 | match syntax.kind() { | 804 | match syntax.kind() { |
1108 | FIELD_EXPR => Some(FieldExpr { syntax }), | 805 | FIELD_EXPR => Some(FieldExpr::from_repr(syntax.into_repr())), |
1109 | _ => None, | 806 | _ => None, |
1110 | } | 807 | } |
1111 | } | 808 | } |
1112 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 809 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
810 | fn to_owned(&self) -> TreePtr<FieldExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
1113 | } | 811 | } |
1114 | 812 | ||
1115 | impl<R: TreeRoot<RaTypes>> FieldExprNode<R> { | ||
1116 | pub fn borrowed(&self) -> FieldExpr { | ||
1117 | FieldExprNode { syntax: self.syntax.borrowed() } | ||
1118 | } | ||
1119 | pub fn owned(&self) -> FieldExprNode { | ||
1120 | FieldExprNode { syntax: self.syntax.owned() } | ||
1121 | } | ||
1122 | } | ||
1123 | 813 | ||
1124 | 814 | impl FieldExpr { | |
1125 | impl<'a> FieldExpr<'a> { | 815 | pub fn expr(&self) -> Option<&Expr> { |
1126 | pub fn expr(self) -> Option<Expr<'a>> { | ||
1127 | super::child_opt(self) | 816 | super::child_opt(self) |
1128 | } | 817 | } |
1129 | 818 | ||
1130 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 819 | pub fn name_ref(&self) -> Option<&NameRef> { |
1131 | super::child_opt(self) | 820 | super::child_opt(self) |
1132 | } | 821 | } |
1133 | } | 822 | } |
1134 | 823 | ||
1135 | // FieldPatList | 824 | // FieldPatList |
1136 | #[derive(Debug, Clone, Copy,)] | 825 | #[derive(Debug, PartialEq, Eq, Hash)] |
1137 | pub struct FieldPatListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 826 | #[repr(transparent)] |
1138 | pub(crate) syntax: SyntaxNode<R>, | 827 | pub struct FieldPatList { |
828 | pub(crate) syntax: SyntaxNode, | ||
1139 | } | 829 | } |
1140 | pub type FieldPatList<'a> = FieldPatListNode<RefRoot<'a>>; | 830 | unsafe impl TransparentNewType for FieldPatList { |
1141 | 831 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1142 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldPatListNode<R1>> for FieldPatListNode<R2> { | ||
1143 | fn eq(&self, other: &FieldPatListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1144 | } | ||
1145 | impl<R: TreeRoot<RaTypes>> Eq for FieldPatListNode<R> {} | ||
1146 | impl<R: TreeRoot<RaTypes>> Hash for FieldPatListNode<R> { | ||
1147 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1148 | } | 832 | } |
1149 | 833 | ||
1150 | impl<'a> AstNode<'a> for FieldPatList<'a> { | 834 | impl AstNode for FieldPatList { |
1151 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 835 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1152 | match syntax.kind() { | 836 | match syntax.kind() { |
1153 | FIELD_PAT_LIST => Some(FieldPatList { syntax }), | 837 | FIELD_PAT_LIST => Some(FieldPatList::from_repr(syntax.into_repr())), |
1154 | _ => None, | 838 | _ => None, |
1155 | } | 839 | } |
1156 | } | 840 | } |
1157 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 841 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1158 | } | 842 | fn to_owned(&self) -> TreePtr<FieldPatList> { TreePtr::cast(self.syntax.to_owned()) } |
1159 | |||
1160 | impl<R: TreeRoot<RaTypes>> FieldPatListNode<R> { | ||
1161 | pub fn borrowed(&self) -> FieldPatList { | ||
1162 | FieldPatListNode { syntax: self.syntax.borrowed() } | ||
1163 | } | ||
1164 | pub fn owned(&self) -> FieldPatListNode { | ||
1165 | FieldPatListNode { syntax: self.syntax.owned() } | ||
1166 | } | ||
1167 | } | 843 | } |
1168 | 844 | ||
1169 | 845 | ||
1170 | impl<'a> FieldPatList<'a> {} | 846 | impl FieldPatList {} |
1171 | 847 | ||
1172 | // FnDef | 848 | // FnDef |
1173 | #[derive(Debug, Clone, Copy,)] | 849 | #[derive(Debug, PartialEq, Eq, Hash)] |
1174 | pub struct FnDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 850 | #[repr(transparent)] |
1175 | pub(crate) syntax: SyntaxNode<R>, | 851 | pub struct FnDef { |
852 | pub(crate) syntax: SyntaxNode, | ||
1176 | } | 853 | } |
1177 | pub type FnDef<'a> = FnDefNode<RefRoot<'a>>; | 854 | unsafe impl TransparentNewType for FnDef { |
1178 | 855 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1179 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnDefNode<R1>> for FnDefNode<R2> { | ||
1180 | fn eq(&self, other: &FnDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
1181 | } | ||
1182 | impl<R: TreeRoot<RaTypes>> Eq for FnDefNode<R> {} | ||
1183 | impl<R: TreeRoot<RaTypes>> Hash for FnDefNode<R> { | ||
1184 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1185 | } | 856 | } |
1186 | 857 | ||
1187 | impl<'a> AstNode<'a> for FnDef<'a> { | 858 | impl AstNode for FnDef { |
1188 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 859 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1189 | match syntax.kind() { | 860 | match syntax.kind() { |
1190 | FN_DEF => Some(FnDef { syntax }), | 861 | FN_DEF => Some(FnDef::from_repr(syntax.into_repr())), |
1191 | _ => None, | 862 | _ => None, |
1192 | } | 863 | } |
1193 | } | 864 | } |
1194 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 865 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1195 | } | 866 | fn to_owned(&self) -> TreePtr<FnDef> { TreePtr::cast(self.syntax.to_owned()) } |
1196 | |||
1197 | impl<R: TreeRoot<RaTypes>> FnDefNode<R> { | ||
1198 | pub fn borrowed(&self) -> FnDef { | ||
1199 | FnDefNode { syntax: self.syntax.borrowed() } | ||
1200 | } | ||
1201 | pub fn owned(&self) -> FnDefNode { | ||
1202 | FnDefNode { syntax: self.syntax.owned() } | ||
1203 | } | ||
1204 | } | 867 | } |
1205 | 868 | ||
1206 | 869 | ||
1207 | impl<'a> ast::VisibilityOwner<'a> for FnDef<'a> {} | 870 | impl ast::VisibilityOwner for FnDef {} |
1208 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} | 871 | impl ast::NameOwner for FnDef {} |
1209 | impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} | 872 | impl ast::TypeParamsOwner for FnDef {} |
1210 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} | 873 | impl ast::AttrsOwner for FnDef {} |
1211 | impl<'a> ast::DocCommentsOwner<'a> for FnDef<'a> {} | 874 | impl ast::DocCommentsOwner for FnDef {} |
1212 | impl<'a> FnDef<'a> { | 875 | impl FnDef { |
1213 | pub fn param_list(self) -> Option<ParamList<'a>> { | 876 | pub fn param_list(&self) -> Option<&ParamList> { |
1214 | super::child_opt(self) | 877 | super::child_opt(self) |
1215 | } | 878 | } |
1216 | 879 | ||
1217 | pub fn body(self) -> Option<Block<'a>> { | 880 | pub fn body(&self) -> Option<&Block> { |
1218 | super::child_opt(self) | 881 | super::child_opt(self) |
1219 | } | 882 | } |
1220 | 883 | ||
1221 | pub fn ret_type(self) -> Option<RetType<'a>> { | 884 | pub fn ret_type(&self) -> Option<&RetType> { |
1222 | super::child_opt(self) | 885 | super::child_opt(self) |
1223 | } | 886 | } |
1224 | } | 887 | } |
1225 | 888 | ||
1226 | // FnPointerType | 889 | // FnPointerType |
1227 | #[derive(Debug, Clone, Copy,)] | 890 | #[derive(Debug, PartialEq, Eq, Hash)] |
1228 | pub struct FnPointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 891 | #[repr(transparent)] |
1229 | pub(crate) syntax: SyntaxNode<R>, | 892 | pub struct FnPointerType { |
1230 | } | 893 | pub(crate) syntax: SyntaxNode, |
1231 | pub type FnPointerType<'a> = FnPointerTypeNode<RefRoot<'a>>; | ||
1232 | |||
1233 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnPointerTypeNode<R1>> for FnPointerTypeNode<R2> { | ||
1234 | fn eq(&self, other: &FnPointerTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1235 | } | 894 | } |
1236 | impl<R: TreeRoot<RaTypes>> Eq for FnPointerTypeNode<R> {} | 895 | unsafe impl TransparentNewType for FnPointerType { |
1237 | impl<R: TreeRoot<RaTypes>> Hash for FnPointerTypeNode<R> { | 896 | type Repr = rowan::SyntaxNode<RaTypes>; |
1238 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1239 | } | 897 | } |
1240 | 898 | ||
1241 | impl<'a> AstNode<'a> for FnPointerType<'a> { | 899 | impl AstNode for FnPointerType { |
1242 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 900 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1243 | match syntax.kind() { | 901 | match syntax.kind() { |
1244 | FN_POINTER_TYPE => Some(FnPointerType { syntax }), | 902 | FN_POINTER_TYPE => Some(FnPointerType::from_repr(syntax.into_repr())), |
1245 | _ => None, | 903 | _ => None, |
1246 | } | 904 | } |
1247 | } | 905 | } |
1248 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 906 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
907 | fn to_owned(&self) -> TreePtr<FnPointerType> { TreePtr::cast(self.syntax.to_owned()) } | ||
1249 | } | 908 | } |
1250 | 909 | ||
1251 | impl<R: TreeRoot<RaTypes>> FnPointerTypeNode<R> { | ||
1252 | pub fn borrowed(&self) -> FnPointerType { | ||
1253 | FnPointerTypeNode { syntax: self.syntax.borrowed() } | ||
1254 | } | ||
1255 | pub fn owned(&self) -> FnPointerTypeNode { | ||
1256 | FnPointerTypeNode { syntax: self.syntax.owned() } | ||
1257 | } | ||
1258 | } | ||
1259 | 910 | ||
1260 | 911 | impl FnPointerType { | |
1261 | impl<'a> FnPointerType<'a> { | 912 | pub fn param_list(&self) -> Option<&ParamList> { |
1262 | pub fn param_list(self) -> Option<ParamList<'a>> { | ||
1263 | super::child_opt(self) | 913 | super::child_opt(self) |
1264 | } | 914 | } |
1265 | 915 | ||
1266 | pub fn ret_type(self) -> Option<RetType<'a>> { | 916 | pub fn ret_type(&self) -> Option<&RetType> { |
1267 | super::child_opt(self) | 917 | super::child_opt(self) |
1268 | } | 918 | } |
1269 | } | 919 | } |
1270 | 920 | ||
1271 | // ForExpr | 921 | // ForExpr |
1272 | #[derive(Debug, Clone, Copy,)] | 922 | #[derive(Debug, PartialEq, Eq, Hash)] |
1273 | pub struct ForExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 923 | #[repr(transparent)] |
1274 | pub(crate) syntax: SyntaxNode<R>, | 924 | pub struct ForExpr { |
1275 | } | 925 | pub(crate) syntax: SyntaxNode, |
1276 | pub type ForExpr<'a> = ForExprNode<RefRoot<'a>>; | ||
1277 | |||
1278 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForExprNode<R1>> for ForExprNode<R2> { | ||
1279 | fn eq(&self, other: &ForExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1280 | } | 926 | } |
1281 | impl<R: TreeRoot<RaTypes>> Eq for ForExprNode<R> {} | 927 | unsafe impl TransparentNewType for ForExpr { |
1282 | impl<R: TreeRoot<RaTypes>> Hash for ForExprNode<R> { | 928 | type Repr = rowan::SyntaxNode<RaTypes>; |
1283 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1284 | } | 929 | } |
1285 | 930 | ||
1286 | impl<'a> AstNode<'a> for ForExpr<'a> { | 931 | impl AstNode for ForExpr { |
1287 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 932 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1288 | match syntax.kind() { | 933 | match syntax.kind() { |
1289 | FOR_EXPR => Some(ForExpr { syntax }), | 934 | FOR_EXPR => Some(ForExpr::from_repr(syntax.into_repr())), |
1290 | _ => None, | 935 | _ => None, |
1291 | } | 936 | } |
1292 | } | 937 | } |
1293 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 938 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1294 | } | 939 | fn to_owned(&self) -> TreePtr<ForExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1295 | |||
1296 | impl<R: TreeRoot<RaTypes>> ForExprNode<R> { | ||
1297 | pub fn borrowed(&self) -> ForExpr { | ||
1298 | ForExprNode { syntax: self.syntax.borrowed() } | ||
1299 | } | ||
1300 | pub fn owned(&self) -> ForExprNode { | ||
1301 | ForExprNode { syntax: self.syntax.owned() } | ||
1302 | } | ||
1303 | } | 940 | } |
1304 | 941 | ||
1305 | 942 | ||
1306 | impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} | 943 | impl ast::LoopBodyOwner for ForExpr {} |
1307 | impl<'a> ForExpr<'a> { | 944 | impl ForExpr { |
1308 | pub fn pat(self) -> Option<Pat<'a>> { | 945 | pub fn pat(&self) -> Option<&Pat> { |
1309 | super::child_opt(self) | 946 | super::child_opt(self) |
1310 | } | 947 | } |
1311 | 948 | ||
1312 | pub fn iterable(self) -> Option<Expr<'a>> { | 949 | pub fn iterable(&self) -> Option<&Expr> { |
1313 | super::child_opt(self) | 950 | super::child_opt(self) |
1314 | } | 951 | } |
1315 | } | 952 | } |
1316 | 953 | ||
1317 | // ForType | 954 | // ForType |
1318 | #[derive(Debug, Clone, Copy,)] | 955 | #[derive(Debug, PartialEq, Eq, Hash)] |
1319 | pub struct ForTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 956 | #[repr(transparent)] |
1320 | pub(crate) syntax: SyntaxNode<R>, | 957 | pub struct ForType { |
1321 | } | 958 | pub(crate) syntax: SyntaxNode, |
1322 | pub type ForType<'a> = ForTypeNode<RefRoot<'a>>; | ||
1323 | |||
1324 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForTypeNode<R1>> for ForTypeNode<R2> { | ||
1325 | fn eq(&self, other: &ForTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1326 | } | 959 | } |
1327 | impl<R: TreeRoot<RaTypes>> Eq for ForTypeNode<R> {} | 960 | unsafe impl TransparentNewType for ForType { |
1328 | impl<R: TreeRoot<RaTypes>> Hash for ForTypeNode<R> { | 961 | type Repr = rowan::SyntaxNode<RaTypes>; |
1329 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1330 | } | 962 | } |
1331 | 963 | ||
1332 | impl<'a> AstNode<'a> for ForType<'a> { | 964 | impl AstNode for ForType { |
1333 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 965 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1334 | match syntax.kind() { | 966 | match syntax.kind() { |
1335 | FOR_TYPE => Some(ForType { syntax }), | 967 | FOR_TYPE => Some(ForType::from_repr(syntax.into_repr())), |
1336 | _ => None, | 968 | _ => None, |
1337 | } | 969 | } |
1338 | } | 970 | } |
1339 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 971 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1340 | } | 972 | fn to_owned(&self) -> TreePtr<ForType> { TreePtr::cast(self.syntax.to_owned()) } |
1341 | |||
1342 | impl<R: TreeRoot<RaTypes>> ForTypeNode<R> { | ||
1343 | pub fn borrowed(&self) -> ForType { | ||
1344 | ForTypeNode { syntax: self.syntax.borrowed() } | ||
1345 | } | ||
1346 | pub fn owned(&self) -> ForTypeNode { | ||
1347 | ForTypeNode { syntax: self.syntax.owned() } | ||
1348 | } | ||
1349 | } | 973 | } |
1350 | 974 | ||
1351 | 975 | ||
1352 | impl<'a> ForType<'a> { | 976 | impl ForType { |
1353 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 977 | pub fn type_ref(&self) -> Option<&TypeRef> { |
1354 | super::child_opt(self) | 978 | super::child_opt(self) |
1355 | } | 979 | } |
1356 | } | 980 | } |
1357 | 981 | ||
1358 | // IfExpr | 982 | // IfExpr |
1359 | #[derive(Debug, Clone, Copy,)] | 983 | #[derive(Debug, PartialEq, Eq, Hash)] |
1360 | pub struct IfExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 984 | #[repr(transparent)] |
1361 | pub(crate) syntax: SyntaxNode<R>, | 985 | pub struct IfExpr { |
986 | pub(crate) syntax: SyntaxNode, | ||
1362 | } | 987 | } |
1363 | pub type IfExpr<'a> = IfExprNode<RefRoot<'a>>; | 988 | unsafe impl TransparentNewType for IfExpr { |
1364 | 989 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1365 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IfExprNode<R1>> for IfExprNode<R2> { | ||
1366 | fn eq(&self, other: &IfExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1367 | } | ||
1368 | impl<R: TreeRoot<RaTypes>> Eq for IfExprNode<R> {} | ||
1369 | impl<R: TreeRoot<RaTypes>> Hash for IfExprNode<R> { | ||
1370 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1371 | } | 990 | } |
1372 | 991 | ||
1373 | impl<'a> AstNode<'a> for IfExpr<'a> { | 992 | impl AstNode for IfExpr { |
1374 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 993 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1375 | match syntax.kind() { | 994 | match syntax.kind() { |
1376 | IF_EXPR => Some(IfExpr { syntax }), | 995 | IF_EXPR => Some(IfExpr::from_repr(syntax.into_repr())), |
1377 | _ => None, | 996 | _ => None, |
1378 | } | 997 | } |
1379 | } | 998 | } |
1380 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 999 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1381 | } | 1000 | fn to_owned(&self) -> TreePtr<IfExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1382 | |||
1383 | impl<R: TreeRoot<RaTypes>> IfExprNode<R> { | ||
1384 | pub fn borrowed(&self) -> IfExpr { | ||
1385 | IfExprNode { syntax: self.syntax.borrowed() } | ||
1386 | } | ||
1387 | pub fn owned(&self) -> IfExprNode { | ||
1388 | IfExprNode { syntax: self.syntax.owned() } | ||
1389 | } | ||
1390 | } | 1001 | } |
1391 | 1002 | ||
1392 | 1003 | ||
1393 | impl<'a> IfExpr<'a> { | 1004 | impl IfExpr { |
1394 | pub fn condition(self) -> Option<Condition<'a>> { | 1005 | pub fn condition(&self) -> Option<&Condition> { |
1395 | super::child_opt(self) | 1006 | super::child_opt(self) |
1396 | } | 1007 | } |
1397 | } | 1008 | } |
1398 | 1009 | ||
1399 | // ImplBlock | 1010 | // ImplBlock |
1400 | #[derive(Debug, Clone, Copy,)] | 1011 | #[derive(Debug, PartialEq, Eq, Hash)] |
1401 | pub struct ImplBlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1012 | #[repr(transparent)] |
1402 | pub(crate) syntax: SyntaxNode<R>, | 1013 | pub struct ImplBlock { |
1014 | pub(crate) syntax: SyntaxNode, | ||
1403 | } | 1015 | } |
1404 | pub type ImplBlock<'a> = ImplBlockNode<RefRoot<'a>>; | 1016 | unsafe impl TransparentNewType for ImplBlock { |
1405 | 1017 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1406 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplBlockNode<R1>> for ImplBlockNode<R2> { | ||
1407 | fn eq(&self, other: &ImplBlockNode<R1>) -> bool { self.syntax == other.syntax } | ||
1408 | } | ||
1409 | impl<R: TreeRoot<RaTypes>> Eq for ImplBlockNode<R> {} | ||
1410 | impl<R: TreeRoot<RaTypes>> Hash for ImplBlockNode<R> { | ||
1411 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1412 | } | 1018 | } |
1413 | 1019 | ||
1414 | impl<'a> AstNode<'a> for ImplBlock<'a> { | 1020 | impl AstNode for ImplBlock { |
1415 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1021 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1416 | match syntax.kind() { | 1022 | match syntax.kind() { |
1417 | IMPL_BLOCK => Some(ImplBlock { syntax }), | 1023 | IMPL_BLOCK => Some(ImplBlock::from_repr(syntax.into_repr())), |
1418 | _ => None, | 1024 | _ => None, |
1419 | } | 1025 | } |
1420 | } | 1026 | } |
1421 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1027 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1422 | } | 1028 | fn to_owned(&self) -> TreePtr<ImplBlock> { TreePtr::cast(self.syntax.to_owned()) } |
1423 | |||
1424 | impl<R: TreeRoot<RaTypes>> ImplBlockNode<R> { | ||
1425 | pub fn borrowed(&self) -> ImplBlock { | ||
1426 | ImplBlockNode { syntax: self.syntax.borrowed() } | ||
1427 | } | ||
1428 | pub fn owned(&self) -> ImplBlockNode { | ||
1429 | ImplBlockNode { syntax: self.syntax.owned() } | ||
1430 | } | ||
1431 | } | 1029 | } |
1432 | 1030 | ||
1433 | 1031 | ||
1434 | impl<'a> ImplBlock<'a> { | 1032 | impl ImplBlock { |
1435 | pub fn item_list(self) -> Option<ItemList<'a>> { | 1033 | pub fn item_list(&self) -> Option<&ItemList> { |
1436 | super::child_opt(self) | 1034 | super::child_opt(self) |
1437 | } | 1035 | } |
1438 | } | 1036 | } |
1439 | 1037 | ||
1440 | // ImplItem | 1038 | // ImplItem |
1039 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1040 | #[repr(transparent)] | ||
1041 | pub struct ImplItem { | ||
1042 | pub(crate) syntax: SyntaxNode, | ||
1043 | } | ||
1044 | unsafe impl TransparentNewType for ImplItem { | ||
1045 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1046 | } | ||
1047 | |||
1441 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1048 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1442 | pub enum ImplItem<'a> { | 1049 | pub enum ImplItemKind<'a> { |
1443 | FnDef(FnDef<'a>), | 1050 | FnDef(&'a FnDef), |
1444 | TypeDef(TypeDef<'a>), | 1051 | TypeDef(&'a TypeDef), |
1445 | ConstDef(ConstDef<'a>), | 1052 | ConstDef(&'a ConstDef), |
1446 | } | 1053 | } |
1447 | 1054 | ||
1448 | impl<'a> AstNode<'a> for ImplItem<'a> { | 1055 | impl AstNode for ImplItem { |
1449 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1056 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1450 | match syntax.kind() { | 1057 | match syntax.kind() { |
1451 | FN_DEF => Some(ImplItem::FnDef(FnDef { syntax })), | 1058 | | FN_DEF |
1452 | TYPE_DEF => Some(ImplItem::TypeDef(TypeDef { syntax })), | 1059 | | TYPE_DEF |
1453 | CONST_DEF => Some(ImplItem::ConstDef(ConstDef { syntax })), | 1060 | | CONST_DEF => Some(ImplItem::from_repr(syntax.into_repr())), |
1454 | _ => None, | 1061 | _ => None, |
1455 | } | 1062 | } |
1456 | } | 1063 | } |
1457 | fn syntax(self) -> SyntaxNodeRef<'a> { | 1064 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1458 | match self { | 1065 | fn to_owned(&self) -> TreePtr<ImplItem> { TreePtr::cast(self.syntax.to_owned()) } |
1459 | ImplItem::FnDef(inner) => inner.syntax(), | 1066 | } |
1460 | ImplItem::TypeDef(inner) => inner.syntax(), | 1067 | |
1461 | ImplItem::ConstDef(inner) => inner.syntax(), | 1068 | impl ImplItem { |
1069 | pub fn kind(&self) -> ImplItemKind { | ||
1070 | match self.syntax.kind() { | ||
1071 | FN_DEF => ImplItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), | ||
1072 | TYPE_DEF => ImplItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), | ||
1073 | CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), | ||
1074 | _ => unreachable!(), | ||
1462 | } | 1075 | } |
1463 | } | 1076 | } |
1464 | } | 1077 | } |
1465 | 1078 | ||
1466 | impl<'a> ImplItem<'a> {} | 1079 | impl ImplItem {} |
1467 | 1080 | ||
1468 | // ImplTraitType | 1081 | // ImplTraitType |
1469 | #[derive(Debug, Clone, Copy,)] | 1082 | #[derive(Debug, PartialEq, Eq, Hash)] |
1470 | pub struct ImplTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1083 | #[repr(transparent)] |
1471 | pub(crate) syntax: SyntaxNode<R>, | 1084 | pub struct ImplTraitType { |
1472 | } | 1085 | pub(crate) syntax: SyntaxNode, |
1473 | pub type ImplTraitType<'a> = ImplTraitTypeNode<RefRoot<'a>>; | ||
1474 | |||
1475 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplTraitTypeNode<R1>> for ImplTraitTypeNode<R2> { | ||
1476 | fn eq(&self, other: &ImplTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1477 | } | 1086 | } |
1478 | impl<R: TreeRoot<RaTypes>> Eq for ImplTraitTypeNode<R> {} | 1087 | unsafe impl TransparentNewType for ImplTraitType { |
1479 | impl<R: TreeRoot<RaTypes>> Hash for ImplTraitTypeNode<R> { | 1088 | type Repr = rowan::SyntaxNode<RaTypes>; |
1480 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1481 | } | 1089 | } |
1482 | 1090 | ||
1483 | impl<'a> AstNode<'a> for ImplTraitType<'a> { | 1091 | impl AstNode for ImplTraitType { |
1484 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1092 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1485 | match syntax.kind() { | 1093 | match syntax.kind() { |
1486 | IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), | 1094 | IMPL_TRAIT_TYPE => Some(ImplTraitType::from_repr(syntax.into_repr())), |
1487 | _ => None, | 1095 | _ => None, |
1488 | } | 1096 | } |
1489 | } | 1097 | } |
1490 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1098 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1099 | fn to_owned(&self) -> TreePtr<ImplTraitType> { TreePtr::cast(self.syntax.to_owned()) } | ||
1491 | } | 1100 | } |
1492 | 1101 | ||
1493 | impl<R: TreeRoot<RaTypes>> ImplTraitTypeNode<R> { | ||
1494 | pub fn borrowed(&self) -> ImplTraitType { | ||
1495 | ImplTraitTypeNode { syntax: self.syntax.borrowed() } | ||
1496 | } | ||
1497 | pub fn owned(&self) -> ImplTraitTypeNode { | ||
1498 | ImplTraitTypeNode { syntax: self.syntax.owned() } | ||
1499 | } | ||
1500 | } | ||
1501 | 1102 | ||
1502 | 1103 | impl ImplTraitType {} | |
1503 | impl<'a> ImplTraitType<'a> {} | ||
1504 | 1104 | ||
1505 | // IndexExpr | 1105 | // IndexExpr |
1506 | #[derive(Debug, Clone, Copy,)] | 1106 | #[derive(Debug, PartialEq, Eq, Hash)] |
1507 | pub struct IndexExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1107 | #[repr(transparent)] |
1508 | pub(crate) syntax: SyntaxNode<R>, | 1108 | pub struct IndexExpr { |
1109 | pub(crate) syntax: SyntaxNode, | ||
1509 | } | 1110 | } |
1510 | pub type IndexExpr<'a> = IndexExprNode<RefRoot<'a>>; | 1111 | unsafe impl TransparentNewType for IndexExpr { |
1511 | 1112 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1512 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IndexExprNode<R1>> for IndexExprNode<R2> { | ||
1513 | fn eq(&self, other: &IndexExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1514 | } | ||
1515 | impl<R: TreeRoot<RaTypes>> Eq for IndexExprNode<R> {} | ||
1516 | impl<R: TreeRoot<RaTypes>> Hash for IndexExprNode<R> { | ||
1517 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1518 | } | 1113 | } |
1519 | 1114 | ||
1520 | impl<'a> AstNode<'a> for IndexExpr<'a> { | 1115 | impl AstNode for IndexExpr { |
1521 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1116 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1522 | match syntax.kind() { | 1117 | match syntax.kind() { |
1523 | INDEX_EXPR => Some(IndexExpr { syntax }), | 1118 | INDEX_EXPR => Some(IndexExpr::from_repr(syntax.into_repr())), |
1524 | _ => None, | 1119 | _ => None, |
1525 | } | 1120 | } |
1526 | } | 1121 | } |
1527 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1122 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1528 | } | 1123 | fn to_owned(&self) -> TreePtr<IndexExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1529 | |||
1530 | impl<R: TreeRoot<RaTypes>> IndexExprNode<R> { | ||
1531 | pub fn borrowed(&self) -> IndexExpr { | ||
1532 | IndexExprNode { syntax: self.syntax.borrowed() } | ||
1533 | } | ||
1534 | pub fn owned(&self) -> IndexExprNode { | ||
1535 | IndexExprNode { syntax: self.syntax.owned() } | ||
1536 | } | ||
1537 | } | 1124 | } |
1538 | 1125 | ||
1539 | 1126 | ||
1540 | impl<'a> IndexExpr<'a> {} | 1127 | impl IndexExpr {} |
1541 | 1128 | ||
1542 | // ItemList | 1129 | // ItemList |
1543 | #[derive(Debug, Clone, Copy,)] | 1130 | #[derive(Debug, PartialEq, Eq, Hash)] |
1544 | pub struct ItemListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1131 | #[repr(transparent)] |
1545 | pub(crate) syntax: SyntaxNode<R>, | 1132 | pub struct ItemList { |
1133 | pub(crate) syntax: SyntaxNode, | ||
1546 | } | 1134 | } |
1547 | pub type ItemList<'a> = ItemListNode<RefRoot<'a>>; | 1135 | unsafe impl TransparentNewType for ItemList { |
1548 | 1136 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1549 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ItemListNode<R1>> for ItemListNode<R2> { | ||
1550 | fn eq(&self, other: &ItemListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1551 | } | ||
1552 | impl<R: TreeRoot<RaTypes>> Eq for ItemListNode<R> {} | ||
1553 | impl<R: TreeRoot<RaTypes>> Hash for ItemListNode<R> { | ||
1554 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1555 | } | 1137 | } |
1556 | 1138 | ||
1557 | impl<'a> AstNode<'a> for ItemList<'a> { | 1139 | impl AstNode for ItemList { |
1558 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1140 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1559 | match syntax.kind() { | 1141 | match syntax.kind() { |
1560 | ITEM_LIST => Some(ItemList { syntax }), | 1142 | ITEM_LIST => Some(ItemList::from_repr(syntax.into_repr())), |
1561 | _ => None, | 1143 | _ => None, |
1562 | } | 1144 | } |
1563 | } | 1145 | } |
1564 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1146 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1565 | } | 1147 | fn to_owned(&self) -> TreePtr<ItemList> { TreePtr::cast(self.syntax.to_owned()) } |
1566 | |||
1567 | impl<R: TreeRoot<RaTypes>> ItemListNode<R> { | ||
1568 | pub fn borrowed(&self) -> ItemList { | ||
1569 | ItemListNode { syntax: self.syntax.borrowed() } | ||
1570 | } | ||
1571 | pub fn owned(&self) -> ItemListNode { | ||
1572 | ItemListNode { syntax: self.syntax.owned() } | ||
1573 | } | ||
1574 | } | 1148 | } |
1575 | 1149 | ||
1576 | 1150 | ||
1577 | impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} | 1151 | impl ast::FnDefOwner for ItemList {} |
1578 | impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} | 1152 | impl ast::ModuleItemOwner for ItemList {} |
1579 | impl<'a> ItemList<'a> { | 1153 | impl ItemList { |
1580 | pub fn impl_items(self) -> impl Iterator<Item = ImplItem<'a>> + 'a { | 1154 | pub fn impl_items(&self) -> impl Iterator<Item = &ImplItem> { |
1581 | super::children(self) | 1155 | super::children(self) |
1582 | } | 1156 | } |
1583 | } | 1157 | } |
1584 | 1158 | ||
1585 | // Label | 1159 | // Label |
1586 | #[derive(Debug, Clone, Copy,)] | 1160 | #[derive(Debug, PartialEq, Eq, Hash)] |
1587 | pub struct LabelNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1161 | #[repr(transparent)] |
1588 | pub(crate) syntax: SyntaxNode<R>, | 1162 | pub struct Label { |
1163 | pub(crate) syntax: SyntaxNode, | ||
1589 | } | 1164 | } |
1590 | pub type Label<'a> = LabelNode<RefRoot<'a>>; | 1165 | unsafe impl TransparentNewType for Label { |
1591 | 1166 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1592 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LabelNode<R1>> for LabelNode<R2> { | ||
1593 | fn eq(&self, other: &LabelNode<R1>) -> bool { self.syntax == other.syntax } | ||
1594 | } | ||
1595 | impl<R: TreeRoot<RaTypes>> Eq for LabelNode<R> {} | ||
1596 | impl<R: TreeRoot<RaTypes>> Hash for LabelNode<R> { | ||
1597 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1598 | } | 1167 | } |
1599 | 1168 | ||
1600 | impl<'a> AstNode<'a> for Label<'a> { | 1169 | impl AstNode for Label { |
1601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1170 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1602 | match syntax.kind() { | 1171 | match syntax.kind() { |
1603 | LABEL => Some(Label { syntax }), | 1172 | LABEL => Some(Label::from_repr(syntax.into_repr())), |
1604 | _ => None, | 1173 | _ => None, |
1605 | } | 1174 | } |
1606 | } | 1175 | } |
1607 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1176 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1608 | } | 1177 | fn to_owned(&self) -> TreePtr<Label> { TreePtr::cast(self.syntax.to_owned()) } |
1609 | |||
1610 | impl<R: TreeRoot<RaTypes>> LabelNode<R> { | ||
1611 | pub fn borrowed(&self) -> Label { | ||
1612 | LabelNode { syntax: self.syntax.borrowed() } | ||
1613 | } | ||
1614 | pub fn owned(&self) -> LabelNode { | ||
1615 | LabelNode { syntax: self.syntax.owned() } | ||
1616 | } | ||
1617 | } | 1178 | } |
1618 | 1179 | ||
1619 | 1180 | ||
1620 | impl<'a> Label<'a> {} | 1181 | impl Label {} |
1621 | 1182 | ||
1622 | // LambdaExpr | 1183 | // LambdaExpr |
1623 | #[derive(Debug, Clone, Copy,)] | 1184 | #[derive(Debug, PartialEq, Eq, Hash)] |
1624 | pub struct LambdaExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1185 | #[repr(transparent)] |
1625 | pub(crate) syntax: SyntaxNode<R>, | 1186 | pub struct LambdaExpr { |
1626 | } | 1187 | pub(crate) syntax: SyntaxNode, |
1627 | pub type LambdaExpr<'a> = LambdaExprNode<RefRoot<'a>>; | ||
1628 | |||
1629 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LambdaExprNode<R1>> for LambdaExprNode<R2> { | ||
1630 | fn eq(&self, other: &LambdaExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1631 | } | 1188 | } |
1632 | impl<R: TreeRoot<RaTypes>> Eq for LambdaExprNode<R> {} | 1189 | unsafe impl TransparentNewType for LambdaExpr { |
1633 | impl<R: TreeRoot<RaTypes>> Hash for LambdaExprNode<R> { | 1190 | type Repr = rowan::SyntaxNode<RaTypes>; |
1634 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1635 | } | 1191 | } |
1636 | 1192 | ||
1637 | impl<'a> AstNode<'a> for LambdaExpr<'a> { | 1193 | impl AstNode for LambdaExpr { |
1638 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1194 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1639 | match syntax.kind() { | 1195 | match syntax.kind() { |
1640 | LAMBDA_EXPR => Some(LambdaExpr { syntax }), | 1196 | LAMBDA_EXPR => Some(LambdaExpr::from_repr(syntax.into_repr())), |
1641 | _ => None, | 1197 | _ => None, |
1642 | } | 1198 | } |
1643 | } | 1199 | } |
1644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1200 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1645 | } | 1201 | fn to_owned(&self) -> TreePtr<LambdaExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1646 | |||
1647 | impl<R: TreeRoot<RaTypes>> LambdaExprNode<R> { | ||
1648 | pub fn borrowed(&self) -> LambdaExpr { | ||
1649 | LambdaExprNode { syntax: self.syntax.borrowed() } | ||
1650 | } | ||
1651 | pub fn owned(&self) -> LambdaExprNode { | ||
1652 | LambdaExprNode { syntax: self.syntax.owned() } | ||
1653 | } | ||
1654 | } | 1202 | } |
1655 | 1203 | ||
1656 | 1204 | ||
1657 | impl<'a> LambdaExpr<'a> { | 1205 | impl LambdaExpr { |
1658 | pub fn param_list(self) -> Option<ParamList<'a>> { | 1206 | pub fn param_list(&self) -> Option<&ParamList> { |
1659 | super::child_opt(self) | 1207 | super::child_opt(self) |
1660 | } | 1208 | } |
1661 | 1209 | ||
1662 | pub fn body(self) -> Option<Expr<'a>> { | 1210 | pub fn body(&self) -> Option<&Expr> { |
1663 | super::child_opt(self) | 1211 | super::child_opt(self) |
1664 | } | 1212 | } |
1665 | } | 1213 | } |
1666 | 1214 | ||
1667 | // LetStmt | 1215 | // LetStmt |
1668 | #[derive(Debug, Clone, Copy,)] | 1216 | #[derive(Debug, PartialEq, Eq, Hash)] |
1669 | pub struct LetStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1217 | #[repr(transparent)] |
1670 | pub(crate) syntax: SyntaxNode<R>, | 1218 | pub struct LetStmt { |
1671 | } | 1219 | pub(crate) syntax: SyntaxNode, |
1672 | pub type LetStmt<'a> = LetStmtNode<RefRoot<'a>>; | ||
1673 | |||
1674 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LetStmtNode<R1>> for LetStmtNode<R2> { | ||
1675 | fn eq(&self, other: &LetStmtNode<R1>) -> bool { self.syntax == other.syntax } | ||
1676 | } | 1220 | } |
1677 | impl<R: TreeRoot<RaTypes>> Eq for LetStmtNode<R> {} | 1221 | unsafe impl TransparentNewType for LetStmt { |
1678 | impl<R: TreeRoot<RaTypes>> Hash for LetStmtNode<R> { | 1222 | type Repr = rowan::SyntaxNode<RaTypes>; |
1679 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1680 | } | 1223 | } |
1681 | 1224 | ||
1682 | impl<'a> AstNode<'a> for LetStmt<'a> { | 1225 | impl AstNode for LetStmt { |
1683 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1226 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1684 | match syntax.kind() { | 1227 | match syntax.kind() { |
1685 | LET_STMT => Some(LetStmt { syntax }), | 1228 | LET_STMT => Some(LetStmt::from_repr(syntax.into_repr())), |
1686 | _ => None, | 1229 | _ => None, |
1687 | } | 1230 | } |
1688 | } | 1231 | } |
1689 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1232 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1690 | } | 1233 | fn to_owned(&self) -> TreePtr<LetStmt> { TreePtr::cast(self.syntax.to_owned()) } |
1691 | |||
1692 | impl<R: TreeRoot<RaTypes>> LetStmtNode<R> { | ||
1693 | pub fn borrowed(&self) -> LetStmt { | ||
1694 | LetStmtNode { syntax: self.syntax.borrowed() } | ||
1695 | } | ||
1696 | pub fn owned(&self) -> LetStmtNode { | ||
1697 | LetStmtNode { syntax: self.syntax.owned() } | ||
1698 | } | ||
1699 | } | 1234 | } |
1700 | 1235 | ||
1701 | 1236 | ||
1702 | impl<'a> LetStmt<'a> { | 1237 | impl LetStmt { |
1703 | pub fn pat(self) -> Option<Pat<'a>> { | 1238 | pub fn pat(&self) -> Option<&Pat> { |
1704 | super::child_opt(self) | 1239 | super::child_opt(self) |
1705 | } | 1240 | } |
1706 | 1241 | ||
1707 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1242 | pub fn type_ref(&self) -> Option<&TypeRef> { |
1708 | super::child_opt(self) | 1243 | super::child_opt(self) |
1709 | } | 1244 | } |
1710 | 1245 | ||
1711 | pub fn initializer(self) -> Option<Expr<'a>> { | 1246 | pub fn initializer(&self) -> Option<&Expr> { |
1712 | super::child_opt(self) | 1247 | super::child_opt(self) |
1713 | } | 1248 | } |
1714 | } | 1249 | } |
1715 | 1250 | ||
1716 | // Lifetime | 1251 | // Lifetime |
1717 | #[derive(Debug, Clone, Copy,)] | 1252 | #[derive(Debug, PartialEq, Eq, Hash)] |
1718 | pub struct LifetimeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1253 | #[repr(transparent)] |
1719 | pub(crate) syntax: SyntaxNode<R>, | 1254 | pub struct Lifetime { |
1255 | pub(crate) syntax: SyntaxNode, | ||
1720 | } | 1256 | } |
1721 | pub type Lifetime<'a> = LifetimeNode<RefRoot<'a>>; | 1257 | unsafe impl TransparentNewType for Lifetime { |
1722 | 1258 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1723 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeNode<R1>> for LifetimeNode<R2> { | ||
1724 | fn eq(&self, other: &LifetimeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1725 | } | ||
1726 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeNode<R> {} | ||
1727 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeNode<R> { | ||
1728 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1729 | } | 1259 | } |
1730 | 1260 | ||
1731 | impl<'a> AstNode<'a> for Lifetime<'a> { | 1261 | impl AstNode for Lifetime { |
1732 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1262 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1733 | match syntax.kind() { | 1263 | match syntax.kind() { |
1734 | LIFETIME => Some(Lifetime { syntax }), | 1264 | LIFETIME => Some(Lifetime::from_repr(syntax.into_repr())), |
1735 | _ => None, | 1265 | _ => None, |
1736 | } | 1266 | } |
1737 | } | 1267 | } |
1738 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1268 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1739 | } | 1269 | fn to_owned(&self) -> TreePtr<Lifetime> { TreePtr::cast(self.syntax.to_owned()) } |
1740 | |||
1741 | impl<R: TreeRoot<RaTypes>> LifetimeNode<R> { | ||
1742 | pub fn borrowed(&self) -> Lifetime { | ||
1743 | LifetimeNode { syntax: self.syntax.borrowed() } | ||
1744 | } | ||
1745 | pub fn owned(&self) -> LifetimeNode { | ||
1746 | LifetimeNode { syntax: self.syntax.owned() } | ||
1747 | } | ||
1748 | } | 1270 | } |
1749 | 1271 | ||
1750 | 1272 | ||
1751 | impl<'a> Lifetime<'a> {} | 1273 | impl Lifetime {} |
1752 | 1274 | ||
1753 | // LifetimeParam | 1275 | // LifetimeParam |
1754 | #[derive(Debug, Clone, Copy,)] | 1276 | #[derive(Debug, PartialEq, Eq, Hash)] |
1755 | pub struct LifetimeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1277 | #[repr(transparent)] |
1756 | pub(crate) syntax: SyntaxNode<R>, | 1278 | pub struct LifetimeParam { |
1757 | } | 1279 | pub(crate) syntax: SyntaxNode, |
1758 | pub type LifetimeParam<'a> = LifetimeParamNode<RefRoot<'a>>; | ||
1759 | |||
1760 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeParamNode<R1>> for LifetimeParamNode<R2> { | ||
1761 | fn eq(&self, other: &LifetimeParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
1762 | } | 1280 | } |
1763 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeParamNode<R> {} | 1281 | unsafe impl TransparentNewType for LifetimeParam { |
1764 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeParamNode<R> { | 1282 | type Repr = rowan::SyntaxNode<RaTypes>; |
1765 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1766 | } | 1283 | } |
1767 | 1284 | ||
1768 | impl<'a> AstNode<'a> for LifetimeParam<'a> { | 1285 | impl AstNode for LifetimeParam { |
1769 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1286 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1770 | match syntax.kind() { | 1287 | match syntax.kind() { |
1771 | LIFETIME_PARAM => Some(LifetimeParam { syntax }), | 1288 | LIFETIME_PARAM => Some(LifetimeParam::from_repr(syntax.into_repr())), |
1772 | _ => None, | 1289 | _ => None, |
1773 | } | 1290 | } |
1774 | } | 1291 | } |
1775 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1292 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1293 | fn to_owned(&self) -> TreePtr<LifetimeParam> { TreePtr::cast(self.syntax.to_owned()) } | ||
1776 | } | 1294 | } |
1777 | 1295 | ||
1778 | impl<R: TreeRoot<RaTypes>> LifetimeParamNode<R> { | ||
1779 | pub fn borrowed(&self) -> LifetimeParam { | ||
1780 | LifetimeParamNode { syntax: self.syntax.borrowed() } | ||
1781 | } | ||
1782 | pub fn owned(&self) -> LifetimeParamNode { | ||
1783 | LifetimeParamNode { syntax: self.syntax.owned() } | ||
1784 | } | ||
1785 | } | ||
1786 | 1296 | ||
1787 | 1297 | impl LifetimeParam { | |
1788 | impl<'a> LifetimeParam<'a> { | 1298 | pub fn lifetime(&self) -> Option<&Lifetime> { |
1789 | pub fn lifetime(self) -> Option<Lifetime<'a>> { | ||
1790 | super::child_opt(self) | 1299 | super::child_opt(self) |
1791 | } | 1300 | } |
1792 | } | 1301 | } |
1793 | 1302 | ||
1794 | // Literal | 1303 | // Literal |
1795 | #[derive(Debug, Clone, Copy,)] | 1304 | #[derive(Debug, PartialEq, Eq, Hash)] |
1796 | pub struct LiteralNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1305 | #[repr(transparent)] |
1797 | pub(crate) syntax: SyntaxNode<R>, | 1306 | pub struct Literal { |
1798 | } | 1307 | pub(crate) syntax: SyntaxNode, |
1799 | pub type Literal<'a> = LiteralNode<RefRoot<'a>>; | ||
1800 | |||
1801 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LiteralNode<R1>> for LiteralNode<R2> { | ||
1802 | fn eq(&self, other: &LiteralNode<R1>) -> bool { self.syntax == other.syntax } | ||
1803 | } | 1308 | } |
1804 | impl<R: TreeRoot<RaTypes>> Eq for LiteralNode<R> {} | 1309 | unsafe impl TransparentNewType for Literal { |
1805 | impl<R: TreeRoot<RaTypes>> Hash for LiteralNode<R> { | 1310 | type Repr = rowan::SyntaxNode<RaTypes>; |
1806 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1807 | } | 1311 | } |
1808 | 1312 | ||
1809 | impl<'a> AstNode<'a> for Literal<'a> { | 1313 | impl AstNode for Literal { |
1810 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1314 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1811 | match syntax.kind() { | 1315 | match syntax.kind() { |
1812 | LITERAL => Some(Literal { syntax }), | 1316 | LITERAL => Some(Literal::from_repr(syntax.into_repr())), |
1813 | _ => None, | 1317 | _ => None, |
1814 | } | 1318 | } |
1815 | } | 1319 | } |
1816 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1320 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1817 | } | 1321 | fn to_owned(&self) -> TreePtr<Literal> { TreePtr::cast(self.syntax.to_owned()) } |
1818 | |||
1819 | impl<R: TreeRoot<RaTypes>> LiteralNode<R> { | ||
1820 | pub fn borrowed(&self) -> Literal { | ||
1821 | LiteralNode { syntax: self.syntax.borrowed() } | ||
1822 | } | ||
1823 | pub fn owned(&self) -> LiteralNode { | ||
1824 | LiteralNode { syntax: self.syntax.owned() } | ||
1825 | } | ||
1826 | } | 1322 | } |
1827 | 1323 | ||
1828 | 1324 | ||
1829 | impl<'a> Literal<'a> {} | 1325 | impl Literal {} |
1830 | 1326 | ||
1831 | // LoopExpr | 1327 | // LoopExpr |
1832 | #[derive(Debug, Clone, Copy,)] | 1328 | #[derive(Debug, PartialEq, Eq, Hash)] |
1833 | pub struct LoopExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1329 | #[repr(transparent)] |
1834 | pub(crate) syntax: SyntaxNode<R>, | 1330 | pub struct LoopExpr { |
1331 | pub(crate) syntax: SyntaxNode, | ||
1835 | } | 1332 | } |
1836 | pub type LoopExpr<'a> = LoopExprNode<RefRoot<'a>>; | 1333 | unsafe impl TransparentNewType for LoopExpr { |
1837 | 1334 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1838 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LoopExprNode<R1>> for LoopExprNode<R2> { | ||
1839 | fn eq(&self, other: &LoopExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1840 | } | ||
1841 | impl<R: TreeRoot<RaTypes>> Eq for LoopExprNode<R> {} | ||
1842 | impl<R: TreeRoot<RaTypes>> Hash for LoopExprNode<R> { | ||
1843 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1844 | } | 1335 | } |
1845 | 1336 | ||
1846 | impl<'a> AstNode<'a> for LoopExpr<'a> { | 1337 | impl AstNode for LoopExpr { |
1847 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1338 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1848 | match syntax.kind() { | 1339 | match syntax.kind() { |
1849 | LOOP_EXPR => Some(LoopExpr { syntax }), | 1340 | LOOP_EXPR => Some(LoopExpr::from_repr(syntax.into_repr())), |
1850 | _ => None, | 1341 | _ => None, |
1851 | } | 1342 | } |
1852 | } | 1343 | } |
1853 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1344 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1854 | } | 1345 | fn to_owned(&self) -> TreePtr<LoopExpr> { TreePtr::cast(self.syntax.to_owned()) } |
1855 | |||
1856 | impl<R: TreeRoot<RaTypes>> LoopExprNode<R> { | ||
1857 | pub fn borrowed(&self) -> LoopExpr { | ||
1858 | LoopExprNode { syntax: self.syntax.borrowed() } | ||
1859 | } | ||
1860 | pub fn owned(&self) -> LoopExprNode { | ||
1861 | LoopExprNode { syntax: self.syntax.owned() } | ||
1862 | } | ||
1863 | } | 1346 | } |
1864 | 1347 | ||
1865 | 1348 | ||
1866 | impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} | 1349 | impl ast::LoopBodyOwner for LoopExpr {} |
1867 | impl<'a> LoopExpr<'a> {} | 1350 | impl LoopExpr {} |
1868 | 1351 | ||
1869 | // MacroCall | 1352 | // MacroCall |
1870 | #[derive(Debug, Clone, Copy,)] | 1353 | #[derive(Debug, PartialEq, Eq, Hash)] |
1871 | pub struct MacroCallNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1354 | #[repr(transparent)] |
1872 | pub(crate) syntax: SyntaxNode<R>, | 1355 | pub struct MacroCall { |
1356 | pub(crate) syntax: SyntaxNode, | ||
1873 | } | 1357 | } |
1874 | pub type MacroCall<'a> = MacroCallNode<RefRoot<'a>>; | 1358 | unsafe impl TransparentNewType for MacroCall { |
1875 | 1359 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1876 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MacroCallNode<R1>> for MacroCallNode<R2> { | ||
1877 | fn eq(&self, other: &MacroCallNode<R1>) -> bool { self.syntax == other.syntax } | ||
1878 | } | ||
1879 | impl<R: TreeRoot<RaTypes>> Eq for MacroCallNode<R> {} | ||
1880 | impl<R: TreeRoot<RaTypes>> Hash for MacroCallNode<R> { | ||
1881 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1882 | } | 1360 | } |
1883 | 1361 | ||
1884 | impl<'a> AstNode<'a> for MacroCall<'a> { | 1362 | impl AstNode for MacroCall { |
1885 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1363 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1886 | match syntax.kind() { | 1364 | match syntax.kind() { |
1887 | MACRO_CALL => Some(MacroCall { syntax }), | 1365 | MACRO_CALL => Some(MacroCall::from_repr(syntax.into_repr())), |
1888 | _ => None, | 1366 | _ => None, |
1889 | } | 1367 | } |
1890 | } | 1368 | } |
1891 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1369 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1892 | } | 1370 | fn to_owned(&self) -> TreePtr<MacroCall> { TreePtr::cast(self.syntax.to_owned()) } |
1893 | |||
1894 | impl<R: TreeRoot<RaTypes>> MacroCallNode<R> { | ||
1895 | pub fn borrowed(&self) -> MacroCall { | ||
1896 | MacroCallNode { syntax: self.syntax.borrowed() } | ||
1897 | } | ||
1898 | pub fn owned(&self) -> MacroCallNode { | ||
1899 | MacroCallNode { syntax: self.syntax.owned() } | ||
1900 | } | ||
1901 | } | 1371 | } |
1902 | 1372 | ||
1903 | 1373 | ||
1904 | impl<'a> MacroCall<'a> { | 1374 | impl MacroCall { |
1905 | pub fn token_tree(self) -> Option<TokenTree<'a>> { | 1375 | pub fn token_tree(&self) -> Option<&TokenTree> { |
1906 | super::child_opt(self) | 1376 | super::child_opt(self) |
1907 | } | 1377 | } |
1908 | 1378 | ||
1909 | pub fn path(self) -> Option<Path<'a>> { | 1379 | pub fn path(&self) -> Option<&Path> { |
1910 | super::child_opt(self) | 1380 | super::child_opt(self) |
1911 | } | 1381 | } |
1912 | } | 1382 | } |
1913 | 1383 | ||
1914 | // MatchArm | 1384 | // MatchArm |
1915 | #[derive(Debug, Clone, Copy,)] | 1385 | #[derive(Debug, PartialEq, Eq, Hash)] |
1916 | pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1386 | #[repr(transparent)] |
1917 | pub(crate) syntax: SyntaxNode<R>, | 1387 | pub struct MatchArm { |
1388 | pub(crate) syntax: SyntaxNode, | ||
1918 | } | 1389 | } |
1919 | pub type MatchArm<'a> = MatchArmNode<RefRoot<'a>>; | 1390 | unsafe impl TransparentNewType for MatchArm { |
1920 | 1391 | type Repr = rowan::SyntaxNode<RaTypes>; | |
1921 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmNode<R1>> for MatchArmNode<R2> { | ||
1922 | fn eq(&self, other: &MatchArmNode<R1>) -> bool { self.syntax == other.syntax } | ||
1923 | } | ||
1924 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmNode<R> {} | ||
1925 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmNode<R> { | ||
1926 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1927 | } | 1392 | } |
1928 | 1393 | ||
1929 | impl<'a> AstNode<'a> for MatchArm<'a> { | 1394 | impl AstNode for MatchArm { |
1930 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1395 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1931 | match syntax.kind() { | 1396 | match syntax.kind() { |
1932 | MATCH_ARM => Some(MatchArm { syntax }), | 1397 | MATCH_ARM => Some(MatchArm::from_repr(syntax.into_repr())), |
1933 | _ => None, | 1398 | _ => None, |
1934 | } | 1399 | } |
1935 | } | 1400 | } |
1936 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1401 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1402 | fn to_owned(&self) -> TreePtr<MatchArm> { TreePtr::cast(self.syntax.to_owned()) } | ||
1937 | } | 1403 | } |
1938 | 1404 | ||
1939 | impl<R: TreeRoot<RaTypes>> MatchArmNode<R> { | ||
1940 | pub fn borrowed(&self) -> MatchArm { | ||
1941 | MatchArmNode { syntax: self.syntax.borrowed() } | ||
1942 | } | ||
1943 | pub fn owned(&self) -> MatchArmNode { | ||
1944 | MatchArmNode { syntax: self.syntax.owned() } | ||
1945 | } | ||
1946 | } | ||
1947 | 1405 | ||
1948 | 1406 | impl MatchArm { | |
1949 | impl<'a> MatchArm<'a> { | 1407 | pub fn pats(&self) -> impl Iterator<Item = &Pat> { |
1950 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { | ||
1951 | super::children(self) | 1408 | super::children(self) |
1952 | } | 1409 | } |
1953 | 1410 | ||
1954 | pub fn guard(self) -> Option<MatchGuard<'a>> { | 1411 | pub fn guard(&self) -> Option<&MatchGuard> { |
1955 | super::child_opt(self) | 1412 | super::child_opt(self) |
1956 | } | 1413 | } |
1957 | 1414 | ||
1958 | pub fn expr(self) -> Option<Expr<'a>> { | 1415 | pub fn expr(&self) -> Option<&Expr> { |
1959 | super::child_opt(self) | 1416 | super::child_opt(self) |
1960 | } | 1417 | } |
1961 | } | 1418 | } |
1962 | 1419 | ||
1963 | // MatchArmList | 1420 | // MatchArmList |
1964 | #[derive(Debug, Clone, Copy,)] | 1421 | #[derive(Debug, PartialEq, Eq, Hash)] |
1965 | pub struct MatchArmListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1422 | #[repr(transparent)] |
1966 | pub(crate) syntax: SyntaxNode<R>, | 1423 | pub struct MatchArmList { |
1967 | } | 1424 | pub(crate) syntax: SyntaxNode, |
1968 | pub type MatchArmList<'a> = MatchArmListNode<RefRoot<'a>>; | ||
1969 | |||
1970 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmListNode<R1>> for MatchArmListNode<R2> { | ||
1971 | fn eq(&self, other: &MatchArmListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1972 | } | 1425 | } |
1973 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmListNode<R> {} | 1426 | unsafe impl TransparentNewType for MatchArmList { |
1974 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmListNode<R> { | 1427 | type Repr = rowan::SyntaxNode<RaTypes>; |
1975 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1976 | } | 1428 | } |
1977 | 1429 | ||
1978 | impl<'a> AstNode<'a> for MatchArmList<'a> { | 1430 | impl AstNode for MatchArmList { |
1979 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1431 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1980 | match syntax.kind() { | 1432 | match syntax.kind() { |
1981 | MATCH_ARM_LIST => Some(MatchArmList { syntax }), | 1433 | MATCH_ARM_LIST => Some(MatchArmList::from_repr(syntax.into_repr())), |
1982 | _ => None, | 1434 | _ => None, |
1983 | } | 1435 | } |
1984 | } | 1436 | } |
1985 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1437 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1438 | fn to_owned(&self) -> TreePtr<MatchArmList> { TreePtr::cast(self.syntax.to_owned()) } | ||
1986 | } | 1439 | } |
1987 | 1440 | ||
1988 | impl<R: TreeRoot<RaTypes>> MatchArmListNode<R> { | ||
1989 | pub fn borrowed(&self) -> MatchArmList { | ||
1990 | MatchArmListNode { syntax: self.syntax.borrowed() } | ||
1991 | } | ||
1992 | pub fn owned(&self) -> MatchArmListNode { | ||
1993 | MatchArmListNode { syntax: self.syntax.owned() } | ||
1994 | } | ||
1995 | } | ||
1996 | 1441 | ||
1997 | 1442 | impl MatchArmList { | |
1998 | impl<'a> MatchArmList<'a> { | 1443 | pub fn arms(&self) -> impl Iterator<Item = &MatchArm> { |
1999 | pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a { | ||
2000 | super::children(self) | 1444 | super::children(self) |
2001 | } | 1445 | } |
2002 | } | 1446 | } |
2003 | 1447 | ||
2004 | // MatchExpr | 1448 | // MatchExpr |
2005 | #[derive(Debug, Clone, Copy,)] | 1449 | #[derive(Debug, PartialEq, Eq, Hash)] |
2006 | pub struct MatchExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1450 | #[repr(transparent)] |
2007 | pub(crate) syntax: SyntaxNode<R>, | 1451 | pub struct MatchExpr { |
2008 | } | 1452 | pub(crate) syntax: SyntaxNode, |
2009 | pub type MatchExpr<'a> = MatchExprNode<RefRoot<'a>>; | ||
2010 | |||
2011 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchExprNode<R1>> for MatchExprNode<R2> { | ||
2012 | fn eq(&self, other: &MatchExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2013 | } | 1453 | } |
2014 | impl<R: TreeRoot<RaTypes>> Eq for MatchExprNode<R> {} | 1454 | unsafe impl TransparentNewType for MatchExpr { |
2015 | impl<R: TreeRoot<RaTypes>> Hash for MatchExprNode<R> { | 1455 | type Repr = rowan::SyntaxNode<RaTypes>; |
2016 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2017 | } | 1456 | } |
2018 | 1457 | ||
2019 | impl<'a> AstNode<'a> for MatchExpr<'a> { | 1458 | impl AstNode for MatchExpr { |
2020 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1459 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2021 | match syntax.kind() { | 1460 | match syntax.kind() { |
2022 | MATCH_EXPR => Some(MatchExpr { syntax }), | 1461 | MATCH_EXPR => Some(MatchExpr::from_repr(syntax.into_repr())), |
2023 | _ => None, | 1462 | _ => None, |
2024 | } | 1463 | } |
2025 | } | 1464 | } |
2026 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1465 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2027 | } | 1466 | fn to_owned(&self) -> TreePtr<MatchExpr> { TreePtr::cast(self.syntax.to_owned()) } |
2028 | |||
2029 | impl<R: TreeRoot<RaTypes>> MatchExprNode<R> { | ||
2030 | pub fn borrowed(&self) -> MatchExpr { | ||
2031 | MatchExprNode { syntax: self.syntax.borrowed() } | ||
2032 | } | ||
2033 | pub fn owned(&self) -> MatchExprNode { | ||
2034 | MatchExprNode { syntax: self.syntax.owned() } | ||
2035 | } | ||
2036 | } | 1467 | } |
2037 | 1468 | ||
2038 | 1469 | ||
2039 | impl<'a> MatchExpr<'a> { | 1470 | impl MatchExpr { |
2040 | pub fn expr(self) -> Option<Expr<'a>> { | 1471 | pub fn expr(&self) -> Option<&Expr> { |
2041 | super::child_opt(self) | 1472 | super::child_opt(self) |
2042 | } | 1473 | } |
2043 | 1474 | ||
2044 | pub fn match_arm_list(self) -> Option<MatchArmList<'a>> { | 1475 | pub fn match_arm_list(&self) -> Option<&MatchArmList> { |
2045 | super::child_opt(self) | 1476 | super::child_opt(self) |
2046 | } | 1477 | } |
2047 | } | 1478 | } |
2048 | 1479 | ||
2049 | // MatchGuard | 1480 | // MatchGuard |
2050 | #[derive(Debug, Clone, Copy,)] | 1481 | #[derive(Debug, PartialEq, Eq, Hash)] |
2051 | pub struct MatchGuardNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1482 | #[repr(transparent)] |
2052 | pub(crate) syntax: SyntaxNode<R>, | 1483 | pub struct MatchGuard { |
1484 | pub(crate) syntax: SyntaxNode, | ||
2053 | } | 1485 | } |
2054 | pub type MatchGuard<'a> = MatchGuardNode<RefRoot<'a>>; | 1486 | unsafe impl TransparentNewType for MatchGuard { |
2055 | 1487 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2056 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchGuardNode<R1>> for MatchGuardNode<R2> { | ||
2057 | fn eq(&self, other: &MatchGuardNode<R1>) -> bool { self.syntax == other.syntax } | ||
2058 | } | ||
2059 | impl<R: TreeRoot<RaTypes>> Eq for MatchGuardNode<R> {} | ||
2060 | impl<R: TreeRoot<RaTypes>> Hash for MatchGuardNode<R> { | ||
2061 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2062 | } | 1488 | } |
2063 | 1489 | ||
2064 | impl<'a> AstNode<'a> for MatchGuard<'a> { | 1490 | impl AstNode for MatchGuard { |
2065 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1491 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2066 | match syntax.kind() { | 1492 | match syntax.kind() { |
2067 | MATCH_GUARD => Some(MatchGuard { syntax }), | 1493 | MATCH_GUARD => Some(MatchGuard::from_repr(syntax.into_repr())), |
2068 | _ => None, | 1494 | _ => None, |
2069 | } | 1495 | } |
2070 | } | 1496 | } |
2071 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1497 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2072 | } | 1498 | fn to_owned(&self) -> TreePtr<MatchGuard> { TreePtr::cast(self.syntax.to_owned()) } |
2073 | |||
2074 | impl<R: TreeRoot<RaTypes>> MatchGuardNode<R> { | ||
2075 | pub fn borrowed(&self) -> MatchGuard { | ||
2076 | MatchGuardNode { syntax: self.syntax.borrowed() } | ||
2077 | } | ||
2078 | pub fn owned(&self) -> MatchGuardNode { | ||
2079 | MatchGuardNode { syntax: self.syntax.owned() } | ||
2080 | } | ||
2081 | } | 1499 | } |
2082 | 1500 | ||
2083 | 1501 | ||
2084 | impl<'a> MatchGuard<'a> {} | 1502 | impl MatchGuard {} |
2085 | 1503 | ||
2086 | // MethodCallExpr | 1504 | // MethodCallExpr |
2087 | #[derive(Debug, Clone, Copy,)] | 1505 | #[derive(Debug, PartialEq, Eq, Hash)] |
2088 | pub struct MethodCallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1506 | #[repr(transparent)] |
2089 | pub(crate) syntax: SyntaxNode<R>, | 1507 | pub struct MethodCallExpr { |
2090 | } | 1508 | pub(crate) syntax: SyntaxNode, |
2091 | pub type MethodCallExpr<'a> = MethodCallExprNode<RefRoot<'a>>; | ||
2092 | |||
2093 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MethodCallExprNode<R1>> for MethodCallExprNode<R2> { | ||
2094 | fn eq(&self, other: &MethodCallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2095 | } | 1509 | } |
2096 | impl<R: TreeRoot<RaTypes>> Eq for MethodCallExprNode<R> {} | 1510 | unsafe impl TransparentNewType for MethodCallExpr { |
2097 | impl<R: TreeRoot<RaTypes>> Hash for MethodCallExprNode<R> { | 1511 | type Repr = rowan::SyntaxNode<RaTypes>; |
2098 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2099 | } | 1512 | } |
2100 | 1513 | ||
2101 | impl<'a> AstNode<'a> for MethodCallExpr<'a> { | 1514 | impl AstNode for MethodCallExpr { |
2102 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1515 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2103 | match syntax.kind() { | 1516 | match syntax.kind() { |
2104 | METHOD_CALL_EXPR => Some(MethodCallExpr { syntax }), | 1517 | METHOD_CALL_EXPR => Some(MethodCallExpr::from_repr(syntax.into_repr())), |
2105 | _ => None, | 1518 | _ => None, |
2106 | } | 1519 | } |
2107 | } | 1520 | } |
2108 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1521 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1522 | fn to_owned(&self) -> TreePtr<MethodCallExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
2109 | } | 1523 | } |
2110 | 1524 | ||
2111 | impl<R: TreeRoot<RaTypes>> MethodCallExprNode<R> { | ||
2112 | pub fn borrowed(&self) -> MethodCallExpr { | ||
2113 | MethodCallExprNode { syntax: self.syntax.borrowed() } | ||
2114 | } | ||
2115 | pub fn owned(&self) -> MethodCallExprNode { | ||
2116 | MethodCallExprNode { syntax: self.syntax.owned() } | ||
2117 | } | ||
2118 | } | ||
2119 | 1525 | ||
2120 | 1526 | impl ast::ArgListOwner for MethodCallExpr {} | |
2121 | impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} | 1527 | impl MethodCallExpr { |
2122 | impl<'a> MethodCallExpr<'a> { | 1528 | pub fn expr(&self) -> Option<&Expr> { |
2123 | pub fn expr(self) -> Option<Expr<'a>> { | ||
2124 | super::child_opt(self) | 1529 | super::child_opt(self) |
2125 | } | 1530 | } |
2126 | 1531 | ||
2127 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 1532 | pub fn name_ref(&self) -> Option<&NameRef> { |
2128 | super::child_opt(self) | 1533 | super::child_opt(self) |
2129 | } | 1534 | } |
2130 | } | 1535 | } |
2131 | 1536 | ||
2132 | // Module | 1537 | // Module |
2133 | #[derive(Debug, Clone, Copy,)] | 1538 | #[derive(Debug, PartialEq, Eq, Hash)] |
2134 | pub struct ModuleNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1539 | #[repr(transparent)] |
2135 | pub(crate) syntax: SyntaxNode<R>, | 1540 | pub struct Module { |
2136 | } | 1541 | pub(crate) syntax: SyntaxNode, |
2137 | pub type Module<'a> = ModuleNode<RefRoot<'a>>; | ||
2138 | |||
2139 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ModuleNode<R1>> for ModuleNode<R2> { | ||
2140 | fn eq(&self, other: &ModuleNode<R1>) -> bool { self.syntax == other.syntax } | ||
2141 | } | 1542 | } |
2142 | impl<R: TreeRoot<RaTypes>> Eq for ModuleNode<R> {} | 1543 | unsafe impl TransparentNewType for Module { |
2143 | impl<R: TreeRoot<RaTypes>> Hash for ModuleNode<R> { | 1544 | type Repr = rowan::SyntaxNode<RaTypes>; |
2144 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2145 | } | 1545 | } |
2146 | 1546 | ||
2147 | impl<'a> AstNode<'a> for Module<'a> { | 1547 | impl AstNode for Module { |
2148 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1548 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2149 | match syntax.kind() { | 1549 | match syntax.kind() { |
2150 | MODULE => Some(Module { syntax }), | 1550 | MODULE => Some(Module::from_repr(syntax.into_repr())), |
2151 | _ => None, | 1551 | _ => None, |
2152 | } | 1552 | } |
2153 | } | 1553 | } |
2154 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1554 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1555 | fn to_owned(&self) -> TreePtr<Module> { TreePtr::cast(self.syntax.to_owned()) } | ||
2155 | } | 1556 | } |
2156 | 1557 | ||
2157 | impl<R: TreeRoot<RaTypes>> ModuleNode<R> { | ||
2158 | pub fn borrowed(&self) -> Module { | ||
2159 | ModuleNode { syntax: self.syntax.borrowed() } | ||
2160 | } | ||
2161 | pub fn owned(&self) -> ModuleNode { | ||
2162 | ModuleNode { syntax: self.syntax.owned() } | ||
2163 | } | ||
2164 | } | ||
2165 | 1558 | ||
2166 | 1559 | impl ast::VisibilityOwner for Module {} | |
2167 | impl<'a> ast::VisibilityOwner<'a> for Module<'a> {} | 1560 | impl ast::NameOwner for Module {} |
2168 | impl<'a> ast::NameOwner<'a> for Module<'a> {} | 1561 | impl ast::AttrsOwner for Module {} |
2169 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} | 1562 | impl ast::DocCommentsOwner for Module {} |
2170 | impl<'a> ast::DocCommentsOwner<'a> for Module<'a> {} | 1563 | impl Module { |
2171 | impl<'a> Module<'a> { | 1564 | pub fn item_list(&self) -> Option<&ItemList> { |
2172 | pub fn item_list(self) -> Option<ItemList<'a>> { | ||
2173 | super::child_opt(self) | 1565 | super::child_opt(self) |
2174 | } | 1566 | } |
2175 | } | 1567 | } |
2176 | 1568 | ||
2177 | // ModuleItem | 1569 | // ModuleItem |
2178 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1570 | #[derive(Debug, PartialEq, Eq, Hash)] |
2179 | pub enum ModuleItem<'a> { | 1571 | #[repr(transparent)] |
2180 | StructDef(StructDef<'a>), | 1572 | pub struct ModuleItem { |
2181 | EnumDef(EnumDef<'a>), | 1573 | pub(crate) syntax: SyntaxNode, |
2182 | FnDef(FnDef<'a>), | 1574 | } |
2183 | TraitDef(TraitDef<'a>), | 1575 | unsafe impl TransparentNewType for ModuleItem { |
2184 | TypeDef(TypeDef<'a>), | 1576 | type Repr = rowan::SyntaxNode<RaTypes>; |
2185 | ImplBlock(ImplBlock<'a>), | ||
2186 | UseItem(UseItem<'a>), | ||
2187 | ExternCrateItem(ExternCrateItem<'a>), | ||
2188 | ConstDef(ConstDef<'a>), | ||
2189 | StaticDef(StaticDef<'a>), | ||
2190 | Module(Module<'a>), | ||
2191 | } | ||
2192 | |||
2193 | impl<'a> AstNode<'a> for ModuleItem<'a> { | ||
2194 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
2195 | match syntax.kind() { | ||
2196 | STRUCT_DEF => Some(ModuleItem::StructDef(StructDef { syntax })), | ||
2197 | ENUM_DEF => Some(ModuleItem::EnumDef(EnumDef { syntax })), | ||
2198 | FN_DEF => Some(ModuleItem::FnDef(FnDef { syntax })), | ||
2199 | TRAIT_DEF => Some(ModuleItem::TraitDef(TraitDef { syntax })), | ||
2200 | TYPE_DEF => Some(ModuleItem::TypeDef(TypeDef { syntax })), | ||
2201 | IMPL_BLOCK => Some(ModuleItem::ImplBlock(ImplBlock { syntax })), | ||
2202 | USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })), | ||
2203 | EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })), | ||
2204 | CONST_DEF => Some(ModuleItem::ConstDef(ConstDef { syntax })), | ||
2205 | STATIC_DEF => Some(ModuleItem::StaticDef(StaticDef { syntax })), | ||
2206 | MODULE => Some(ModuleItem::Module(Module { syntax })), | ||
2207 | _ => None, | ||
2208 | } | ||
2209 | } | ||
2210 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
2211 | match self { | ||
2212 | ModuleItem::StructDef(inner) => inner.syntax(), | ||
2213 | ModuleItem::EnumDef(inner) => inner.syntax(), | ||
2214 | ModuleItem::FnDef(inner) => inner.syntax(), | ||
2215 | ModuleItem::TraitDef(inner) => inner.syntax(), | ||
2216 | ModuleItem::TypeDef(inner) => inner.syntax(), | ||
2217 | ModuleItem::ImplBlock(inner) => inner.syntax(), | ||
2218 | ModuleItem::UseItem(inner) => inner.syntax(), | ||
2219 | ModuleItem::ExternCrateItem(inner) => inner.syntax(), | ||
2220 | ModuleItem::ConstDef(inner) => inner.syntax(), | ||
2221 | ModuleItem::StaticDef(inner) => inner.syntax(), | ||
2222 | ModuleItem::Module(inner) => inner.syntax(), | ||
2223 | } | ||
2224 | } | ||
2225 | } | 1577 | } |
2226 | 1578 | ||
2227 | impl<'a> ModuleItem<'a> {} | 1579 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1580 | pub enum ModuleItemKind<'a> { | ||
1581 | StructDef(&'a StructDef), | ||
1582 | EnumDef(&'a EnumDef), | ||
1583 | FnDef(&'a FnDef), | ||
1584 | TraitDef(&'a TraitDef), | ||
1585 | TypeDef(&'a TypeDef), | ||
1586 | ImplBlock(&'a ImplBlock), | ||
1587 | UseItem(&'a UseItem), | ||
1588 | ExternCrateItem(&'a ExternCrateItem), | ||
1589 | ConstDef(&'a ConstDef), | ||
1590 | StaticDef(&'a StaticDef), | ||
1591 | Module(&'a Module), | ||
1592 | } | ||
1593 | |||
1594 | impl AstNode for ModuleItem { | ||
1595 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
1596 | match syntax.kind() { | ||
1597 | | STRUCT_DEF | ||
1598 | | ENUM_DEF | ||
1599 | | FN_DEF | ||
1600 | | TRAIT_DEF | ||
1601 | | TYPE_DEF | ||
1602 | | IMPL_BLOCK | ||
1603 | | USE_ITEM | ||
1604 | | EXTERN_CRATE_ITEM | ||
1605 | | CONST_DEF | ||
1606 | | STATIC_DEF | ||
1607 | | MODULE => Some(ModuleItem::from_repr(syntax.into_repr())), | ||
1608 | _ => None, | ||
1609 | } | ||
1610 | } | ||
1611 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1612 | fn to_owned(&self) -> TreePtr<ModuleItem> { TreePtr::cast(self.syntax.to_owned()) } | ||
1613 | } | ||
1614 | |||
1615 | impl ModuleItem { | ||
1616 | pub fn kind(&self) -> ModuleItemKind { | ||
1617 | match self.syntax.kind() { | ||
1618 | STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(&self.syntax).unwrap()), | ||
1619 | ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()), | ||
1620 | FN_DEF => ModuleItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), | ||
1621 | TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(&self.syntax).unwrap()), | ||
1622 | TYPE_DEF => ModuleItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), | ||
1623 | IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(&self.syntax).unwrap()), | ||
1624 | USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(&self.syntax).unwrap()), | ||
1625 | EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(&self.syntax).unwrap()), | ||
1626 | CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), | ||
1627 | STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(&self.syntax).unwrap()), | ||
1628 | MODULE => ModuleItemKind::Module(Module::cast(&self.syntax).unwrap()), | ||
1629 | _ => unreachable!(), | ||
1630 | } | ||
1631 | } | ||
1632 | } | ||
1633 | |||
1634 | impl ModuleItem {} | ||
2228 | 1635 | ||
2229 | // Name | 1636 | // Name |
2230 | #[derive(Debug, Clone, Copy,)] | 1637 | #[derive(Debug, PartialEq, Eq, Hash)] |
2231 | pub struct NameNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1638 | #[repr(transparent)] |
2232 | pub(crate) syntax: SyntaxNode<R>, | 1639 | pub struct Name { |
2233 | } | 1640 | pub(crate) syntax: SyntaxNode, |
2234 | pub type Name<'a> = NameNode<RefRoot<'a>>; | ||
2235 | |||
2236 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameNode<R1>> for NameNode<R2> { | ||
2237 | fn eq(&self, other: &NameNode<R1>) -> bool { self.syntax == other.syntax } | ||
2238 | } | 1641 | } |
2239 | impl<R: TreeRoot<RaTypes>> Eq for NameNode<R> {} | 1642 | unsafe impl TransparentNewType for Name { |
2240 | impl<R: TreeRoot<RaTypes>> Hash for NameNode<R> { | 1643 | type Repr = rowan::SyntaxNode<RaTypes>; |
2241 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2242 | } | 1644 | } |
2243 | 1645 | ||
2244 | impl<'a> AstNode<'a> for Name<'a> { | 1646 | impl AstNode for Name { |
2245 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1647 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2246 | match syntax.kind() { | 1648 | match syntax.kind() { |
2247 | NAME => Some(Name { syntax }), | 1649 | NAME => Some(Name::from_repr(syntax.into_repr())), |
2248 | _ => None, | 1650 | _ => None, |
2249 | } | 1651 | } |
2250 | } | 1652 | } |
2251 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1653 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1654 | fn to_owned(&self) -> TreePtr<Name> { TreePtr::cast(self.syntax.to_owned()) } | ||
2252 | } | 1655 | } |
2253 | 1656 | ||
2254 | impl<R: TreeRoot<RaTypes>> NameNode<R> { | ||
2255 | pub fn borrowed(&self) -> Name { | ||
2256 | NameNode { syntax: self.syntax.borrowed() } | ||
2257 | } | ||
2258 | pub fn owned(&self) -> NameNode { | ||
2259 | NameNode { syntax: self.syntax.owned() } | ||
2260 | } | ||
2261 | } | ||
2262 | 1657 | ||
2263 | 1658 | impl Name {} | |
2264 | impl<'a> Name<'a> {} | ||
2265 | 1659 | ||
2266 | // NameRef | 1660 | // NameRef |
2267 | #[derive(Debug, Clone, Copy,)] | 1661 | #[derive(Debug, PartialEq, Eq, Hash)] |
2268 | pub struct NameRefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1662 | #[repr(transparent)] |
2269 | pub(crate) syntax: SyntaxNode<R>, | 1663 | pub struct NameRef { |
2270 | } | 1664 | pub(crate) syntax: SyntaxNode, |
2271 | pub type NameRef<'a> = NameRefNode<RefRoot<'a>>; | ||
2272 | |||
2273 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameRefNode<R1>> for NameRefNode<R2> { | ||
2274 | fn eq(&self, other: &NameRefNode<R1>) -> bool { self.syntax == other.syntax } | ||
2275 | } | 1665 | } |
2276 | impl<R: TreeRoot<RaTypes>> Eq for NameRefNode<R> {} | 1666 | unsafe impl TransparentNewType for NameRef { |
2277 | impl<R: TreeRoot<RaTypes>> Hash for NameRefNode<R> { | 1667 | type Repr = rowan::SyntaxNode<RaTypes>; |
2278 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2279 | } | 1668 | } |
2280 | 1669 | ||
2281 | impl<'a> AstNode<'a> for NameRef<'a> { | 1670 | impl AstNode for NameRef { |
2282 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1671 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2283 | match syntax.kind() { | 1672 | match syntax.kind() { |
2284 | NAME_REF => Some(NameRef { syntax }), | 1673 | NAME_REF => Some(NameRef::from_repr(syntax.into_repr())), |
2285 | _ => None, | 1674 | _ => None, |
2286 | } | 1675 | } |
2287 | } | 1676 | } |
2288 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1677 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1678 | fn to_owned(&self) -> TreePtr<NameRef> { TreePtr::cast(self.syntax.to_owned()) } | ||
2289 | } | 1679 | } |
2290 | 1680 | ||
2291 | impl<R: TreeRoot<RaTypes>> NameRefNode<R> { | ||
2292 | pub fn borrowed(&self) -> NameRef { | ||
2293 | NameRefNode { syntax: self.syntax.borrowed() } | ||
2294 | } | ||
2295 | pub fn owned(&self) -> NameRefNode { | ||
2296 | NameRefNode { syntax: self.syntax.owned() } | ||
2297 | } | ||
2298 | } | ||
2299 | 1681 | ||
2300 | 1682 | impl NameRef {} | |
2301 | impl<'a> NameRef<'a> {} | ||
2302 | 1683 | ||
2303 | // NamedField | 1684 | // NamedField |
2304 | #[derive(Debug, Clone, Copy,)] | 1685 | #[derive(Debug, PartialEq, Eq, Hash)] |
2305 | pub struct NamedFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1686 | #[repr(transparent)] |
2306 | pub(crate) syntax: SyntaxNode<R>, | 1687 | pub struct NamedField { |
1688 | pub(crate) syntax: SyntaxNode, | ||
2307 | } | 1689 | } |
2308 | pub type NamedField<'a> = NamedFieldNode<RefRoot<'a>>; | 1690 | unsafe impl TransparentNewType for NamedField { |
2309 | 1691 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2310 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldNode<R1>> for NamedFieldNode<R2> { | ||
2311 | fn eq(&self, other: &NamedFieldNode<R1>) -> bool { self.syntax == other.syntax } | ||
2312 | } | ||
2313 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldNode<R> {} | ||
2314 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldNode<R> { | ||
2315 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2316 | } | 1692 | } |
2317 | 1693 | ||
2318 | impl<'a> AstNode<'a> for NamedField<'a> { | 1694 | impl AstNode for NamedField { |
2319 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1695 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2320 | match syntax.kind() { | 1696 | match syntax.kind() { |
2321 | NAMED_FIELD => Some(NamedField { syntax }), | 1697 | NAMED_FIELD => Some(NamedField::from_repr(syntax.into_repr())), |
2322 | _ => None, | 1698 | _ => None, |
2323 | } | 1699 | } |
2324 | } | 1700 | } |
2325 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1701 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2326 | } | 1702 | fn to_owned(&self) -> TreePtr<NamedField> { TreePtr::cast(self.syntax.to_owned()) } |
2327 | |||
2328 | impl<R: TreeRoot<RaTypes>> NamedFieldNode<R> { | ||
2329 | pub fn borrowed(&self) -> NamedField { | ||
2330 | NamedFieldNode { syntax: self.syntax.borrowed() } | ||
2331 | } | ||
2332 | pub fn owned(&self) -> NamedFieldNode { | ||
2333 | NamedFieldNode { syntax: self.syntax.owned() } | ||
2334 | } | ||
2335 | } | 1703 | } |
2336 | 1704 | ||
2337 | 1705 | ||
2338 | impl<'a> NamedField<'a> { | 1706 | impl NamedField { |
2339 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 1707 | pub fn name_ref(&self) -> Option<&NameRef> { |
2340 | super::child_opt(self) | 1708 | super::child_opt(self) |
2341 | } | 1709 | } |
2342 | 1710 | ||
2343 | pub fn expr(self) -> Option<Expr<'a>> { | 1711 | pub fn expr(&self) -> Option<&Expr> { |
2344 | super::child_opt(self) | 1712 | super::child_opt(self) |
2345 | } | 1713 | } |
2346 | } | 1714 | } |
2347 | 1715 | ||
2348 | // NamedFieldDef | 1716 | // NamedFieldDef |
2349 | #[derive(Debug, Clone, Copy,)] | 1717 | #[derive(Debug, PartialEq, Eq, Hash)] |
2350 | pub struct NamedFieldDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1718 | #[repr(transparent)] |
2351 | pub(crate) syntax: SyntaxNode<R>, | 1719 | pub struct NamedFieldDef { |
1720 | pub(crate) syntax: SyntaxNode, | ||
2352 | } | 1721 | } |
2353 | pub type NamedFieldDef<'a> = NamedFieldDefNode<RefRoot<'a>>; | 1722 | unsafe impl TransparentNewType for NamedFieldDef { |
2354 | 1723 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2355 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefNode<R1>> for NamedFieldDefNode<R2> { | ||
2356 | fn eq(&self, other: &NamedFieldDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
2357 | } | ||
2358 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefNode<R> {} | ||
2359 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefNode<R> { | ||
2360 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2361 | } | 1724 | } |
2362 | 1725 | ||
2363 | impl<'a> AstNode<'a> for NamedFieldDef<'a> { | 1726 | impl AstNode for NamedFieldDef { |
2364 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1727 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2365 | match syntax.kind() { | 1728 | match syntax.kind() { |
2366 | NAMED_FIELD_DEF => Some(NamedFieldDef { syntax }), | 1729 | NAMED_FIELD_DEF => Some(NamedFieldDef::from_repr(syntax.into_repr())), |
2367 | _ => None, | 1730 | _ => None, |
2368 | } | 1731 | } |
2369 | } | 1732 | } |
2370 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1733 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1734 | fn to_owned(&self) -> TreePtr<NamedFieldDef> { TreePtr::cast(self.syntax.to_owned()) } | ||
2371 | } | 1735 | } |
2372 | 1736 | ||
2373 | impl<R: TreeRoot<RaTypes>> NamedFieldDefNode<R> { | ||
2374 | pub fn borrowed(&self) -> NamedFieldDef { | ||
2375 | NamedFieldDefNode { syntax: self.syntax.borrowed() } | ||
2376 | } | ||
2377 | pub fn owned(&self) -> NamedFieldDefNode { | ||
2378 | NamedFieldDefNode { syntax: self.syntax.owned() } | ||
2379 | } | ||
2380 | } | ||
2381 | 1737 | ||
2382 | 1738 | impl ast::VisibilityOwner for NamedFieldDef {} | |
2383 | impl<'a> ast::VisibilityOwner<'a> for NamedFieldDef<'a> {} | 1739 | impl ast::NameOwner for NamedFieldDef {} |
2384 | impl<'a> ast::NameOwner<'a> for NamedFieldDef<'a> {} | 1740 | impl ast::AttrsOwner for NamedFieldDef {} |
2385 | impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {} | 1741 | impl NamedFieldDef { |
2386 | impl<'a> NamedFieldDef<'a> { | 1742 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2387 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
2388 | super::child_opt(self) | 1743 | super::child_opt(self) |
2389 | } | 1744 | } |
2390 | } | 1745 | } |
2391 | 1746 | ||
2392 | // NamedFieldDefList | 1747 | // NamedFieldDefList |
2393 | #[derive(Debug, Clone, Copy,)] | 1748 | #[derive(Debug, PartialEq, Eq, Hash)] |
2394 | pub struct NamedFieldDefListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1749 | #[repr(transparent)] |
2395 | pub(crate) syntax: SyntaxNode<R>, | 1750 | pub struct NamedFieldDefList { |
2396 | } | 1751 | pub(crate) syntax: SyntaxNode, |
2397 | pub type NamedFieldDefList<'a> = NamedFieldDefListNode<RefRoot<'a>>; | ||
2398 | |||
2399 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefListNode<R1>> for NamedFieldDefListNode<R2> { | ||
2400 | fn eq(&self, other: &NamedFieldDefListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2401 | } | 1752 | } |
2402 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefListNode<R> {} | 1753 | unsafe impl TransparentNewType for NamedFieldDefList { |
2403 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefListNode<R> { | 1754 | type Repr = rowan::SyntaxNode<RaTypes>; |
2404 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2405 | } | 1755 | } |
2406 | 1756 | ||
2407 | impl<'a> AstNode<'a> for NamedFieldDefList<'a> { | 1757 | impl AstNode for NamedFieldDefList { |
2408 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1758 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2409 | match syntax.kind() { | 1759 | match syntax.kind() { |
2410 | NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList { syntax }), | 1760 | NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList::from_repr(syntax.into_repr())), |
2411 | _ => None, | 1761 | _ => None, |
2412 | } | 1762 | } |
2413 | } | 1763 | } |
2414 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1764 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1765 | fn to_owned(&self) -> TreePtr<NamedFieldDefList> { TreePtr::cast(self.syntax.to_owned()) } | ||
2415 | } | 1766 | } |
2416 | 1767 | ||
2417 | impl<R: TreeRoot<RaTypes>> NamedFieldDefListNode<R> { | ||
2418 | pub fn borrowed(&self) -> NamedFieldDefList { | ||
2419 | NamedFieldDefListNode { syntax: self.syntax.borrowed() } | ||
2420 | } | ||
2421 | pub fn owned(&self) -> NamedFieldDefListNode { | ||
2422 | NamedFieldDefListNode { syntax: self.syntax.owned() } | ||
2423 | } | ||
2424 | } | ||
2425 | 1768 | ||
2426 | 1769 | impl NamedFieldDefList { | |
2427 | impl<'a> NamedFieldDefList<'a> { | 1770 | pub fn fields(&self) -> impl Iterator<Item = &NamedFieldDef> { |
2428 | pub fn fields(self) -> impl Iterator<Item = NamedFieldDef<'a>> + 'a { | ||
2429 | super::children(self) | 1771 | super::children(self) |
2430 | } | 1772 | } |
2431 | } | 1773 | } |
2432 | 1774 | ||
2433 | // NamedFieldList | 1775 | // NamedFieldList |
2434 | #[derive(Debug, Clone, Copy,)] | 1776 | #[derive(Debug, PartialEq, Eq, Hash)] |
2435 | pub struct NamedFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1777 | #[repr(transparent)] |
2436 | pub(crate) syntax: SyntaxNode<R>, | 1778 | pub struct NamedFieldList { |
2437 | } | 1779 | pub(crate) syntax: SyntaxNode, |
2438 | pub type NamedFieldList<'a> = NamedFieldListNode<RefRoot<'a>>; | ||
2439 | |||
2440 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldListNode<R1>> for NamedFieldListNode<R2> { | ||
2441 | fn eq(&self, other: &NamedFieldListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2442 | } | 1780 | } |
2443 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldListNode<R> {} | 1781 | unsafe impl TransparentNewType for NamedFieldList { |
2444 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldListNode<R> { | 1782 | type Repr = rowan::SyntaxNode<RaTypes>; |
2445 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2446 | } | 1783 | } |
2447 | 1784 | ||
2448 | impl<'a> AstNode<'a> for NamedFieldList<'a> { | 1785 | impl AstNode for NamedFieldList { |
2449 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1786 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2450 | match syntax.kind() { | 1787 | match syntax.kind() { |
2451 | NAMED_FIELD_LIST => Some(NamedFieldList { syntax }), | 1788 | NAMED_FIELD_LIST => Some(NamedFieldList::from_repr(syntax.into_repr())), |
2452 | _ => None, | 1789 | _ => None, |
2453 | } | 1790 | } |
2454 | } | 1791 | } |
2455 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1792 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2456 | } | 1793 | fn to_owned(&self) -> TreePtr<NamedFieldList> { TreePtr::cast(self.syntax.to_owned()) } |
2457 | |||
2458 | impl<R: TreeRoot<RaTypes>> NamedFieldListNode<R> { | ||
2459 | pub fn borrowed(&self) -> NamedFieldList { | ||
2460 | NamedFieldListNode { syntax: self.syntax.borrowed() } | ||
2461 | } | ||
2462 | pub fn owned(&self) -> NamedFieldListNode { | ||
2463 | NamedFieldListNode { syntax: self.syntax.owned() } | ||
2464 | } | ||
2465 | } | 1794 | } |
2466 | 1795 | ||
2467 | 1796 | ||
2468 | impl<'a> NamedFieldList<'a> { | 1797 | impl NamedFieldList { |
2469 | pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a { | 1798 | pub fn fields(&self) -> impl Iterator<Item = &NamedField> { |
2470 | super::children(self) | 1799 | super::children(self) |
2471 | } | 1800 | } |
2472 | } | 1801 | } |
2473 | 1802 | ||
2474 | // NeverType | 1803 | // NeverType |
2475 | #[derive(Debug, Clone, Copy,)] | 1804 | #[derive(Debug, PartialEq, Eq, Hash)] |
2476 | pub struct NeverTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1805 | #[repr(transparent)] |
2477 | pub(crate) syntax: SyntaxNode<R>, | 1806 | pub struct NeverType { |
2478 | } | 1807 | pub(crate) syntax: SyntaxNode, |
2479 | pub type NeverType<'a> = NeverTypeNode<RefRoot<'a>>; | ||
2480 | |||
2481 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NeverTypeNode<R1>> for NeverTypeNode<R2> { | ||
2482 | fn eq(&self, other: &NeverTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2483 | } | 1808 | } |
2484 | impl<R: TreeRoot<RaTypes>> Eq for NeverTypeNode<R> {} | 1809 | unsafe impl TransparentNewType for NeverType { |
2485 | impl<R: TreeRoot<RaTypes>> Hash for NeverTypeNode<R> { | 1810 | type Repr = rowan::SyntaxNode<RaTypes>; |
2486 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2487 | } | 1811 | } |
2488 | 1812 | ||
2489 | impl<'a> AstNode<'a> for NeverType<'a> { | 1813 | impl AstNode for NeverType { |
2490 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1814 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2491 | match syntax.kind() { | 1815 | match syntax.kind() { |
2492 | NEVER_TYPE => Some(NeverType { syntax }), | 1816 | NEVER_TYPE => Some(NeverType::from_repr(syntax.into_repr())), |
2493 | _ => None, | 1817 | _ => None, |
2494 | } | 1818 | } |
2495 | } | 1819 | } |
2496 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1820 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2497 | } | 1821 | fn to_owned(&self) -> TreePtr<NeverType> { TreePtr::cast(self.syntax.to_owned()) } |
2498 | |||
2499 | impl<R: TreeRoot<RaTypes>> NeverTypeNode<R> { | ||
2500 | pub fn borrowed(&self) -> NeverType { | ||
2501 | NeverTypeNode { syntax: self.syntax.borrowed() } | ||
2502 | } | ||
2503 | pub fn owned(&self) -> NeverTypeNode { | ||
2504 | NeverTypeNode { syntax: self.syntax.owned() } | ||
2505 | } | ||
2506 | } | 1822 | } |
2507 | 1823 | ||
2508 | 1824 | ||
2509 | impl<'a> NeverType<'a> {} | 1825 | impl NeverType {} |
2510 | 1826 | ||
2511 | // NominalDef | 1827 | // NominalDef |
1828 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1829 | #[repr(transparent)] | ||
1830 | pub struct NominalDef { | ||
1831 | pub(crate) syntax: SyntaxNode, | ||
1832 | } | ||
1833 | unsafe impl TransparentNewType for NominalDef { | ||
1834 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1835 | } | ||
1836 | |||
2512 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1837 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2513 | pub enum NominalDef<'a> { | 1838 | pub enum NominalDefKind<'a> { |
2514 | StructDef(StructDef<'a>), | 1839 | StructDef(&'a StructDef), |
2515 | EnumDef(EnumDef<'a>), | 1840 | EnumDef(&'a EnumDef), |
2516 | } | 1841 | } |
2517 | 1842 | ||
2518 | impl<'a> AstNode<'a> for NominalDef<'a> { | 1843 | impl AstNode for NominalDef { |
2519 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1844 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2520 | match syntax.kind() { | 1845 | match syntax.kind() { |
2521 | STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })), | 1846 | | STRUCT_DEF |
2522 | ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })), | 1847 | | ENUM_DEF => Some(NominalDef::from_repr(syntax.into_repr())), |
2523 | _ => None, | 1848 | _ => None, |
2524 | } | 1849 | } |
2525 | } | 1850 | } |
2526 | fn syntax(self) -> SyntaxNodeRef<'a> { | 1851 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2527 | match self { | 1852 | fn to_owned(&self) -> TreePtr<NominalDef> { TreePtr::cast(self.syntax.to_owned()) } |
2528 | NominalDef::StructDef(inner) => inner.syntax(), | 1853 | } |
2529 | NominalDef::EnumDef(inner) => inner.syntax(), | 1854 | |
1855 | impl NominalDef { | ||
1856 | pub fn kind(&self) -> NominalDefKind { | ||
1857 | match self.syntax.kind() { | ||
1858 | STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(&self.syntax).unwrap()), | ||
1859 | ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()), | ||
1860 | _ => unreachable!(), | ||
2530 | } | 1861 | } |
2531 | } | 1862 | } |
2532 | } | 1863 | } |
2533 | 1864 | ||
2534 | impl<'a> ast::NameOwner<'a> for NominalDef<'a> {} | 1865 | impl ast::NameOwner for NominalDef {} |
2535 | impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {} | 1866 | impl ast::TypeParamsOwner for NominalDef {} |
2536 | impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} | 1867 | impl ast::AttrsOwner for NominalDef {} |
2537 | impl<'a> NominalDef<'a> {} | 1868 | impl NominalDef {} |
2538 | 1869 | ||
2539 | // Param | 1870 | // Param |
2540 | #[derive(Debug, Clone, Copy,)] | 1871 | #[derive(Debug, PartialEq, Eq, Hash)] |
2541 | pub struct ParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1872 | #[repr(transparent)] |
2542 | pub(crate) syntax: SyntaxNode<R>, | 1873 | pub struct Param { |
2543 | } | 1874 | pub(crate) syntax: SyntaxNode, |
2544 | pub type Param<'a> = ParamNode<RefRoot<'a>>; | ||
2545 | |||
2546 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamNode<R1>> for ParamNode<R2> { | ||
2547 | fn eq(&self, other: &ParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
2548 | } | 1875 | } |
2549 | impl<R: TreeRoot<RaTypes>> Eq for ParamNode<R> {} | 1876 | unsafe impl TransparentNewType for Param { |
2550 | impl<R: TreeRoot<RaTypes>> Hash for ParamNode<R> { | 1877 | type Repr = rowan::SyntaxNode<RaTypes>; |
2551 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2552 | } | 1878 | } |
2553 | 1879 | ||
2554 | impl<'a> AstNode<'a> for Param<'a> { | 1880 | impl AstNode for Param { |
2555 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1881 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2556 | match syntax.kind() { | 1882 | match syntax.kind() { |
2557 | PARAM => Some(Param { syntax }), | 1883 | PARAM => Some(Param::from_repr(syntax.into_repr())), |
2558 | _ => None, | 1884 | _ => None, |
2559 | } | 1885 | } |
2560 | } | 1886 | } |
2561 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1887 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2562 | } | 1888 | fn to_owned(&self) -> TreePtr<Param> { TreePtr::cast(self.syntax.to_owned()) } |
2563 | |||
2564 | impl<R: TreeRoot<RaTypes>> ParamNode<R> { | ||
2565 | pub fn borrowed(&self) -> Param { | ||
2566 | ParamNode { syntax: self.syntax.borrowed() } | ||
2567 | } | ||
2568 | pub fn owned(&self) -> ParamNode { | ||
2569 | ParamNode { syntax: self.syntax.owned() } | ||
2570 | } | ||
2571 | } | 1889 | } |
2572 | 1890 | ||
2573 | 1891 | ||
2574 | impl<'a> Param<'a> { | 1892 | impl Param { |
2575 | pub fn pat(self) -> Option<Pat<'a>> { | 1893 | pub fn pat(&self) -> Option<&Pat> { |
2576 | super::child_opt(self) | 1894 | super::child_opt(self) |
2577 | } | 1895 | } |
2578 | 1896 | ||
2579 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1897 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2580 | super::child_opt(self) | 1898 | super::child_opt(self) |
2581 | } | 1899 | } |
2582 | } | 1900 | } |
2583 | 1901 | ||
2584 | // ParamList | 1902 | // ParamList |
2585 | #[derive(Debug, Clone, Copy,)] | 1903 | #[derive(Debug, PartialEq, Eq, Hash)] |
2586 | pub struct ParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1904 | #[repr(transparent)] |
2587 | pub(crate) syntax: SyntaxNode<R>, | 1905 | pub struct ParamList { |
1906 | pub(crate) syntax: SyntaxNode, | ||
2588 | } | 1907 | } |
2589 | pub type ParamList<'a> = ParamListNode<RefRoot<'a>>; | 1908 | unsafe impl TransparentNewType for ParamList { |
2590 | 1909 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2591 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamListNode<R1>> for ParamListNode<R2> { | ||
2592 | fn eq(&self, other: &ParamListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2593 | } | ||
2594 | impl<R: TreeRoot<RaTypes>> Eq for ParamListNode<R> {} | ||
2595 | impl<R: TreeRoot<RaTypes>> Hash for ParamListNode<R> { | ||
2596 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2597 | } | 1910 | } |
2598 | 1911 | ||
2599 | impl<'a> AstNode<'a> for ParamList<'a> { | 1912 | impl AstNode for ParamList { |
2600 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1913 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2601 | match syntax.kind() { | 1914 | match syntax.kind() { |
2602 | PARAM_LIST => Some(ParamList { syntax }), | 1915 | PARAM_LIST => Some(ParamList::from_repr(syntax.into_repr())), |
2603 | _ => None, | 1916 | _ => None, |
2604 | } | 1917 | } |
2605 | } | 1918 | } |
2606 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1919 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2607 | } | 1920 | fn to_owned(&self) -> TreePtr<ParamList> { TreePtr::cast(self.syntax.to_owned()) } |
2608 | |||
2609 | impl<R: TreeRoot<RaTypes>> ParamListNode<R> { | ||
2610 | pub fn borrowed(&self) -> ParamList { | ||
2611 | ParamListNode { syntax: self.syntax.borrowed() } | ||
2612 | } | ||
2613 | pub fn owned(&self) -> ParamListNode { | ||
2614 | ParamListNode { syntax: self.syntax.owned() } | ||
2615 | } | ||
2616 | } | 1921 | } |
2617 | 1922 | ||
2618 | 1923 | ||
2619 | impl<'a> ParamList<'a> { | 1924 | impl ParamList { |
2620 | pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { | 1925 | pub fn params(&self) -> impl Iterator<Item = &Param> { |
2621 | super::children(self) | 1926 | super::children(self) |
2622 | } | 1927 | } |
2623 | 1928 | ||
2624 | pub fn self_param(self) -> Option<SelfParam<'a>> { | 1929 | pub fn self_param(&self) -> Option<&SelfParam> { |
2625 | super::child_opt(self) | 1930 | super::child_opt(self) |
2626 | } | 1931 | } |
2627 | } | 1932 | } |
2628 | 1933 | ||
2629 | // ParenExpr | 1934 | // ParenExpr |
2630 | #[derive(Debug, Clone, Copy,)] | 1935 | #[derive(Debug, PartialEq, Eq, Hash)] |
2631 | pub struct ParenExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1936 | #[repr(transparent)] |
2632 | pub(crate) syntax: SyntaxNode<R>, | 1937 | pub struct ParenExpr { |
2633 | } | 1938 | pub(crate) syntax: SyntaxNode, |
2634 | pub type ParenExpr<'a> = ParenExprNode<RefRoot<'a>>; | ||
2635 | |||
2636 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenExprNode<R1>> for ParenExprNode<R2> { | ||
2637 | fn eq(&self, other: &ParenExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2638 | } | 1939 | } |
2639 | impl<R: TreeRoot<RaTypes>> Eq for ParenExprNode<R> {} | 1940 | unsafe impl TransparentNewType for ParenExpr { |
2640 | impl<R: TreeRoot<RaTypes>> Hash for ParenExprNode<R> { | 1941 | type Repr = rowan::SyntaxNode<RaTypes>; |
2641 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2642 | } | 1942 | } |
2643 | 1943 | ||
2644 | impl<'a> AstNode<'a> for ParenExpr<'a> { | 1944 | impl AstNode for ParenExpr { |
2645 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1945 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2646 | match syntax.kind() { | 1946 | match syntax.kind() { |
2647 | PAREN_EXPR => Some(ParenExpr { syntax }), | 1947 | PAREN_EXPR => Some(ParenExpr::from_repr(syntax.into_repr())), |
2648 | _ => None, | 1948 | _ => None, |
2649 | } | 1949 | } |
2650 | } | 1950 | } |
2651 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1951 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1952 | fn to_owned(&self) -> TreePtr<ParenExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
2652 | } | 1953 | } |
2653 | 1954 | ||
2654 | impl<R: TreeRoot<RaTypes>> ParenExprNode<R> { | ||
2655 | pub fn borrowed(&self) -> ParenExpr { | ||
2656 | ParenExprNode { syntax: self.syntax.borrowed() } | ||
2657 | } | ||
2658 | pub fn owned(&self) -> ParenExprNode { | ||
2659 | ParenExprNode { syntax: self.syntax.owned() } | ||
2660 | } | ||
2661 | } | ||
2662 | 1955 | ||
2663 | 1956 | impl ParenExpr { | |
2664 | impl<'a> ParenExpr<'a> { | 1957 | pub fn expr(&self) -> Option<&Expr> { |
2665 | pub fn expr(self) -> Option<Expr<'a>> { | ||
2666 | super::child_opt(self) | 1958 | super::child_opt(self) |
2667 | } | 1959 | } |
2668 | } | 1960 | } |
2669 | 1961 | ||
2670 | // ParenType | 1962 | // ParenType |
2671 | #[derive(Debug, Clone, Copy,)] | 1963 | #[derive(Debug, PartialEq, Eq, Hash)] |
2672 | pub struct ParenTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1964 | #[repr(transparent)] |
2673 | pub(crate) syntax: SyntaxNode<R>, | 1965 | pub struct ParenType { |
1966 | pub(crate) syntax: SyntaxNode, | ||
2674 | } | 1967 | } |
2675 | pub type ParenType<'a> = ParenTypeNode<RefRoot<'a>>; | 1968 | unsafe impl TransparentNewType for ParenType { |
2676 | 1969 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2677 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenTypeNode<R1>> for ParenTypeNode<R2> { | ||
2678 | fn eq(&self, other: &ParenTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2679 | } | ||
2680 | impl<R: TreeRoot<RaTypes>> Eq for ParenTypeNode<R> {} | ||
2681 | impl<R: TreeRoot<RaTypes>> Hash for ParenTypeNode<R> { | ||
2682 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2683 | } | 1970 | } |
2684 | 1971 | ||
2685 | impl<'a> AstNode<'a> for ParenType<'a> { | 1972 | impl AstNode for ParenType { |
2686 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1973 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2687 | match syntax.kind() { | 1974 | match syntax.kind() { |
2688 | PAREN_TYPE => Some(ParenType { syntax }), | 1975 | PAREN_TYPE => Some(ParenType::from_repr(syntax.into_repr())), |
2689 | _ => None, | 1976 | _ => None, |
2690 | } | 1977 | } |
2691 | } | 1978 | } |
2692 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1979 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2693 | } | 1980 | fn to_owned(&self) -> TreePtr<ParenType> { TreePtr::cast(self.syntax.to_owned()) } |
2694 | |||
2695 | impl<R: TreeRoot<RaTypes>> ParenTypeNode<R> { | ||
2696 | pub fn borrowed(&self) -> ParenType { | ||
2697 | ParenTypeNode { syntax: self.syntax.borrowed() } | ||
2698 | } | ||
2699 | pub fn owned(&self) -> ParenTypeNode { | ||
2700 | ParenTypeNode { syntax: self.syntax.owned() } | ||
2701 | } | ||
2702 | } | 1981 | } |
2703 | 1982 | ||
2704 | 1983 | ||
2705 | impl<'a> ParenType<'a> { | 1984 | impl ParenType { |
2706 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1985 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2707 | super::child_opt(self) | 1986 | super::child_opt(self) |
2708 | } | 1987 | } |
2709 | } | 1988 | } |
2710 | 1989 | ||
2711 | // Pat | 1990 | // Pat |
1991 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1992 | #[repr(transparent)] | ||
1993 | pub struct Pat { | ||
1994 | pub(crate) syntax: SyntaxNode, | ||
1995 | } | ||
1996 | unsafe impl TransparentNewType for Pat { | ||
1997 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1998 | } | ||
1999 | |||
2712 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 2000 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2713 | pub enum Pat<'a> { | 2001 | pub enum PatKind<'a> { |
2714 | RefPat(RefPat<'a>), | 2002 | RefPat(&'a RefPat), |
2715 | BindPat(BindPat<'a>), | 2003 | BindPat(&'a BindPat), |
2716 | PlaceholderPat(PlaceholderPat<'a>), | 2004 | PlaceholderPat(&'a PlaceholderPat), |
2717 | PathPat(PathPat<'a>), | 2005 | PathPat(&'a PathPat), |
2718 | StructPat(StructPat<'a>), | 2006 | StructPat(&'a StructPat), |
2719 | FieldPatList(FieldPatList<'a>), | 2007 | FieldPatList(&'a FieldPatList), |
2720 | TupleStructPat(TupleStructPat<'a>), | 2008 | TupleStructPat(&'a TupleStructPat), |
2721 | TuplePat(TuplePat<'a>), | 2009 | TuplePat(&'a TuplePat), |
2722 | SlicePat(SlicePat<'a>), | 2010 | SlicePat(&'a SlicePat), |
2723 | RangePat(RangePat<'a>), | 2011 | RangePat(&'a RangePat), |
2724 | } | 2012 | } |
2725 | 2013 | ||
2726 | impl<'a> AstNode<'a> for Pat<'a> { | 2014 | impl AstNode for Pat { |
2727 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2015 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2728 | match syntax.kind() { | 2016 | match syntax.kind() { |
2729 | REF_PAT => Some(Pat::RefPat(RefPat { syntax })), | 2017 | | REF_PAT |
2730 | BIND_PAT => Some(Pat::BindPat(BindPat { syntax })), | 2018 | | BIND_PAT |
2731 | PLACEHOLDER_PAT => Some(Pat::PlaceholderPat(PlaceholderPat { syntax })), | 2019 | | PLACEHOLDER_PAT |
2732 | PATH_PAT => Some(Pat::PathPat(PathPat { syntax })), | 2020 | | PATH_PAT |
2733 | STRUCT_PAT => Some(Pat::StructPat(StructPat { syntax })), | 2021 | | STRUCT_PAT |
2734 | FIELD_PAT_LIST => Some(Pat::FieldPatList(FieldPatList { syntax })), | 2022 | | FIELD_PAT_LIST |
2735 | TUPLE_STRUCT_PAT => Some(Pat::TupleStructPat(TupleStructPat { syntax })), | 2023 | | TUPLE_STRUCT_PAT |
2736 | TUPLE_PAT => Some(Pat::TuplePat(TuplePat { syntax })), | 2024 | | TUPLE_PAT |
2737 | SLICE_PAT => Some(Pat::SlicePat(SlicePat { syntax })), | 2025 | | SLICE_PAT |
2738 | RANGE_PAT => Some(Pat::RangePat(RangePat { syntax })), | 2026 | | RANGE_PAT => Some(Pat::from_repr(syntax.into_repr())), |
2739 | _ => None, | 2027 | _ => None, |
2740 | } | 2028 | } |
2741 | } | 2029 | } |
2742 | fn syntax(self) -> SyntaxNodeRef<'a> { | 2030 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2743 | match self { | 2031 | fn to_owned(&self) -> TreePtr<Pat> { TreePtr::cast(self.syntax.to_owned()) } |
2744 | Pat::RefPat(inner) => inner.syntax(), | 2032 | } |
2745 | Pat::BindPat(inner) => inner.syntax(), | 2033 | |
2746 | Pat::PlaceholderPat(inner) => inner.syntax(), | 2034 | impl Pat { |
2747 | Pat::PathPat(inner) => inner.syntax(), | 2035 | pub fn kind(&self) -> PatKind { |
2748 | Pat::StructPat(inner) => inner.syntax(), | 2036 | match self.syntax.kind() { |
2749 | Pat::FieldPatList(inner) => inner.syntax(), | 2037 | REF_PAT => PatKind::RefPat(RefPat::cast(&self.syntax).unwrap()), |
2750 | Pat::TupleStructPat(inner) => inner.syntax(), | 2038 | BIND_PAT => PatKind::BindPat(BindPat::cast(&self.syntax).unwrap()), |
2751 | Pat::TuplePat(inner) => inner.syntax(), | 2039 | PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(&self.syntax).unwrap()), |
2752 | Pat::SlicePat(inner) => inner.syntax(), | 2040 | PATH_PAT => PatKind::PathPat(PathPat::cast(&self.syntax).unwrap()), |
2753 | Pat::RangePat(inner) => inner.syntax(), | 2041 | STRUCT_PAT => PatKind::StructPat(StructPat::cast(&self.syntax).unwrap()), |
2042 | FIELD_PAT_LIST => PatKind::FieldPatList(FieldPatList::cast(&self.syntax).unwrap()), | ||
2043 | TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(&self.syntax).unwrap()), | ||
2044 | TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(&self.syntax).unwrap()), | ||
2045 | SLICE_PAT => PatKind::SlicePat(SlicePat::cast(&self.syntax).unwrap()), | ||
2046 | RANGE_PAT => PatKind::RangePat(RangePat::cast(&self.syntax).unwrap()), | ||
2047 | _ => unreachable!(), | ||
2754 | } | 2048 | } |
2755 | } | 2049 | } |
2756 | } | 2050 | } |
2757 | 2051 | ||
2758 | impl<'a> Pat<'a> {} | 2052 | impl Pat {} |
2759 | 2053 | ||
2760 | // Path | 2054 | // Path |
2761 | #[derive(Debug, Clone, Copy,)] | 2055 | #[derive(Debug, PartialEq, Eq, Hash)] |
2762 | pub struct PathNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2056 | #[repr(transparent)] |
2763 | pub(crate) syntax: SyntaxNode<R>, | 2057 | pub struct Path { |
2764 | } | 2058 | pub(crate) syntax: SyntaxNode, |
2765 | pub type Path<'a> = PathNode<RefRoot<'a>>; | ||
2766 | |||
2767 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathNode<R1>> for PathNode<R2> { | ||
2768 | fn eq(&self, other: &PathNode<R1>) -> bool { self.syntax == other.syntax } | ||
2769 | } | 2059 | } |
2770 | impl<R: TreeRoot<RaTypes>> Eq for PathNode<R> {} | 2060 | unsafe impl TransparentNewType for Path { |
2771 | impl<R: TreeRoot<RaTypes>> Hash for PathNode<R> { | 2061 | type Repr = rowan::SyntaxNode<RaTypes>; |
2772 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2773 | } | 2062 | } |
2774 | 2063 | ||
2775 | impl<'a> AstNode<'a> for Path<'a> { | 2064 | impl AstNode for Path { |
2776 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2065 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2777 | match syntax.kind() { | 2066 | match syntax.kind() { |
2778 | PATH => Some(Path { syntax }), | 2067 | PATH => Some(Path::from_repr(syntax.into_repr())), |
2779 | _ => None, | 2068 | _ => None, |
2780 | } | 2069 | } |
2781 | } | 2070 | } |
2782 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2071 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2783 | } | 2072 | fn to_owned(&self) -> TreePtr<Path> { TreePtr::cast(self.syntax.to_owned()) } |
2784 | |||
2785 | impl<R: TreeRoot<RaTypes>> PathNode<R> { | ||
2786 | pub fn borrowed(&self) -> Path { | ||
2787 | PathNode { syntax: self.syntax.borrowed() } | ||
2788 | } | ||
2789 | pub fn owned(&self) -> PathNode { | ||
2790 | PathNode { syntax: self.syntax.owned() } | ||
2791 | } | ||
2792 | } | 2073 | } |
2793 | 2074 | ||
2794 | 2075 | ||
2795 | impl<'a> Path<'a> { | 2076 | impl Path { |
2796 | pub fn segment(self) -> Option<PathSegment<'a>> { | 2077 | pub fn segment(&self) -> Option<&PathSegment> { |
2797 | super::child_opt(self) | 2078 | super::child_opt(self) |
2798 | } | 2079 | } |
2799 | 2080 | ||
2800 | pub fn qualifier(self) -> Option<Path<'a>> { | 2081 | pub fn qualifier(&self) -> Option<&Path> { |
2801 | super::child_opt(self) | 2082 | super::child_opt(self) |
2802 | } | 2083 | } |
2803 | } | 2084 | } |
2804 | 2085 | ||
2805 | // PathExpr | 2086 | // PathExpr |
2806 | #[derive(Debug, Clone, Copy,)] | 2087 | #[derive(Debug, PartialEq, Eq, Hash)] |
2807 | pub struct PathExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2088 | #[repr(transparent)] |
2808 | pub(crate) syntax: SyntaxNode<R>, | 2089 | pub struct PathExpr { |
2090 | pub(crate) syntax: SyntaxNode, | ||
2809 | } | 2091 | } |
2810 | pub type PathExpr<'a> = PathExprNode<RefRoot<'a>>; | 2092 | unsafe impl TransparentNewType for PathExpr { |
2811 | 2093 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2812 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathExprNode<R1>> for PathExprNode<R2> { | ||
2813 | fn eq(&self, other: &PathExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2814 | } | ||
2815 | impl<R: TreeRoot<RaTypes>> Eq for PathExprNode<R> {} | ||
2816 | impl<R: TreeRoot<RaTypes>> Hash for PathExprNode<R> { | ||
2817 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2818 | } | 2094 | } |
2819 | 2095 | ||
2820 | impl<'a> AstNode<'a> for PathExpr<'a> { | 2096 | impl AstNode for PathExpr { |
2821 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2097 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2822 | match syntax.kind() { | 2098 | match syntax.kind() { |
2823 | PATH_EXPR => Some(PathExpr { syntax }), | 2099 | PATH_EXPR => Some(PathExpr::from_repr(syntax.into_repr())), |
2824 | _ => None, | 2100 | _ => None, |
2825 | } | 2101 | } |
2826 | } | 2102 | } |
2827 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2103 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2828 | } | 2104 | fn to_owned(&self) -> TreePtr<PathExpr> { TreePtr::cast(self.syntax.to_owned()) } |
2829 | |||
2830 | impl<R: TreeRoot<RaTypes>> PathExprNode<R> { | ||
2831 | pub fn borrowed(&self) -> PathExpr { | ||
2832 | PathExprNode { syntax: self.syntax.borrowed() } | ||
2833 | } | ||
2834 | pub fn owned(&self) -> PathExprNode { | ||
2835 | PathExprNode { syntax: self.syntax.owned() } | ||
2836 | } | ||
2837 | } | 2105 | } |
2838 | 2106 | ||
2839 | 2107 | ||
2840 | impl<'a> PathExpr<'a> { | 2108 | impl PathExpr { |
2841 | pub fn path(self) -> Option<Path<'a>> { | 2109 | pub fn path(&self) -> Option<&Path> { |
2842 | super::child_opt(self) | 2110 | super::child_opt(self) |
2843 | } | 2111 | } |
2844 | } | 2112 | } |
2845 | 2113 | ||
2846 | // PathPat | 2114 | // PathPat |
2847 | #[derive(Debug, Clone, Copy,)] | 2115 | #[derive(Debug, PartialEq, Eq, Hash)] |
2848 | pub struct PathPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2116 | #[repr(transparent)] |
2849 | pub(crate) syntax: SyntaxNode<R>, | 2117 | pub struct PathPat { |
2118 | pub(crate) syntax: SyntaxNode, | ||
2850 | } | 2119 | } |
2851 | pub type PathPat<'a> = PathPatNode<RefRoot<'a>>; | 2120 | unsafe impl TransparentNewType for PathPat { |
2852 | 2121 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2853 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathPatNode<R1>> for PathPatNode<R2> { | ||
2854 | fn eq(&self, other: &PathPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2855 | } | ||
2856 | impl<R: TreeRoot<RaTypes>> Eq for PathPatNode<R> {} | ||
2857 | impl<R: TreeRoot<RaTypes>> Hash for PathPatNode<R> { | ||
2858 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2859 | } | 2122 | } |
2860 | 2123 | ||
2861 | impl<'a> AstNode<'a> for PathPat<'a> { | 2124 | impl AstNode for PathPat { |
2862 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2125 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2863 | match syntax.kind() { | 2126 | match syntax.kind() { |
2864 | PATH_PAT => Some(PathPat { syntax }), | 2127 | PATH_PAT => Some(PathPat::from_repr(syntax.into_repr())), |
2865 | _ => None, | 2128 | _ => None, |
2866 | } | 2129 | } |
2867 | } | 2130 | } |
2868 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2131 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2869 | } | 2132 | fn to_owned(&self) -> TreePtr<PathPat> { TreePtr::cast(self.syntax.to_owned()) } |
2870 | |||
2871 | impl<R: TreeRoot<RaTypes>> PathPatNode<R> { | ||
2872 | pub fn borrowed(&self) -> PathPat { | ||
2873 | PathPatNode { syntax: self.syntax.borrowed() } | ||
2874 | } | ||
2875 | pub fn owned(&self) -> PathPatNode { | ||
2876 | PathPatNode { syntax: self.syntax.owned() } | ||
2877 | } | ||
2878 | } | 2133 | } |
2879 | 2134 | ||
2880 | 2135 | ||
2881 | impl<'a> PathPat<'a> {} | 2136 | impl PathPat {} |
2882 | 2137 | ||
2883 | // PathSegment | 2138 | // PathSegment |
2884 | #[derive(Debug, Clone, Copy,)] | 2139 | #[derive(Debug, PartialEq, Eq, Hash)] |
2885 | pub struct PathSegmentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2140 | #[repr(transparent)] |
2886 | pub(crate) syntax: SyntaxNode<R>, | 2141 | pub struct PathSegment { |
2887 | } | 2142 | pub(crate) syntax: SyntaxNode, |
2888 | pub type PathSegment<'a> = PathSegmentNode<RefRoot<'a>>; | ||
2889 | |||
2890 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathSegmentNode<R1>> for PathSegmentNode<R2> { | ||
2891 | fn eq(&self, other: &PathSegmentNode<R1>) -> bool { self.syntax == other.syntax } | ||
2892 | } | 2143 | } |
2893 | impl<R: TreeRoot<RaTypes>> Eq for PathSegmentNode<R> {} | 2144 | unsafe impl TransparentNewType for PathSegment { |
2894 | impl<R: TreeRoot<RaTypes>> Hash for PathSegmentNode<R> { | 2145 | type Repr = rowan::SyntaxNode<RaTypes>; |
2895 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2896 | } | 2146 | } |
2897 | 2147 | ||
2898 | impl<'a> AstNode<'a> for PathSegment<'a> { | 2148 | impl AstNode for PathSegment { |
2899 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2149 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2900 | match syntax.kind() { | 2150 | match syntax.kind() { |
2901 | PATH_SEGMENT => Some(PathSegment { syntax }), | 2151 | PATH_SEGMENT => Some(PathSegment::from_repr(syntax.into_repr())), |
2902 | _ => None, | 2152 | _ => None, |
2903 | } | 2153 | } |
2904 | } | 2154 | } |
2905 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2155 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2156 | fn to_owned(&self) -> TreePtr<PathSegment> { TreePtr::cast(self.syntax.to_owned()) } | ||
2906 | } | 2157 | } |
2907 | 2158 | ||
2908 | impl<R: TreeRoot<RaTypes>> PathSegmentNode<R> { | ||
2909 | pub fn borrowed(&self) -> PathSegment { | ||
2910 | PathSegmentNode { syntax: self.syntax.borrowed() } | ||
2911 | } | ||
2912 | pub fn owned(&self) -> PathSegmentNode { | ||
2913 | PathSegmentNode { syntax: self.syntax.owned() } | ||
2914 | } | ||
2915 | } | ||
2916 | 2159 | ||
2917 | 2160 | impl PathSegment { | |
2918 | impl<'a> PathSegment<'a> { | 2161 | pub fn name_ref(&self) -> Option<&NameRef> { |
2919 | pub fn name_ref(self) -> Option<NameRef<'a>> { | ||
2920 | super::child_opt(self) | 2162 | super::child_opt(self) |
2921 | } | 2163 | } |
2922 | } | 2164 | } |
2923 | 2165 | ||
2924 | // PathType | 2166 | // PathType |
2925 | #[derive(Debug, Clone, Copy,)] | 2167 | #[derive(Debug, PartialEq, Eq, Hash)] |
2926 | pub struct PathTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2168 | #[repr(transparent)] |
2927 | pub(crate) syntax: SyntaxNode<R>, | 2169 | pub struct PathType { |
2928 | } | 2170 | pub(crate) syntax: SyntaxNode, |
2929 | pub type PathType<'a> = PathTypeNode<RefRoot<'a>>; | ||
2930 | |||
2931 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathTypeNode<R1>> for PathTypeNode<R2> { | ||
2932 | fn eq(&self, other: &PathTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2933 | } | 2171 | } |
2934 | impl<R: TreeRoot<RaTypes>> Eq for PathTypeNode<R> {} | 2172 | unsafe impl TransparentNewType for PathType { |
2935 | impl<R: TreeRoot<RaTypes>> Hash for PathTypeNode<R> { | 2173 | type Repr = rowan::SyntaxNode<RaTypes>; |
2936 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2937 | } | 2174 | } |
2938 | 2175 | ||
2939 | impl<'a> AstNode<'a> for PathType<'a> { | 2176 | impl AstNode for PathType { |
2940 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2177 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2941 | match syntax.kind() { | 2178 | match syntax.kind() { |
2942 | PATH_TYPE => Some(PathType { syntax }), | 2179 | PATH_TYPE => Some(PathType::from_repr(syntax.into_repr())), |
2943 | _ => None, | 2180 | _ => None, |
2944 | } | 2181 | } |
2945 | } | 2182 | } |
2946 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2183 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2947 | } | 2184 | fn to_owned(&self) -> TreePtr<PathType> { TreePtr::cast(self.syntax.to_owned()) } |
2948 | |||
2949 | impl<R: TreeRoot<RaTypes>> PathTypeNode<R> { | ||
2950 | pub fn borrowed(&self) -> PathType { | ||
2951 | PathTypeNode { syntax: self.syntax.borrowed() } | ||
2952 | } | ||
2953 | pub fn owned(&self) -> PathTypeNode { | ||
2954 | PathTypeNode { syntax: self.syntax.owned() } | ||
2955 | } | ||
2956 | } | 2185 | } |
2957 | 2186 | ||
2958 | 2187 | ||
2959 | impl<'a> PathType<'a> { | 2188 | impl PathType { |
2960 | pub fn path(self) -> Option<Path<'a>> { | 2189 | pub fn path(&self) -> Option<&Path> { |
2961 | super::child_opt(self) | 2190 | super::child_opt(self) |
2962 | } | 2191 | } |
2963 | } | 2192 | } |
2964 | 2193 | ||
2965 | // PlaceholderPat | 2194 | // PlaceholderPat |
2966 | #[derive(Debug, Clone, Copy,)] | 2195 | #[derive(Debug, PartialEq, Eq, Hash)] |
2967 | pub struct PlaceholderPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2196 | #[repr(transparent)] |
2968 | pub(crate) syntax: SyntaxNode<R>, | 2197 | pub struct PlaceholderPat { |
2198 | pub(crate) syntax: SyntaxNode, | ||
2969 | } | 2199 | } |
2970 | pub type PlaceholderPat<'a> = PlaceholderPatNode<RefRoot<'a>>; | 2200 | unsafe impl TransparentNewType for PlaceholderPat { |
2971 | 2201 | type Repr = rowan::SyntaxNode<RaTypes>; | |
2972 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderPatNode<R1>> for PlaceholderPatNode<R2> { | ||
2973 | fn eq(&self, other: &PlaceholderPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2974 | } | ||
2975 | impl<R: TreeRoot<RaTypes>> Eq for PlaceholderPatNode<R> {} | ||
2976 | impl<R: TreeRoot<RaTypes>> Hash for PlaceholderPatNode<R> { | ||
2977 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2978 | } | 2202 | } |
2979 | 2203 | ||
2980 | impl<'a> AstNode<'a> for PlaceholderPat<'a> { | 2204 | impl AstNode for PlaceholderPat { |
2981 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2205 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2982 | match syntax.kind() { | 2206 | match syntax.kind() { |
2983 | PLACEHOLDER_PAT => Some(PlaceholderPat { syntax }), | 2207 | PLACEHOLDER_PAT => Some(PlaceholderPat::from_repr(syntax.into_repr())), |
2984 | _ => None, | 2208 | _ => None, |
2985 | } | 2209 | } |
2986 | } | 2210 | } |
2987 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2211 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2988 | } | 2212 | fn to_owned(&self) -> TreePtr<PlaceholderPat> { TreePtr::cast(self.syntax.to_owned()) } |
2989 | |||
2990 | impl<R: TreeRoot<RaTypes>> PlaceholderPatNode<R> { | ||
2991 | pub fn borrowed(&self) -> PlaceholderPat { | ||
2992 | PlaceholderPatNode { syntax: self.syntax.borrowed() } | ||
2993 | } | ||
2994 | pub fn owned(&self) -> PlaceholderPatNode { | ||
2995 | PlaceholderPatNode { syntax: self.syntax.owned() } | ||
2996 | } | ||
2997 | } | 2213 | } |
2998 | 2214 | ||
2999 | 2215 | ||
3000 | impl<'a> PlaceholderPat<'a> {} | 2216 | impl PlaceholderPat {} |
3001 | 2217 | ||
3002 | // PlaceholderType | 2218 | // PlaceholderType |
3003 | #[derive(Debug, Clone, Copy,)] | 2219 | #[derive(Debug, PartialEq, Eq, Hash)] |
3004 | pub struct PlaceholderTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2220 | #[repr(transparent)] |
3005 | pub(crate) syntax: SyntaxNode<R>, | 2221 | pub struct PlaceholderType { |
2222 | pub(crate) syntax: SyntaxNode, | ||
3006 | } | 2223 | } |
3007 | pub type PlaceholderType<'a> = PlaceholderTypeNode<RefRoot<'a>>; | 2224 | unsafe impl TransparentNewType for PlaceholderType { |
3008 | 2225 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3009 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderTypeNode<R1>> for PlaceholderTypeNode<R2> { | ||
3010 | fn eq(&self, other: &PlaceholderTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3011 | } | ||
3012 | impl<R: TreeRoot<RaTypes>> Eq for PlaceholderTypeNode<R> {} | ||
3013 | impl<R: TreeRoot<RaTypes>> Hash for PlaceholderTypeNode<R> { | ||
3014 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3015 | } | 2226 | } |
3016 | 2227 | ||
3017 | impl<'a> AstNode<'a> for PlaceholderType<'a> { | 2228 | impl AstNode for PlaceholderType { |
3018 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2229 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3019 | match syntax.kind() { | 2230 | match syntax.kind() { |
3020 | PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }), | 2231 | PLACEHOLDER_TYPE => Some(PlaceholderType::from_repr(syntax.into_repr())), |
3021 | _ => None, | 2232 | _ => None, |
3022 | } | 2233 | } |
3023 | } | 2234 | } |
3024 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2235 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3025 | } | 2236 | fn to_owned(&self) -> TreePtr<PlaceholderType> { TreePtr::cast(self.syntax.to_owned()) } |
3026 | |||
3027 | impl<R: TreeRoot<RaTypes>> PlaceholderTypeNode<R> { | ||
3028 | pub fn borrowed(&self) -> PlaceholderType { | ||
3029 | PlaceholderTypeNode { syntax: self.syntax.borrowed() } | ||
3030 | } | ||
3031 | pub fn owned(&self) -> PlaceholderTypeNode { | ||
3032 | PlaceholderTypeNode { syntax: self.syntax.owned() } | ||
3033 | } | ||
3034 | } | 2237 | } |
3035 | 2238 | ||
3036 | 2239 | ||
3037 | impl<'a> PlaceholderType<'a> {} | 2240 | impl PlaceholderType {} |
3038 | 2241 | ||
3039 | // PointerType | 2242 | // PointerType |
3040 | #[derive(Debug, Clone, Copy,)] | 2243 | #[derive(Debug, PartialEq, Eq, Hash)] |
3041 | pub struct PointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2244 | #[repr(transparent)] |
3042 | pub(crate) syntax: SyntaxNode<R>, | 2245 | pub struct PointerType { |
3043 | } | 2246 | pub(crate) syntax: SyntaxNode, |
3044 | pub type PointerType<'a> = PointerTypeNode<RefRoot<'a>>; | ||
3045 | |||
3046 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PointerTypeNode<R1>> for PointerTypeNode<R2> { | ||
3047 | fn eq(&self, other: &PointerTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3048 | } | 2247 | } |
3049 | impl<R: TreeRoot<RaTypes>> Eq for PointerTypeNode<R> {} | 2248 | unsafe impl TransparentNewType for PointerType { |
3050 | impl<R: TreeRoot<RaTypes>> Hash for PointerTypeNode<R> { | 2249 | type Repr = rowan::SyntaxNode<RaTypes>; |
3051 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3052 | } | 2250 | } |
3053 | 2251 | ||
3054 | impl<'a> AstNode<'a> for PointerType<'a> { | 2252 | impl AstNode for PointerType { |
3055 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2253 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3056 | match syntax.kind() { | 2254 | match syntax.kind() { |
3057 | POINTER_TYPE => Some(PointerType { syntax }), | 2255 | POINTER_TYPE => Some(PointerType::from_repr(syntax.into_repr())), |
3058 | _ => None, | 2256 | _ => None, |
3059 | } | 2257 | } |
3060 | } | 2258 | } |
3061 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2259 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2260 | fn to_owned(&self) -> TreePtr<PointerType> { TreePtr::cast(self.syntax.to_owned()) } | ||
3062 | } | 2261 | } |
3063 | 2262 | ||
3064 | impl<R: TreeRoot<RaTypes>> PointerTypeNode<R> { | ||
3065 | pub fn borrowed(&self) -> PointerType { | ||
3066 | PointerTypeNode { syntax: self.syntax.borrowed() } | ||
3067 | } | ||
3068 | pub fn owned(&self) -> PointerTypeNode { | ||
3069 | PointerTypeNode { syntax: self.syntax.owned() } | ||
3070 | } | ||
3071 | } | ||
3072 | 2263 | ||
3073 | 2264 | impl PointerType { | |
3074 | impl<'a> PointerType<'a> { | 2265 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3075 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
3076 | super::child_opt(self) | 2266 | super::child_opt(self) |
3077 | } | 2267 | } |
3078 | } | 2268 | } |
3079 | 2269 | ||
3080 | // PosField | 2270 | // PosField |
3081 | #[derive(Debug, Clone, Copy,)] | 2271 | #[derive(Debug, PartialEq, Eq, Hash)] |
3082 | pub struct PosFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2272 | #[repr(transparent)] |
3083 | pub(crate) syntax: SyntaxNode<R>, | 2273 | pub struct PosField { |
3084 | } | 2274 | pub(crate) syntax: SyntaxNode, |
3085 | pub type PosField<'a> = PosFieldNode<RefRoot<'a>>; | ||
3086 | |||
3087 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PosFieldNode<R1>> for PosFieldNode<R2> { | ||
3088 | fn eq(&self, other: &PosFieldNode<R1>) -> bool { self.syntax == other.syntax } | ||
3089 | } | 2275 | } |
3090 | impl<R: TreeRoot<RaTypes>> Eq for PosFieldNode<R> {} | 2276 | unsafe impl TransparentNewType for PosField { |
3091 | impl<R: TreeRoot<RaTypes>> Hash for PosFieldNode<R> { | 2277 | type Repr = rowan::SyntaxNode<RaTypes>; |
3092 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3093 | } | 2278 | } |
3094 | 2279 | ||
3095 | impl<'a> AstNode<'a> for PosField<'a> { | 2280 | impl AstNode for PosField { |
3096 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2281 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3097 | match syntax.kind() { | 2282 | match syntax.kind() { |
3098 | POS_FIELD => Some(PosField { syntax }), | 2283 | POS_FIELD => Some(PosField::from_repr(syntax.into_repr())), |
3099 | _ => None, | 2284 | _ => None, |
3100 | } | 2285 | } |
3101 | } | 2286 | } |
3102 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2287 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3103 | } | 2288 | fn to_owned(&self) -> TreePtr<PosField> { TreePtr::cast(self.syntax.to_owned()) } |
3104 | |||
3105 | impl<R: TreeRoot<RaTypes>> PosFieldNode<R> { | ||
3106 | pub fn borrowed(&self) -> PosField { | ||
3107 | PosFieldNode { syntax: self.syntax.borrowed() } | ||
3108 | } | ||
3109 | pub fn owned(&self) -> PosFieldNode { | ||
3110 | PosFieldNode { syntax: self.syntax.owned() } | ||
3111 | } | ||
3112 | } | 2289 | } |
3113 | 2290 | ||
3114 | 2291 | ||
3115 | impl<'a> ast::VisibilityOwner<'a> for PosField<'a> {} | 2292 | impl ast::VisibilityOwner for PosField {} |
3116 | impl<'a> ast::AttrsOwner<'a> for PosField<'a> {} | 2293 | impl ast::AttrsOwner for PosField {} |
3117 | impl<'a> PosField<'a> { | 2294 | impl PosField { |
3118 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2295 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3119 | super::child_opt(self) | 2296 | super::child_opt(self) |
3120 | } | 2297 | } |
3121 | } | 2298 | } |
3122 | 2299 | ||
3123 | // PosFieldList | 2300 | // PosFieldList |
3124 | #[derive(Debug, Clone, Copy,)] | 2301 | #[derive(Debug, PartialEq, Eq, Hash)] |
3125 | pub struct PosFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2302 | #[repr(transparent)] |
3126 | pub(crate) syntax: SyntaxNode<R>, | 2303 | pub struct PosFieldList { |
3127 | } | 2304 | pub(crate) syntax: SyntaxNode, |
3128 | pub type PosFieldList<'a> = PosFieldListNode<RefRoot<'a>>; | ||
3129 | |||
3130 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PosFieldListNode<R1>> for PosFieldListNode<R2> { | ||
3131 | fn eq(&self, other: &PosFieldListNode<R1>) -> bool { self.syntax == other.syntax } | ||
3132 | } | 2305 | } |
3133 | impl<R: TreeRoot<RaTypes>> Eq for PosFieldListNode<R> {} | 2306 | unsafe impl TransparentNewType for PosFieldList { |
3134 | impl<R: TreeRoot<RaTypes>> Hash for PosFieldListNode<R> { | 2307 | type Repr = rowan::SyntaxNode<RaTypes>; |
3135 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3136 | } | 2308 | } |
3137 | 2309 | ||
3138 | impl<'a> AstNode<'a> for PosFieldList<'a> { | 2310 | impl AstNode for PosFieldList { |
3139 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2311 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3140 | match syntax.kind() { | 2312 | match syntax.kind() { |
3141 | POS_FIELD_LIST => Some(PosFieldList { syntax }), | 2313 | POS_FIELD_LIST => Some(PosFieldList::from_repr(syntax.into_repr())), |
3142 | _ => None, | 2314 | _ => None, |
3143 | } | 2315 | } |
3144 | } | 2316 | } |
3145 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2317 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3146 | } | 2318 | fn to_owned(&self) -> TreePtr<PosFieldList> { TreePtr::cast(self.syntax.to_owned()) } |
3147 | |||
3148 | impl<R: TreeRoot<RaTypes>> PosFieldListNode<R> { | ||
3149 | pub fn borrowed(&self) -> PosFieldList { | ||
3150 | PosFieldListNode { syntax: self.syntax.borrowed() } | ||
3151 | } | ||
3152 | pub fn owned(&self) -> PosFieldListNode { | ||
3153 | PosFieldListNode { syntax: self.syntax.owned() } | ||
3154 | } | ||
3155 | } | 2319 | } |
3156 | 2320 | ||
3157 | 2321 | ||
3158 | impl<'a> PosFieldList<'a> { | 2322 | impl PosFieldList { |
3159 | pub fn fields(self) -> impl Iterator<Item = PosField<'a>> + 'a { | 2323 | pub fn fields(&self) -> impl Iterator<Item = &PosField> { |
3160 | super::children(self) | 2324 | super::children(self) |
3161 | } | 2325 | } |
3162 | } | 2326 | } |
3163 | 2327 | ||
3164 | // PrefixExpr | 2328 | // PrefixExpr |
3165 | #[derive(Debug, Clone, Copy,)] | 2329 | #[derive(Debug, PartialEq, Eq, Hash)] |
3166 | pub struct PrefixExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2330 | #[repr(transparent)] |
3167 | pub(crate) syntax: SyntaxNode<R>, | 2331 | pub struct PrefixExpr { |
2332 | pub(crate) syntax: SyntaxNode, | ||
3168 | } | 2333 | } |
3169 | pub type PrefixExpr<'a> = PrefixExprNode<RefRoot<'a>>; | 2334 | unsafe impl TransparentNewType for PrefixExpr { |
3170 | 2335 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3171 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PrefixExprNode<R1>> for PrefixExprNode<R2> { | ||
3172 | fn eq(&self, other: &PrefixExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3173 | } | ||
3174 | impl<R: TreeRoot<RaTypes>> Eq for PrefixExprNode<R> {} | ||
3175 | impl<R: TreeRoot<RaTypes>> Hash for PrefixExprNode<R> { | ||
3176 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3177 | } | 2336 | } |
3178 | 2337 | ||
3179 | impl<'a> AstNode<'a> for PrefixExpr<'a> { | 2338 | impl AstNode for PrefixExpr { |
3180 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2339 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3181 | match syntax.kind() { | 2340 | match syntax.kind() { |
3182 | PREFIX_EXPR => Some(PrefixExpr { syntax }), | 2341 | PREFIX_EXPR => Some(PrefixExpr::from_repr(syntax.into_repr())), |
3183 | _ => None, | 2342 | _ => None, |
3184 | } | 2343 | } |
3185 | } | 2344 | } |
3186 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2345 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3187 | } | 2346 | fn to_owned(&self) -> TreePtr<PrefixExpr> { TreePtr::cast(self.syntax.to_owned()) } |
3188 | |||
3189 | impl<R: TreeRoot<RaTypes>> PrefixExprNode<R> { | ||
3190 | pub fn borrowed(&self) -> PrefixExpr { | ||
3191 | PrefixExprNode { syntax: self.syntax.borrowed() } | ||
3192 | } | ||
3193 | pub fn owned(&self) -> PrefixExprNode { | ||
3194 | PrefixExprNode { syntax: self.syntax.owned() } | ||
3195 | } | ||
3196 | } | 2347 | } |
3197 | 2348 | ||
3198 | 2349 | ||
3199 | impl<'a> PrefixExpr<'a> { | 2350 | impl PrefixExpr { |
3200 | pub fn expr(self) -> Option<Expr<'a>> { | 2351 | pub fn expr(&self) -> Option<&Expr> { |
3201 | super::child_opt(self) | 2352 | super::child_opt(self) |
3202 | } | 2353 | } |
3203 | } | 2354 | } |
3204 | 2355 | ||
3205 | // RangeExpr | 2356 | // RangeExpr |
3206 | #[derive(Debug, Clone, Copy,)] | 2357 | #[derive(Debug, PartialEq, Eq, Hash)] |
3207 | pub struct RangeExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2358 | #[repr(transparent)] |
3208 | pub(crate) syntax: SyntaxNode<R>, | 2359 | pub struct RangeExpr { |
3209 | } | 2360 | pub(crate) syntax: SyntaxNode, |
3210 | pub type RangeExpr<'a> = RangeExprNode<RefRoot<'a>>; | ||
3211 | |||
3212 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RangeExprNode<R1>> for RangeExprNode<R2> { | ||
3213 | fn eq(&self, other: &RangeExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3214 | } | 2361 | } |
3215 | impl<R: TreeRoot<RaTypes>> Eq for RangeExprNode<R> {} | 2362 | unsafe impl TransparentNewType for RangeExpr { |
3216 | impl<R: TreeRoot<RaTypes>> Hash for RangeExprNode<R> { | 2363 | type Repr = rowan::SyntaxNode<RaTypes>; |
3217 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3218 | } | 2364 | } |
3219 | 2365 | ||
3220 | impl<'a> AstNode<'a> for RangeExpr<'a> { | 2366 | impl AstNode for RangeExpr { |
3221 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2367 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3222 | match syntax.kind() { | 2368 | match syntax.kind() { |
3223 | RANGE_EXPR => Some(RangeExpr { syntax }), | 2369 | RANGE_EXPR => Some(RangeExpr::from_repr(syntax.into_repr())), |
3224 | _ => None, | 2370 | _ => None, |
3225 | } | 2371 | } |
3226 | } | 2372 | } |
3227 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2373 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2374 | fn to_owned(&self) -> TreePtr<RangeExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
3228 | } | 2375 | } |
3229 | 2376 | ||
3230 | impl<R: TreeRoot<RaTypes>> RangeExprNode<R> { | ||
3231 | pub fn borrowed(&self) -> RangeExpr { | ||
3232 | RangeExprNode { syntax: self.syntax.borrowed() } | ||
3233 | } | ||
3234 | pub fn owned(&self) -> RangeExprNode { | ||
3235 | RangeExprNode { syntax: self.syntax.owned() } | ||
3236 | } | ||
3237 | } | ||
3238 | 2377 | ||
3239 | 2378 | impl RangeExpr {} | |
3240 | impl<'a> RangeExpr<'a> {} | ||
3241 | 2379 | ||
3242 | // RangePat | 2380 | // RangePat |
3243 | #[derive(Debug, Clone, Copy,)] | 2381 | #[derive(Debug, PartialEq, Eq, Hash)] |
3244 | pub struct RangePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2382 | #[repr(transparent)] |
3245 | pub(crate) syntax: SyntaxNode<R>, | 2383 | pub struct RangePat { |
2384 | pub(crate) syntax: SyntaxNode, | ||
3246 | } | 2385 | } |
3247 | pub type RangePat<'a> = RangePatNode<RefRoot<'a>>; | 2386 | unsafe impl TransparentNewType for RangePat { |
3248 | 2387 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3249 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RangePatNode<R1>> for RangePatNode<R2> { | ||
3250 | fn eq(&self, other: &RangePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3251 | } | ||
3252 | impl<R: TreeRoot<RaTypes>> Eq for RangePatNode<R> {} | ||
3253 | impl<R: TreeRoot<RaTypes>> Hash for RangePatNode<R> { | ||
3254 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3255 | } | 2388 | } |
3256 | 2389 | ||
3257 | impl<'a> AstNode<'a> for RangePat<'a> { | 2390 | impl AstNode for RangePat { |
3258 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2391 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3259 | match syntax.kind() { | 2392 | match syntax.kind() { |
3260 | RANGE_PAT => Some(RangePat { syntax }), | 2393 | RANGE_PAT => Some(RangePat::from_repr(syntax.into_repr())), |
3261 | _ => None, | 2394 | _ => None, |
3262 | } | 2395 | } |
3263 | } | 2396 | } |
3264 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2397 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3265 | } | 2398 | fn to_owned(&self) -> TreePtr<RangePat> { TreePtr::cast(self.syntax.to_owned()) } |
3266 | |||
3267 | impl<R: TreeRoot<RaTypes>> RangePatNode<R> { | ||
3268 | pub fn borrowed(&self) -> RangePat { | ||
3269 | RangePatNode { syntax: self.syntax.borrowed() } | ||
3270 | } | ||
3271 | pub fn owned(&self) -> RangePatNode { | ||
3272 | RangePatNode { syntax: self.syntax.owned() } | ||
3273 | } | ||
3274 | } | 2399 | } |
3275 | 2400 | ||
3276 | 2401 | ||
3277 | impl<'a> RangePat<'a> {} | 2402 | impl RangePat {} |
3278 | 2403 | ||
3279 | // RefExpr | 2404 | // RefExpr |
3280 | #[derive(Debug, Clone, Copy,)] | 2405 | #[derive(Debug, PartialEq, Eq, Hash)] |
3281 | pub struct RefExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2406 | #[repr(transparent)] |
3282 | pub(crate) syntax: SyntaxNode<R>, | 2407 | pub struct RefExpr { |
2408 | pub(crate) syntax: SyntaxNode, | ||
3283 | } | 2409 | } |
3284 | pub type RefExpr<'a> = RefExprNode<RefRoot<'a>>; | 2410 | unsafe impl TransparentNewType for RefExpr { |
3285 | 2411 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3286 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RefExprNode<R1>> for RefExprNode<R2> { | ||
3287 | fn eq(&self, other: &RefExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3288 | } | ||
3289 | impl<R: TreeRoot<RaTypes>> Eq for RefExprNode<R> {} | ||
3290 | impl<R: TreeRoot<RaTypes>> Hash for RefExprNode<R> { | ||
3291 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3292 | } | 2412 | } |
3293 | 2413 | ||
3294 | impl<'a> AstNode<'a> for RefExpr<'a> { | 2414 | impl AstNode for RefExpr { |
3295 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2415 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3296 | match syntax.kind() { | 2416 | match syntax.kind() { |
3297 | REF_EXPR => Some(RefExpr { syntax }), | 2417 | REF_EXPR => Some(RefExpr::from_repr(syntax.into_repr())), |
3298 | _ => None, | 2418 | _ => None, |
3299 | } | 2419 | } |
3300 | } | 2420 | } |
3301 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2421 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3302 | } | 2422 | fn to_owned(&self) -> TreePtr<RefExpr> { TreePtr::cast(self.syntax.to_owned()) } |
3303 | |||
3304 | impl<R: TreeRoot<RaTypes>> RefExprNode<R> { | ||
3305 | pub fn borrowed(&self) -> RefExpr { | ||
3306 | RefExprNode { syntax: self.syntax.borrowed() } | ||
3307 | } | ||
3308 | pub fn owned(&self) -> RefExprNode { | ||
3309 | RefExprNode { syntax: self.syntax.owned() } | ||
3310 | } | ||
3311 | } | 2423 | } |
3312 | 2424 | ||
3313 | 2425 | ||
3314 | impl<'a> RefExpr<'a> { | 2426 | impl RefExpr { |
3315 | pub fn expr(self) -> Option<Expr<'a>> { | 2427 | pub fn expr(&self) -> Option<&Expr> { |
3316 | super::child_opt(self) | 2428 | super::child_opt(self) |
3317 | } | 2429 | } |
3318 | } | 2430 | } |
3319 | 2431 | ||
3320 | // RefPat | 2432 | // RefPat |
3321 | #[derive(Debug, Clone, Copy,)] | 2433 | #[derive(Debug, PartialEq, Eq, Hash)] |
3322 | pub struct RefPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2434 | #[repr(transparent)] |
3323 | pub(crate) syntax: SyntaxNode<R>, | 2435 | pub struct RefPat { |
2436 | pub(crate) syntax: SyntaxNode, | ||
3324 | } | 2437 | } |
3325 | pub type RefPat<'a> = RefPatNode<RefRoot<'a>>; | 2438 | unsafe impl TransparentNewType for RefPat { |
3326 | 2439 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3327 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RefPatNode<R1>> for RefPatNode<R2> { | ||
3328 | fn eq(&self, other: &RefPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3329 | } | ||
3330 | impl<R: TreeRoot<RaTypes>> Eq for RefPatNode<R> {} | ||
3331 | impl<R: TreeRoot<RaTypes>> Hash for RefPatNode<R> { | ||
3332 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3333 | } | 2440 | } |
3334 | 2441 | ||
3335 | impl<'a> AstNode<'a> for RefPat<'a> { | 2442 | impl AstNode for RefPat { |
3336 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2443 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3337 | match syntax.kind() { | 2444 | match syntax.kind() { |
3338 | REF_PAT => Some(RefPat { syntax }), | 2445 | REF_PAT => Some(RefPat::from_repr(syntax.into_repr())), |
3339 | _ => None, | 2446 | _ => None, |
3340 | } | 2447 | } |
3341 | } | 2448 | } |
3342 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2449 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3343 | } | 2450 | fn to_owned(&self) -> TreePtr<RefPat> { TreePtr::cast(self.syntax.to_owned()) } |
3344 | |||
3345 | impl<R: TreeRoot<RaTypes>> RefPatNode<R> { | ||
3346 | pub fn borrowed(&self) -> RefPat { | ||
3347 | RefPatNode { syntax: self.syntax.borrowed() } | ||
3348 | } | ||
3349 | pub fn owned(&self) -> RefPatNode { | ||
3350 | RefPatNode { syntax: self.syntax.owned() } | ||
3351 | } | ||
3352 | } | 2451 | } |
3353 | 2452 | ||
3354 | 2453 | ||
3355 | impl<'a> RefPat<'a> {} | 2454 | impl RefPat {} |
3356 | 2455 | ||
3357 | // ReferenceType | 2456 | // ReferenceType |
3358 | #[derive(Debug, Clone, Copy,)] | 2457 | #[derive(Debug, PartialEq, Eq, Hash)] |
3359 | pub struct ReferenceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2458 | #[repr(transparent)] |
3360 | pub(crate) syntax: SyntaxNode<R>, | 2459 | pub struct ReferenceType { |
3361 | } | 2460 | pub(crate) syntax: SyntaxNode, |
3362 | pub type ReferenceType<'a> = ReferenceTypeNode<RefRoot<'a>>; | ||
3363 | |||
3364 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ReferenceTypeNode<R1>> for ReferenceTypeNode<R2> { | ||
3365 | fn eq(&self, other: &ReferenceTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3366 | } | 2461 | } |
3367 | impl<R: TreeRoot<RaTypes>> Eq for ReferenceTypeNode<R> {} | 2462 | unsafe impl TransparentNewType for ReferenceType { |
3368 | impl<R: TreeRoot<RaTypes>> Hash for ReferenceTypeNode<R> { | 2463 | type Repr = rowan::SyntaxNode<RaTypes>; |
3369 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3370 | } | 2464 | } |
3371 | 2465 | ||
3372 | impl<'a> AstNode<'a> for ReferenceType<'a> { | 2466 | impl AstNode for ReferenceType { |
3373 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2467 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3374 | match syntax.kind() { | 2468 | match syntax.kind() { |
3375 | REFERENCE_TYPE => Some(ReferenceType { syntax }), | 2469 | REFERENCE_TYPE => Some(ReferenceType::from_repr(syntax.into_repr())), |
3376 | _ => None, | 2470 | _ => None, |
3377 | } | 2471 | } |
3378 | } | 2472 | } |
3379 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2473 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3380 | } | 2474 | fn to_owned(&self) -> TreePtr<ReferenceType> { TreePtr::cast(self.syntax.to_owned()) } |
3381 | |||
3382 | impl<R: TreeRoot<RaTypes>> ReferenceTypeNode<R> { | ||
3383 | pub fn borrowed(&self) -> ReferenceType { | ||
3384 | ReferenceTypeNode { syntax: self.syntax.borrowed() } | ||
3385 | } | ||
3386 | pub fn owned(&self) -> ReferenceTypeNode { | ||
3387 | ReferenceTypeNode { syntax: self.syntax.owned() } | ||
3388 | } | ||
3389 | } | 2475 | } |
3390 | 2476 | ||
3391 | 2477 | ||
3392 | impl<'a> ReferenceType<'a> { | 2478 | impl ReferenceType { |
3393 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2479 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3394 | super::child_opt(self) | 2480 | super::child_opt(self) |
3395 | } | 2481 | } |
3396 | } | 2482 | } |
3397 | 2483 | ||
3398 | // RetType | 2484 | // RetType |
3399 | #[derive(Debug, Clone, Copy,)] | 2485 | #[derive(Debug, PartialEq, Eq, Hash)] |
3400 | pub struct RetTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2486 | #[repr(transparent)] |
3401 | pub(crate) syntax: SyntaxNode<R>, | 2487 | pub struct RetType { |
3402 | } | 2488 | pub(crate) syntax: SyntaxNode, |
3403 | pub type RetType<'a> = RetTypeNode<RefRoot<'a>>; | ||
3404 | |||
3405 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RetTypeNode<R1>> for RetTypeNode<R2> { | ||
3406 | fn eq(&self, other: &RetTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3407 | } | 2489 | } |
3408 | impl<R: TreeRoot<RaTypes>> Eq for RetTypeNode<R> {} | 2490 | unsafe impl TransparentNewType for RetType { |
3409 | impl<R: TreeRoot<RaTypes>> Hash for RetTypeNode<R> { | 2491 | type Repr = rowan::SyntaxNode<RaTypes>; |
3410 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3411 | } | 2492 | } |
3412 | 2493 | ||
3413 | impl<'a> AstNode<'a> for RetType<'a> { | 2494 | impl AstNode for RetType { |
3414 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2495 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3415 | match syntax.kind() { | 2496 | match syntax.kind() { |
3416 | RET_TYPE => Some(RetType { syntax }), | 2497 | RET_TYPE => Some(RetType::from_repr(syntax.into_repr())), |
3417 | _ => None, | 2498 | _ => None, |
3418 | } | 2499 | } |
3419 | } | 2500 | } |
3420 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2501 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3421 | } | 2502 | fn to_owned(&self) -> TreePtr<RetType> { TreePtr::cast(self.syntax.to_owned()) } |
3422 | |||
3423 | impl<R: TreeRoot<RaTypes>> RetTypeNode<R> { | ||
3424 | pub fn borrowed(&self) -> RetType { | ||
3425 | RetTypeNode { syntax: self.syntax.borrowed() } | ||
3426 | } | ||
3427 | pub fn owned(&self) -> RetTypeNode { | ||
3428 | RetTypeNode { syntax: self.syntax.owned() } | ||
3429 | } | ||
3430 | } | 2503 | } |
3431 | 2504 | ||
3432 | 2505 | ||
3433 | impl<'a> RetType<'a> { | 2506 | impl RetType { |
3434 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2507 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3435 | super::child_opt(self) | 2508 | super::child_opt(self) |
3436 | } | 2509 | } |
3437 | } | 2510 | } |
3438 | 2511 | ||
3439 | // ReturnExpr | 2512 | // ReturnExpr |
3440 | #[derive(Debug, Clone, Copy,)] | 2513 | #[derive(Debug, PartialEq, Eq, Hash)] |
3441 | pub struct ReturnExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2514 | #[repr(transparent)] |
3442 | pub(crate) syntax: SyntaxNode<R>, | 2515 | pub struct ReturnExpr { |
2516 | pub(crate) syntax: SyntaxNode, | ||
3443 | } | 2517 | } |
3444 | pub type ReturnExpr<'a> = ReturnExprNode<RefRoot<'a>>; | 2518 | unsafe impl TransparentNewType for ReturnExpr { |
3445 | 2519 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3446 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ReturnExprNode<R1>> for ReturnExprNode<R2> { | ||
3447 | fn eq(&self, other: &ReturnExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3448 | } | ||
3449 | impl<R: TreeRoot<RaTypes>> Eq for ReturnExprNode<R> {} | ||
3450 | impl<R: TreeRoot<RaTypes>> Hash for ReturnExprNode<R> { | ||
3451 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3452 | } | 2520 | } |
3453 | 2521 | ||
3454 | impl<'a> AstNode<'a> for ReturnExpr<'a> { | 2522 | impl AstNode for ReturnExpr { |
3455 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2523 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3456 | match syntax.kind() { | 2524 | match syntax.kind() { |
3457 | RETURN_EXPR => Some(ReturnExpr { syntax }), | 2525 | RETURN_EXPR => Some(ReturnExpr::from_repr(syntax.into_repr())), |
3458 | _ => None, | 2526 | _ => None, |
3459 | } | 2527 | } |
3460 | } | 2528 | } |
3461 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2529 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3462 | } | 2530 | fn to_owned(&self) -> TreePtr<ReturnExpr> { TreePtr::cast(self.syntax.to_owned()) } |
3463 | |||
3464 | impl<R: TreeRoot<RaTypes>> ReturnExprNode<R> { | ||
3465 | pub fn borrowed(&self) -> ReturnExpr { | ||
3466 | ReturnExprNode { syntax: self.syntax.borrowed() } | ||
3467 | } | ||
3468 | pub fn owned(&self) -> ReturnExprNode { | ||
3469 | ReturnExprNode { syntax: self.syntax.owned() } | ||
3470 | } | ||
3471 | } | 2531 | } |
3472 | 2532 | ||
3473 | 2533 | ||
3474 | impl<'a> ReturnExpr<'a> { | 2534 | impl ReturnExpr { |
3475 | pub fn expr(self) -> Option<Expr<'a>> { | 2535 | pub fn expr(&self) -> Option<&Expr> { |
3476 | super::child_opt(self) | 2536 | super::child_opt(self) |
3477 | } | 2537 | } |
3478 | } | 2538 | } |
3479 | 2539 | ||
3480 | // SelfKw | 2540 | // SelfKw |
3481 | #[derive(Debug, Clone, Copy,)] | 2541 | #[derive(Debug, PartialEq, Eq, Hash)] |
3482 | pub struct SelfKwNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2542 | #[repr(transparent)] |
3483 | pub(crate) syntax: SyntaxNode<R>, | 2543 | pub struct SelfKw { |
3484 | } | 2544 | pub(crate) syntax: SyntaxNode, |
3485 | pub type SelfKw<'a> = SelfKwNode<RefRoot<'a>>; | ||
3486 | |||
3487 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SelfKwNode<R1>> for SelfKwNode<R2> { | ||
3488 | fn eq(&self, other: &SelfKwNode<R1>) -> bool { self.syntax == other.syntax } | ||
3489 | } | 2545 | } |
3490 | impl<R: TreeRoot<RaTypes>> Eq for SelfKwNode<R> {} | 2546 | unsafe impl TransparentNewType for SelfKw { |
3491 | impl<R: TreeRoot<RaTypes>> Hash for SelfKwNode<R> { | 2547 | type Repr = rowan::SyntaxNode<RaTypes>; |
3492 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3493 | } | 2548 | } |
3494 | 2549 | ||
3495 | impl<'a> AstNode<'a> for SelfKw<'a> { | 2550 | impl AstNode for SelfKw { |
3496 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2551 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3497 | match syntax.kind() { | 2552 | match syntax.kind() { |
3498 | SELF_KW => Some(SelfKw { syntax }), | 2553 | SELF_KW => Some(SelfKw::from_repr(syntax.into_repr())), |
3499 | _ => None, | 2554 | _ => None, |
3500 | } | 2555 | } |
3501 | } | 2556 | } |
3502 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2557 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2558 | fn to_owned(&self) -> TreePtr<SelfKw> { TreePtr::cast(self.syntax.to_owned()) } | ||
3503 | } | 2559 | } |
3504 | 2560 | ||
3505 | impl<R: TreeRoot<RaTypes>> SelfKwNode<R> { | ||
3506 | pub fn borrowed(&self) -> SelfKw { | ||
3507 | SelfKwNode { syntax: self.syntax.borrowed() } | ||
3508 | } | ||
3509 | pub fn owned(&self) -> SelfKwNode { | ||
3510 | SelfKwNode { syntax: self.syntax.owned() } | ||
3511 | } | ||
3512 | } | ||
3513 | 2561 | ||
3514 | 2562 | impl SelfKw {} | |
3515 | impl<'a> SelfKw<'a> {} | ||
3516 | 2563 | ||
3517 | // SelfParam | 2564 | // SelfParam |
3518 | #[derive(Debug, Clone, Copy,)] | 2565 | #[derive(Debug, PartialEq, Eq, Hash)] |
3519 | pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2566 | #[repr(transparent)] |
3520 | pub(crate) syntax: SyntaxNode<R>, | 2567 | pub struct SelfParam { |
2568 | pub(crate) syntax: SyntaxNode, | ||
3521 | } | 2569 | } |
3522 | pub type SelfParam<'a> = SelfParamNode<RefRoot<'a>>; | 2570 | unsafe impl TransparentNewType for SelfParam { |
3523 | 2571 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3524 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SelfParamNode<R1>> for SelfParamNode<R2> { | ||
3525 | fn eq(&self, other: &SelfParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
3526 | } | ||
3527 | impl<R: TreeRoot<RaTypes>> Eq for SelfParamNode<R> {} | ||
3528 | impl<R: TreeRoot<RaTypes>> Hash for SelfParamNode<R> { | ||
3529 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3530 | } | 2572 | } |
3531 | 2573 | ||
3532 | impl<'a> AstNode<'a> for SelfParam<'a> { | 2574 | impl AstNode for SelfParam { |
3533 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2575 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3534 | match syntax.kind() { | 2576 | match syntax.kind() { |
3535 | SELF_PARAM => Some(SelfParam { syntax }), | 2577 | SELF_PARAM => Some(SelfParam::from_repr(syntax.into_repr())), |
3536 | _ => None, | 2578 | _ => None, |
3537 | } | 2579 | } |
3538 | } | 2580 | } |
3539 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2581 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3540 | } | 2582 | fn to_owned(&self) -> TreePtr<SelfParam> { TreePtr::cast(self.syntax.to_owned()) } |
3541 | |||
3542 | impl<R: TreeRoot<RaTypes>> SelfParamNode<R> { | ||
3543 | pub fn borrowed(&self) -> SelfParam { | ||
3544 | SelfParamNode { syntax: self.syntax.borrowed() } | ||
3545 | } | ||
3546 | pub fn owned(&self) -> SelfParamNode { | ||
3547 | SelfParamNode { syntax: self.syntax.owned() } | ||
3548 | } | ||
3549 | } | 2583 | } |
3550 | 2584 | ||
3551 | 2585 | ||
3552 | impl<'a> SelfParam<'a> { | 2586 | impl SelfParam { |
3553 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2587 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3554 | super::child_opt(self) | 2588 | super::child_opt(self) |
3555 | } | 2589 | } |
3556 | 2590 | ||
3557 | pub fn self_kw(self) -> Option<SelfKw<'a>> { | 2591 | pub fn self_kw(&self) -> Option<&SelfKw> { |
3558 | super::child_opt(self) | 2592 | super::child_opt(self) |
3559 | } | 2593 | } |
3560 | } | 2594 | } |
3561 | 2595 | ||
3562 | // SlicePat | 2596 | // SlicePat |
3563 | #[derive(Debug, Clone, Copy,)] | 2597 | #[derive(Debug, PartialEq, Eq, Hash)] |
3564 | pub struct SlicePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2598 | #[repr(transparent)] |
3565 | pub(crate) syntax: SyntaxNode<R>, | 2599 | pub struct SlicePat { |
2600 | pub(crate) syntax: SyntaxNode, | ||
3566 | } | 2601 | } |
3567 | pub type SlicePat<'a> = SlicePatNode<RefRoot<'a>>; | 2602 | unsafe impl TransparentNewType for SlicePat { |
3568 | 2603 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3569 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SlicePatNode<R1>> for SlicePatNode<R2> { | ||
3570 | fn eq(&self, other: &SlicePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3571 | } | ||
3572 | impl<R: TreeRoot<RaTypes>> Eq for SlicePatNode<R> {} | ||
3573 | impl<R: TreeRoot<RaTypes>> Hash for SlicePatNode<R> { | ||
3574 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3575 | } | 2604 | } |
3576 | 2605 | ||
3577 | impl<'a> AstNode<'a> for SlicePat<'a> { | 2606 | impl AstNode for SlicePat { |
3578 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2607 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3579 | match syntax.kind() { | 2608 | match syntax.kind() { |
3580 | SLICE_PAT => Some(SlicePat { syntax }), | 2609 | SLICE_PAT => Some(SlicePat::from_repr(syntax.into_repr())), |
3581 | _ => None, | 2610 | _ => None, |
3582 | } | 2611 | } |
3583 | } | 2612 | } |
3584 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2613 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3585 | } | 2614 | fn to_owned(&self) -> TreePtr<SlicePat> { TreePtr::cast(self.syntax.to_owned()) } |
3586 | |||
3587 | impl<R: TreeRoot<RaTypes>> SlicePatNode<R> { | ||
3588 | pub fn borrowed(&self) -> SlicePat { | ||
3589 | SlicePatNode { syntax: self.syntax.borrowed() } | ||
3590 | } | ||
3591 | pub fn owned(&self) -> SlicePatNode { | ||
3592 | SlicePatNode { syntax: self.syntax.owned() } | ||
3593 | } | ||
3594 | } | 2615 | } |
3595 | 2616 | ||
3596 | 2617 | ||
3597 | impl<'a> SlicePat<'a> {} | 2618 | impl SlicePat {} |
3598 | 2619 | ||
3599 | // SliceType | 2620 | // SliceType |
3600 | #[derive(Debug, Clone, Copy,)] | 2621 | #[derive(Debug, PartialEq, Eq, Hash)] |
3601 | pub struct SliceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2622 | #[repr(transparent)] |
3602 | pub(crate) syntax: SyntaxNode<R>, | 2623 | pub struct SliceType { |
2624 | pub(crate) syntax: SyntaxNode, | ||
3603 | } | 2625 | } |
3604 | pub type SliceType<'a> = SliceTypeNode<RefRoot<'a>>; | 2626 | unsafe impl TransparentNewType for SliceType { |
3605 | 2627 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3606 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SliceTypeNode<R1>> for SliceTypeNode<R2> { | ||
3607 | fn eq(&self, other: &SliceTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3608 | } | ||
3609 | impl<R: TreeRoot<RaTypes>> Eq for SliceTypeNode<R> {} | ||
3610 | impl<R: TreeRoot<RaTypes>> Hash for SliceTypeNode<R> { | ||
3611 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3612 | } | 2628 | } |
3613 | 2629 | ||
3614 | impl<'a> AstNode<'a> for SliceType<'a> { | 2630 | impl AstNode for SliceType { |
3615 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2631 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3616 | match syntax.kind() { | 2632 | match syntax.kind() { |
3617 | SLICE_TYPE => Some(SliceType { syntax }), | 2633 | SLICE_TYPE => Some(SliceType::from_repr(syntax.into_repr())), |
3618 | _ => None, | 2634 | _ => None, |
3619 | } | 2635 | } |
3620 | } | 2636 | } |
3621 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2637 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3622 | } | 2638 | fn to_owned(&self) -> TreePtr<SliceType> { TreePtr::cast(self.syntax.to_owned()) } |
3623 | |||
3624 | impl<R: TreeRoot<RaTypes>> SliceTypeNode<R> { | ||
3625 | pub fn borrowed(&self) -> SliceType { | ||
3626 | SliceTypeNode { syntax: self.syntax.borrowed() } | ||
3627 | } | ||
3628 | pub fn owned(&self) -> SliceTypeNode { | ||
3629 | SliceTypeNode { syntax: self.syntax.owned() } | ||
3630 | } | ||
3631 | } | 2639 | } |
3632 | 2640 | ||
3633 | 2641 | ||
3634 | impl<'a> SliceType<'a> { | 2642 | impl SliceType { |
3635 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2643 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3636 | super::child_opt(self) | 2644 | super::child_opt(self) |
3637 | } | 2645 | } |
3638 | } | 2646 | } |
3639 | 2647 | ||
3640 | // SourceFile | 2648 | // SourceFile |
3641 | #[derive(Debug, Clone, Copy,)] | 2649 | #[derive(Debug, PartialEq, Eq, Hash)] |
3642 | pub struct SourceFileNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2650 | #[repr(transparent)] |
3643 | pub(crate) syntax: SyntaxNode<R>, | 2651 | pub struct SourceFile { |
2652 | pub(crate) syntax: SyntaxNode, | ||
3644 | } | 2653 | } |
3645 | pub type SourceFile<'a> = SourceFileNode<RefRoot<'a>>; | 2654 | unsafe impl TransparentNewType for SourceFile { |
3646 | 2655 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3647 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SourceFileNode<R1>> for SourceFileNode<R2> { | ||
3648 | fn eq(&self, other: &SourceFileNode<R1>) -> bool { self.syntax == other.syntax } | ||
3649 | } | ||
3650 | impl<R: TreeRoot<RaTypes>> Eq for SourceFileNode<R> {} | ||
3651 | impl<R: TreeRoot<RaTypes>> Hash for SourceFileNode<R> { | ||
3652 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3653 | } | 2656 | } |
3654 | 2657 | ||
3655 | impl<'a> AstNode<'a> for SourceFile<'a> { | 2658 | impl AstNode for SourceFile { |
3656 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2659 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3657 | match syntax.kind() { | 2660 | match syntax.kind() { |
3658 | SOURCE_FILE => Some(SourceFile { syntax }), | 2661 | SOURCE_FILE => Some(SourceFile::from_repr(syntax.into_repr())), |
3659 | _ => None, | 2662 | _ => None, |
3660 | } | 2663 | } |
3661 | } | 2664 | } |
3662 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2665 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2666 | fn to_owned(&self) -> TreePtr<SourceFile> { TreePtr::cast(self.syntax.to_owned()) } | ||
3663 | } | 2667 | } |
3664 | 2668 | ||
3665 | impl<R: TreeRoot<RaTypes>> SourceFileNode<R> { | ||
3666 | pub fn borrowed(&self) -> SourceFile { | ||
3667 | SourceFileNode { syntax: self.syntax.borrowed() } | ||
3668 | } | ||
3669 | pub fn owned(&self) -> SourceFileNode { | ||
3670 | SourceFileNode { syntax: self.syntax.owned() } | ||
3671 | } | ||
3672 | } | ||
3673 | 2669 | ||
3674 | 2670 | impl ast::ModuleItemOwner for SourceFile {} | |
3675 | impl<'a> ast::ModuleItemOwner<'a> for SourceFile<'a> {} | 2671 | impl ast::FnDefOwner for SourceFile {} |
3676 | impl<'a> ast::FnDefOwner<'a> for SourceFile<'a> {} | 2672 | impl SourceFile { |
3677 | impl<'a> SourceFile<'a> { | 2673 | pub fn modules(&self) -> impl Iterator<Item = &Module> { |
3678 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { | ||
3679 | super::children(self) | 2674 | super::children(self) |
3680 | } | 2675 | } |
3681 | } | 2676 | } |
3682 | 2677 | ||
3683 | // StaticDef | 2678 | // StaticDef |
3684 | #[derive(Debug, Clone, Copy,)] | 2679 | #[derive(Debug, PartialEq, Eq, Hash)] |
3685 | pub struct StaticDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2680 | #[repr(transparent)] |
3686 | pub(crate) syntax: SyntaxNode<R>, | 2681 | pub struct StaticDef { |
3687 | } | 2682 | pub(crate) syntax: SyntaxNode, |
3688 | pub type StaticDef<'a> = StaticDefNode<RefRoot<'a>>; | ||
3689 | |||
3690 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StaticDefNode<R1>> for StaticDefNode<R2> { | ||
3691 | fn eq(&self, other: &StaticDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3692 | } | 2683 | } |
3693 | impl<R: TreeRoot<RaTypes>> Eq for StaticDefNode<R> {} | 2684 | unsafe impl TransparentNewType for StaticDef { |
3694 | impl<R: TreeRoot<RaTypes>> Hash for StaticDefNode<R> { | 2685 | type Repr = rowan::SyntaxNode<RaTypes>; |
3695 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3696 | } | 2686 | } |
3697 | 2687 | ||
3698 | impl<'a> AstNode<'a> for StaticDef<'a> { | 2688 | impl AstNode for StaticDef { |
3699 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2689 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3700 | match syntax.kind() { | 2690 | match syntax.kind() { |
3701 | STATIC_DEF => Some(StaticDef { syntax }), | 2691 | STATIC_DEF => Some(StaticDef::from_repr(syntax.into_repr())), |
3702 | _ => None, | 2692 | _ => None, |
3703 | } | 2693 | } |
3704 | } | 2694 | } |
3705 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2695 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2696 | fn to_owned(&self) -> TreePtr<StaticDef> { TreePtr::cast(self.syntax.to_owned()) } | ||
3706 | } | 2697 | } |
3707 | 2698 | ||
3708 | impl<R: TreeRoot<RaTypes>> StaticDefNode<R> { | ||
3709 | pub fn borrowed(&self) -> StaticDef { | ||
3710 | StaticDefNode { syntax: self.syntax.borrowed() } | ||
3711 | } | ||
3712 | pub fn owned(&self) -> StaticDefNode { | ||
3713 | StaticDefNode { syntax: self.syntax.owned() } | ||
3714 | } | ||
3715 | } | ||
3716 | 2699 | ||
3717 | 2700 | impl ast::VisibilityOwner for StaticDef {} | |
3718 | impl<'a> ast::VisibilityOwner<'a> for StaticDef<'a> {} | 2701 | impl ast::NameOwner for StaticDef {} |
3719 | impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} | 2702 | impl ast::TypeParamsOwner for StaticDef {} |
3720 | impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {} | 2703 | impl ast::AttrsOwner for StaticDef {} |
3721 | impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} | 2704 | impl ast::DocCommentsOwner for StaticDef {} |
3722 | impl<'a> ast::DocCommentsOwner<'a> for StaticDef<'a> {} | 2705 | impl StaticDef {} |
3723 | impl<'a> StaticDef<'a> {} | ||
3724 | 2706 | ||
3725 | // Stmt | 2707 | // Stmt |
2708 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
2709 | #[repr(transparent)] | ||
2710 | pub struct Stmt { | ||
2711 | pub(crate) syntax: SyntaxNode, | ||
2712 | } | ||
2713 | unsafe impl TransparentNewType for Stmt { | ||
2714 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
2715 | } | ||
2716 | |||
3726 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 2717 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
3727 | pub enum Stmt<'a> { | 2718 | pub enum StmtKind<'a> { |
3728 | ExprStmt(ExprStmt<'a>), | 2719 | ExprStmt(&'a ExprStmt), |
3729 | LetStmt(LetStmt<'a>), | 2720 | LetStmt(&'a LetStmt), |
3730 | } | 2721 | } |
3731 | 2722 | ||
3732 | impl<'a> AstNode<'a> for Stmt<'a> { | 2723 | impl AstNode for Stmt { |
3733 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2724 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3734 | match syntax.kind() { | 2725 | match syntax.kind() { |
3735 | EXPR_STMT => Some(Stmt::ExprStmt(ExprStmt { syntax })), | 2726 | | EXPR_STMT |
3736 | LET_STMT => Some(Stmt::LetStmt(LetStmt { syntax })), | 2727 | | LET_STMT => Some(Stmt::from_repr(syntax.into_repr())), |
3737 | _ => None, | 2728 | _ => None, |
3738 | } | 2729 | } |
3739 | } | 2730 | } |
3740 | fn syntax(self) -> SyntaxNodeRef<'a> { | 2731 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3741 | match self { | 2732 | fn to_owned(&self) -> TreePtr<Stmt> { TreePtr::cast(self.syntax.to_owned()) } |
3742 | Stmt::ExprStmt(inner) => inner.syntax(), | 2733 | } |
3743 | Stmt::LetStmt(inner) => inner.syntax(), | 2734 | |
2735 | impl Stmt { | ||
2736 | pub fn kind(&self) -> StmtKind { | ||
2737 | match self.syntax.kind() { | ||
2738 | EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(&self.syntax).unwrap()), | ||
2739 | LET_STMT => StmtKind::LetStmt(LetStmt::cast(&self.syntax).unwrap()), | ||
2740 | _ => unreachable!(), | ||
3744 | } | 2741 | } |
3745 | } | 2742 | } |
3746 | } | 2743 | } |
3747 | 2744 | ||
3748 | impl<'a> Stmt<'a> {} | 2745 | impl Stmt {} |
3749 | 2746 | ||
3750 | // String | 2747 | // String |
3751 | #[derive(Debug, Clone, Copy,)] | 2748 | #[derive(Debug, PartialEq, Eq, Hash)] |
3752 | pub struct StringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2749 | #[repr(transparent)] |
3753 | pub(crate) syntax: SyntaxNode<R>, | 2750 | pub struct String { |
3754 | } | 2751 | pub(crate) syntax: SyntaxNode, |
3755 | pub type String<'a> = StringNode<RefRoot<'a>>; | ||
3756 | |||
3757 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StringNode<R1>> for StringNode<R2> { | ||
3758 | fn eq(&self, other: &StringNode<R1>) -> bool { self.syntax == other.syntax } | ||
3759 | } | 2752 | } |
3760 | impl<R: TreeRoot<RaTypes>> Eq for StringNode<R> {} | 2753 | unsafe impl TransparentNewType for String { |
3761 | impl<R: TreeRoot<RaTypes>> Hash for StringNode<R> { | 2754 | type Repr = rowan::SyntaxNode<RaTypes>; |
3762 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3763 | } | 2755 | } |
3764 | 2756 | ||
3765 | impl<'a> AstNode<'a> for String<'a> { | 2757 | impl AstNode for String { |
3766 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2758 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3767 | match syntax.kind() { | 2759 | match syntax.kind() { |
3768 | STRING => Some(String { syntax }), | 2760 | STRING => Some(String::from_repr(syntax.into_repr())), |
3769 | _ => None, | 2761 | _ => None, |
3770 | } | 2762 | } |
3771 | } | 2763 | } |
3772 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2764 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3773 | } | 2765 | fn to_owned(&self) -> TreePtr<String> { TreePtr::cast(self.syntax.to_owned()) } |
3774 | |||
3775 | impl<R: TreeRoot<RaTypes>> StringNode<R> { | ||
3776 | pub fn borrowed(&self) -> String { | ||
3777 | StringNode { syntax: self.syntax.borrowed() } | ||
3778 | } | ||
3779 | pub fn owned(&self) -> StringNode { | ||
3780 | StringNode { syntax: self.syntax.owned() } | ||
3781 | } | ||
3782 | } | 2766 | } |
3783 | 2767 | ||
3784 | 2768 | ||
3785 | impl<'a> String<'a> {} | 2769 | impl String {} |
3786 | 2770 | ||
3787 | // StructDef | 2771 | // StructDef |
3788 | #[derive(Debug, Clone, Copy,)] | 2772 | #[derive(Debug, PartialEq, Eq, Hash)] |
3789 | pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2773 | #[repr(transparent)] |
3790 | pub(crate) syntax: SyntaxNode<R>, | 2774 | pub struct StructDef { |
2775 | pub(crate) syntax: SyntaxNode, | ||
3791 | } | 2776 | } |
3792 | pub type StructDef<'a> = StructDefNode<RefRoot<'a>>; | 2777 | unsafe impl TransparentNewType for StructDef { |
3793 | 2778 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3794 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructDefNode<R1>> for StructDefNode<R2> { | ||
3795 | fn eq(&self, other: &StructDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3796 | } | ||
3797 | impl<R: TreeRoot<RaTypes>> Eq for StructDefNode<R> {} | ||
3798 | impl<R: TreeRoot<RaTypes>> Hash for StructDefNode<R> { | ||
3799 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3800 | } | 2779 | } |
3801 | 2780 | ||
3802 | impl<'a> AstNode<'a> for StructDef<'a> { | 2781 | impl AstNode for StructDef { |
3803 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2782 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3804 | match syntax.kind() { | 2783 | match syntax.kind() { |
3805 | STRUCT_DEF => Some(StructDef { syntax }), | 2784 | STRUCT_DEF => Some(StructDef::from_repr(syntax.into_repr())), |
3806 | _ => None, | 2785 | _ => None, |
3807 | } | 2786 | } |
3808 | } | 2787 | } |
3809 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2788 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3810 | } | 2789 | fn to_owned(&self) -> TreePtr<StructDef> { TreePtr::cast(self.syntax.to_owned()) } |
3811 | |||
3812 | impl<R: TreeRoot<RaTypes>> StructDefNode<R> { | ||
3813 | pub fn borrowed(&self) -> StructDef { | ||
3814 | StructDefNode { syntax: self.syntax.borrowed() } | ||
3815 | } | ||
3816 | pub fn owned(&self) -> StructDefNode { | ||
3817 | StructDefNode { syntax: self.syntax.owned() } | ||
3818 | } | ||
3819 | } | 2790 | } |
3820 | 2791 | ||
3821 | 2792 | ||
3822 | impl<'a> ast::VisibilityOwner<'a> for StructDef<'a> {} | 2793 | impl ast::VisibilityOwner for StructDef {} |
3823 | impl<'a> ast::NameOwner<'a> for StructDef<'a> {} | 2794 | impl ast::NameOwner for StructDef {} |
3824 | impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {} | 2795 | impl ast::TypeParamsOwner for StructDef {} |
3825 | impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} | 2796 | impl ast::AttrsOwner for StructDef {} |
3826 | impl<'a> ast::DocCommentsOwner<'a> for StructDef<'a> {} | 2797 | impl ast::DocCommentsOwner for StructDef {} |
3827 | impl<'a> StructDef<'a> {} | 2798 | impl StructDef {} |
3828 | 2799 | ||
3829 | // StructLit | 2800 | // StructLit |
3830 | #[derive(Debug, Clone, Copy,)] | 2801 | #[derive(Debug, PartialEq, Eq, Hash)] |
3831 | pub struct StructLitNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2802 | #[repr(transparent)] |
3832 | pub(crate) syntax: SyntaxNode<R>, | 2803 | pub struct StructLit { |
2804 | pub(crate) syntax: SyntaxNode, | ||
3833 | } | 2805 | } |
3834 | pub type StructLit<'a> = StructLitNode<RefRoot<'a>>; | 2806 | unsafe impl TransparentNewType for StructLit { |
3835 | 2807 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3836 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructLitNode<R1>> for StructLitNode<R2> { | ||
3837 | fn eq(&self, other: &StructLitNode<R1>) -> bool { self.syntax == other.syntax } | ||
3838 | } | ||
3839 | impl<R: TreeRoot<RaTypes>> Eq for StructLitNode<R> {} | ||
3840 | impl<R: TreeRoot<RaTypes>> Hash for StructLitNode<R> { | ||
3841 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3842 | } | 2808 | } |
3843 | 2809 | ||
3844 | impl<'a> AstNode<'a> for StructLit<'a> { | 2810 | impl AstNode for StructLit { |
3845 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2811 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3846 | match syntax.kind() { | 2812 | match syntax.kind() { |
3847 | STRUCT_LIT => Some(StructLit { syntax }), | 2813 | STRUCT_LIT => Some(StructLit::from_repr(syntax.into_repr())), |
3848 | _ => None, | 2814 | _ => None, |
3849 | } | 2815 | } |
3850 | } | 2816 | } |
3851 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2817 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3852 | } | 2818 | fn to_owned(&self) -> TreePtr<StructLit> { TreePtr::cast(self.syntax.to_owned()) } |
3853 | |||
3854 | impl<R: TreeRoot<RaTypes>> StructLitNode<R> { | ||
3855 | pub fn borrowed(&self) -> StructLit { | ||
3856 | StructLitNode { syntax: self.syntax.borrowed() } | ||
3857 | } | ||
3858 | pub fn owned(&self) -> StructLitNode { | ||
3859 | StructLitNode { syntax: self.syntax.owned() } | ||
3860 | } | ||
3861 | } | 2819 | } |
3862 | 2820 | ||
3863 | 2821 | ||
3864 | impl<'a> StructLit<'a> { | 2822 | impl StructLit { |
3865 | pub fn path(self) -> Option<Path<'a>> { | 2823 | pub fn path(&self) -> Option<&Path> { |
3866 | super::child_opt(self) | 2824 | super::child_opt(self) |
3867 | } | 2825 | } |
3868 | 2826 | ||
3869 | pub fn named_field_list(self) -> Option<NamedFieldList<'a>> { | 2827 | pub fn named_field_list(&self) -> Option<&NamedFieldList> { |
3870 | super::child_opt(self) | 2828 | super::child_opt(self) |
3871 | } | 2829 | } |
3872 | 2830 | ||
3873 | pub fn spread(self) -> Option<Expr<'a>> { | 2831 | pub fn spread(&self) -> Option<&Expr> { |
3874 | super::child_opt(self) | 2832 | super::child_opt(self) |
3875 | } | 2833 | } |
3876 | } | 2834 | } |
3877 | 2835 | ||
3878 | // StructPat | 2836 | // StructPat |
3879 | #[derive(Debug, Clone, Copy,)] | 2837 | #[derive(Debug, PartialEq, Eq, Hash)] |
3880 | pub struct StructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2838 | #[repr(transparent)] |
3881 | pub(crate) syntax: SyntaxNode<R>, | 2839 | pub struct StructPat { |
3882 | } | 2840 | pub(crate) syntax: SyntaxNode, |
3883 | pub type StructPat<'a> = StructPatNode<RefRoot<'a>>; | ||
3884 | |||
3885 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructPatNode<R1>> for StructPatNode<R2> { | ||
3886 | fn eq(&self, other: &StructPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3887 | } | 2841 | } |
3888 | impl<R: TreeRoot<RaTypes>> Eq for StructPatNode<R> {} | 2842 | unsafe impl TransparentNewType for StructPat { |
3889 | impl<R: TreeRoot<RaTypes>> Hash for StructPatNode<R> { | 2843 | type Repr = rowan::SyntaxNode<RaTypes>; |
3890 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3891 | } | 2844 | } |
3892 | 2845 | ||
3893 | impl<'a> AstNode<'a> for StructPat<'a> { | 2846 | impl AstNode for StructPat { |
3894 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2847 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3895 | match syntax.kind() { | 2848 | match syntax.kind() { |
3896 | STRUCT_PAT => Some(StructPat { syntax }), | 2849 | STRUCT_PAT => Some(StructPat::from_repr(syntax.into_repr())), |
3897 | _ => None, | 2850 | _ => None, |
3898 | } | 2851 | } |
3899 | } | 2852 | } |
3900 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2853 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2854 | fn to_owned(&self) -> TreePtr<StructPat> { TreePtr::cast(self.syntax.to_owned()) } | ||
3901 | } | 2855 | } |
3902 | 2856 | ||
3903 | impl<R: TreeRoot<RaTypes>> StructPatNode<R> { | ||
3904 | pub fn borrowed(&self) -> StructPat { | ||
3905 | StructPatNode { syntax: self.syntax.borrowed() } | ||
3906 | } | ||
3907 | pub fn owned(&self) -> StructPatNode { | ||
3908 | StructPatNode { syntax: self.syntax.owned() } | ||
3909 | } | ||
3910 | } | ||
3911 | 2857 | ||
3912 | 2858 | impl StructPat {} | |
3913 | impl<'a> StructPat<'a> {} | ||
3914 | 2859 | ||
3915 | // TokenTree | 2860 | // TokenTree |
3916 | #[derive(Debug, Clone, Copy,)] | 2861 | #[derive(Debug, PartialEq, Eq, Hash)] |
3917 | pub struct TokenTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2862 | #[repr(transparent)] |
3918 | pub(crate) syntax: SyntaxNode<R>, | 2863 | pub struct TokenTree { |
3919 | } | 2864 | pub(crate) syntax: SyntaxNode, |
3920 | pub type TokenTree<'a> = TokenTreeNode<RefRoot<'a>>; | ||
3921 | |||
3922 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TokenTreeNode<R1>> for TokenTreeNode<R2> { | ||
3923 | fn eq(&self, other: &TokenTreeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3924 | } | 2865 | } |
3925 | impl<R: TreeRoot<RaTypes>> Eq for TokenTreeNode<R> {} | 2866 | unsafe impl TransparentNewType for TokenTree { |
3926 | impl<R: TreeRoot<RaTypes>> Hash for TokenTreeNode<R> { | 2867 | type Repr = rowan::SyntaxNode<RaTypes>; |
3927 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3928 | } | 2868 | } |
3929 | 2869 | ||
3930 | impl<'a> AstNode<'a> for TokenTree<'a> { | 2870 | impl AstNode for TokenTree { |
3931 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2871 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3932 | match syntax.kind() { | 2872 | match syntax.kind() { |
3933 | TOKEN_TREE => Some(TokenTree { syntax }), | 2873 | TOKEN_TREE => Some(TokenTree::from_repr(syntax.into_repr())), |
3934 | _ => None, | 2874 | _ => None, |
3935 | } | 2875 | } |
3936 | } | 2876 | } |
3937 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2877 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3938 | } | 2878 | fn to_owned(&self) -> TreePtr<TokenTree> { TreePtr::cast(self.syntax.to_owned()) } |
3939 | |||
3940 | impl<R: TreeRoot<RaTypes>> TokenTreeNode<R> { | ||
3941 | pub fn borrowed(&self) -> TokenTree { | ||
3942 | TokenTreeNode { syntax: self.syntax.borrowed() } | ||
3943 | } | ||
3944 | pub fn owned(&self) -> TokenTreeNode { | ||
3945 | TokenTreeNode { syntax: self.syntax.owned() } | ||
3946 | } | ||
3947 | } | 2879 | } |
3948 | 2880 | ||
3949 | 2881 | ||
3950 | impl<'a> TokenTree<'a> {} | 2882 | impl TokenTree {} |
3951 | 2883 | ||
3952 | // TraitDef | 2884 | // TraitDef |
3953 | #[derive(Debug, Clone, Copy,)] | 2885 | #[derive(Debug, PartialEq, Eq, Hash)] |
3954 | pub struct TraitDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2886 | #[repr(transparent)] |
3955 | pub(crate) syntax: SyntaxNode<R>, | 2887 | pub struct TraitDef { |
2888 | pub(crate) syntax: SyntaxNode, | ||
3956 | } | 2889 | } |
3957 | pub type TraitDef<'a> = TraitDefNode<RefRoot<'a>>; | 2890 | unsafe impl TransparentNewType for TraitDef { |
3958 | 2891 | type Repr = rowan::SyntaxNode<RaTypes>; | |
3959 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TraitDefNode<R1>> for TraitDefNode<R2> { | ||
3960 | fn eq(&self, other: &TraitDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3961 | } | ||
3962 | impl<R: TreeRoot<RaTypes>> Eq for TraitDefNode<R> {} | ||
3963 | impl<R: TreeRoot<RaTypes>> Hash for TraitDefNode<R> { | ||
3964 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3965 | } | 2892 | } |
3966 | 2893 | ||
3967 | impl<'a> AstNode<'a> for TraitDef<'a> { | 2894 | impl AstNode for TraitDef { |
3968 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2895 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3969 | match syntax.kind() { | 2896 | match syntax.kind() { |
3970 | TRAIT_DEF => Some(TraitDef { syntax }), | 2897 | TRAIT_DEF => Some(TraitDef::from_repr(syntax.into_repr())), |
3971 | _ => None, | 2898 | _ => None, |
3972 | } | 2899 | } |
3973 | } | 2900 | } |
3974 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2901 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3975 | } | 2902 | fn to_owned(&self) -> TreePtr<TraitDef> { TreePtr::cast(self.syntax.to_owned()) } |
3976 | |||
3977 | impl<R: TreeRoot<RaTypes>> TraitDefNode<R> { | ||
3978 | pub fn borrowed(&self) -> TraitDef { | ||
3979 | TraitDefNode { syntax: self.syntax.borrowed() } | ||
3980 | } | ||
3981 | pub fn owned(&self) -> TraitDefNode { | ||
3982 | TraitDefNode { syntax: self.syntax.owned() } | ||
3983 | } | ||
3984 | } | 2903 | } |
3985 | 2904 | ||
3986 | 2905 | ||
3987 | impl<'a> ast::VisibilityOwner<'a> for TraitDef<'a> {} | 2906 | impl ast::VisibilityOwner for TraitDef {} |
3988 | impl<'a> ast::NameOwner<'a> for TraitDef<'a> {} | 2907 | impl ast::NameOwner for TraitDef {} |
3989 | impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {} | 2908 | impl ast::AttrsOwner for TraitDef {} |
3990 | impl<'a> ast::DocCommentsOwner<'a> for TraitDef<'a> {} | 2909 | impl ast::DocCommentsOwner for TraitDef {} |
3991 | impl<'a> TraitDef<'a> {} | 2910 | impl TraitDef {} |
3992 | 2911 | ||
3993 | // TryExpr | 2912 | // TryExpr |
3994 | #[derive(Debug, Clone, Copy,)] | 2913 | #[derive(Debug, PartialEq, Eq, Hash)] |
3995 | pub struct TryExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2914 | #[repr(transparent)] |
3996 | pub(crate) syntax: SyntaxNode<R>, | 2915 | pub struct TryExpr { |
2916 | pub(crate) syntax: SyntaxNode, | ||
3997 | } | 2917 | } |
3998 | pub type TryExpr<'a> = TryExprNode<RefRoot<'a>>; | 2918 | unsafe impl TransparentNewType for TryExpr { |
3999 | 2919 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4000 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TryExprNode<R1>> for TryExprNode<R2> { | ||
4001 | fn eq(&self, other: &TryExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
4002 | } | ||
4003 | impl<R: TreeRoot<RaTypes>> Eq for TryExprNode<R> {} | ||
4004 | impl<R: TreeRoot<RaTypes>> Hash for TryExprNode<R> { | ||
4005 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4006 | } | 2920 | } |
4007 | 2921 | ||
4008 | impl<'a> AstNode<'a> for TryExpr<'a> { | 2922 | impl AstNode for TryExpr { |
4009 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2923 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4010 | match syntax.kind() { | 2924 | match syntax.kind() { |
4011 | TRY_EXPR => Some(TryExpr { syntax }), | 2925 | TRY_EXPR => Some(TryExpr::from_repr(syntax.into_repr())), |
4012 | _ => None, | 2926 | _ => None, |
4013 | } | 2927 | } |
4014 | } | 2928 | } |
4015 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2929 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2930 | fn to_owned(&self) -> TreePtr<TryExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
4016 | } | 2931 | } |
4017 | 2932 | ||
4018 | impl<R: TreeRoot<RaTypes>> TryExprNode<R> { | ||
4019 | pub fn borrowed(&self) -> TryExpr { | ||
4020 | TryExprNode { syntax: self.syntax.borrowed() } | ||
4021 | } | ||
4022 | pub fn owned(&self) -> TryExprNode { | ||
4023 | TryExprNode { syntax: self.syntax.owned() } | ||
4024 | } | ||
4025 | } | ||
4026 | 2933 | ||
4027 | 2934 | impl TryExpr { | |
4028 | impl<'a> TryExpr<'a> { | 2935 | pub fn expr(&self) -> Option<&Expr> { |
4029 | pub fn expr(self) -> Option<Expr<'a>> { | ||
4030 | super::child_opt(self) | 2936 | super::child_opt(self) |
4031 | } | 2937 | } |
4032 | } | 2938 | } |
4033 | 2939 | ||
4034 | // TupleExpr | 2940 | // TupleExpr |
4035 | #[derive(Debug, Clone, Copy,)] | 2941 | #[derive(Debug, PartialEq, Eq, Hash)] |
4036 | pub struct TupleExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2942 | #[repr(transparent)] |
4037 | pub(crate) syntax: SyntaxNode<R>, | 2943 | pub struct TupleExpr { |
4038 | } | 2944 | pub(crate) syntax: SyntaxNode, |
4039 | pub type TupleExpr<'a> = TupleExprNode<RefRoot<'a>>; | ||
4040 | |||
4041 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleExprNode<R1>> for TupleExprNode<R2> { | ||
4042 | fn eq(&self, other: &TupleExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
4043 | } | 2945 | } |
4044 | impl<R: TreeRoot<RaTypes>> Eq for TupleExprNode<R> {} | 2946 | unsafe impl TransparentNewType for TupleExpr { |
4045 | impl<R: TreeRoot<RaTypes>> Hash for TupleExprNode<R> { | 2947 | type Repr = rowan::SyntaxNode<RaTypes>; |
4046 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4047 | } | 2948 | } |
4048 | 2949 | ||
4049 | impl<'a> AstNode<'a> for TupleExpr<'a> { | 2950 | impl AstNode for TupleExpr { |
4050 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2951 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4051 | match syntax.kind() { | 2952 | match syntax.kind() { |
4052 | TUPLE_EXPR => Some(TupleExpr { syntax }), | 2953 | TUPLE_EXPR => Some(TupleExpr::from_repr(syntax.into_repr())), |
4053 | _ => None, | 2954 | _ => None, |
4054 | } | 2955 | } |
4055 | } | 2956 | } |
4056 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2957 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4057 | } | 2958 | fn to_owned(&self) -> TreePtr<TupleExpr> { TreePtr::cast(self.syntax.to_owned()) } |
4058 | |||
4059 | impl<R: TreeRoot<RaTypes>> TupleExprNode<R> { | ||
4060 | pub fn borrowed(&self) -> TupleExpr { | ||
4061 | TupleExprNode { syntax: self.syntax.borrowed() } | ||
4062 | } | ||
4063 | pub fn owned(&self) -> TupleExprNode { | ||
4064 | TupleExprNode { syntax: self.syntax.owned() } | ||
4065 | } | ||
4066 | } | 2959 | } |
4067 | 2960 | ||
4068 | 2961 | ||
4069 | impl<'a> TupleExpr<'a> {} | 2962 | impl TupleExpr {} |
4070 | 2963 | ||
4071 | // TuplePat | 2964 | // TuplePat |
4072 | #[derive(Debug, Clone, Copy,)] | 2965 | #[derive(Debug, PartialEq, Eq, Hash)] |
4073 | pub struct TuplePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2966 | #[repr(transparent)] |
4074 | pub(crate) syntax: SyntaxNode<R>, | 2967 | pub struct TuplePat { |
2968 | pub(crate) syntax: SyntaxNode, | ||
4075 | } | 2969 | } |
4076 | pub type TuplePat<'a> = TuplePatNode<RefRoot<'a>>; | 2970 | unsafe impl TransparentNewType for TuplePat { |
4077 | 2971 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4078 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TuplePatNode<R1>> for TuplePatNode<R2> { | ||
4079 | fn eq(&self, other: &TuplePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
4080 | } | ||
4081 | impl<R: TreeRoot<RaTypes>> Eq for TuplePatNode<R> {} | ||
4082 | impl<R: TreeRoot<RaTypes>> Hash for TuplePatNode<R> { | ||
4083 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4084 | } | 2972 | } |
4085 | 2973 | ||
4086 | impl<'a> AstNode<'a> for TuplePat<'a> { | 2974 | impl AstNode for TuplePat { |
4087 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2975 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4088 | match syntax.kind() { | 2976 | match syntax.kind() { |
4089 | TUPLE_PAT => Some(TuplePat { syntax }), | 2977 | TUPLE_PAT => Some(TuplePat::from_repr(syntax.into_repr())), |
4090 | _ => None, | 2978 | _ => None, |
4091 | } | 2979 | } |
4092 | } | 2980 | } |
4093 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2981 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4094 | } | 2982 | fn to_owned(&self) -> TreePtr<TuplePat> { TreePtr::cast(self.syntax.to_owned()) } |
4095 | |||
4096 | impl<R: TreeRoot<RaTypes>> TuplePatNode<R> { | ||
4097 | pub fn borrowed(&self) -> TuplePat { | ||
4098 | TuplePatNode { syntax: self.syntax.borrowed() } | ||
4099 | } | ||
4100 | pub fn owned(&self) -> TuplePatNode { | ||
4101 | TuplePatNode { syntax: self.syntax.owned() } | ||
4102 | } | ||
4103 | } | 2983 | } |
4104 | 2984 | ||
4105 | 2985 | ||
4106 | impl<'a> TuplePat<'a> {} | 2986 | impl TuplePat {} |
4107 | 2987 | ||
4108 | // TupleStructPat | 2988 | // TupleStructPat |
4109 | #[derive(Debug, Clone, Copy,)] | 2989 | #[derive(Debug, PartialEq, Eq, Hash)] |
4110 | pub struct TupleStructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2990 | #[repr(transparent)] |
4111 | pub(crate) syntax: SyntaxNode<R>, | 2991 | pub struct TupleStructPat { |
2992 | pub(crate) syntax: SyntaxNode, | ||
4112 | } | 2993 | } |
4113 | pub type TupleStructPat<'a> = TupleStructPatNode<RefRoot<'a>>; | 2994 | unsafe impl TransparentNewType for TupleStructPat { |
4114 | 2995 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4115 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleStructPatNode<R1>> for TupleStructPatNode<R2> { | ||
4116 | fn eq(&self, other: &TupleStructPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
4117 | } | ||
4118 | impl<R: TreeRoot<RaTypes>> Eq for TupleStructPatNode<R> {} | ||
4119 | impl<R: TreeRoot<RaTypes>> Hash for TupleStructPatNode<R> { | ||
4120 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4121 | } | 2996 | } |
4122 | 2997 | ||
4123 | impl<'a> AstNode<'a> for TupleStructPat<'a> { | 2998 | impl AstNode for TupleStructPat { |
4124 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2999 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4125 | match syntax.kind() { | 3000 | match syntax.kind() { |
4126 | TUPLE_STRUCT_PAT => Some(TupleStructPat { syntax }), | 3001 | TUPLE_STRUCT_PAT => Some(TupleStructPat::from_repr(syntax.into_repr())), |
4127 | _ => None, | 3002 | _ => None, |
4128 | } | 3003 | } |
4129 | } | 3004 | } |
4130 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3005 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4131 | } | 3006 | fn to_owned(&self) -> TreePtr<TupleStructPat> { TreePtr::cast(self.syntax.to_owned()) } |
4132 | |||
4133 | impl<R: TreeRoot<RaTypes>> TupleStructPatNode<R> { | ||
4134 | pub fn borrowed(&self) -> TupleStructPat { | ||
4135 | TupleStructPatNode { syntax: self.syntax.borrowed() } | ||
4136 | } | ||
4137 | pub fn owned(&self) -> TupleStructPatNode { | ||
4138 | TupleStructPatNode { syntax: self.syntax.owned() } | ||
4139 | } | ||
4140 | } | 3007 | } |
4141 | 3008 | ||
4142 | 3009 | ||
4143 | impl<'a> TupleStructPat<'a> { | 3010 | impl TupleStructPat { |
4144 | pub fn args(self) -> impl Iterator<Item = Pat<'a>> + 'a { | 3011 | pub fn args(&self) -> impl Iterator<Item = &Pat> { |
4145 | super::children(self) | 3012 | super::children(self) |
4146 | } | 3013 | } |
4147 | 3014 | ||
4148 | pub fn path(self) -> Option<Path<'a>> { | 3015 | pub fn path(&self) -> Option<&Path> { |
4149 | super::child_opt(self) | 3016 | super::child_opt(self) |
4150 | } | 3017 | } |
4151 | } | 3018 | } |
4152 | 3019 | ||
4153 | // TupleType | 3020 | // TupleType |
4154 | #[derive(Debug, Clone, Copy,)] | 3021 | #[derive(Debug, PartialEq, Eq, Hash)] |
4155 | pub struct TupleTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3022 | #[repr(transparent)] |
4156 | pub(crate) syntax: SyntaxNode<R>, | 3023 | pub struct TupleType { |
4157 | } | 3024 | pub(crate) syntax: SyntaxNode, |
4158 | pub type TupleType<'a> = TupleTypeNode<RefRoot<'a>>; | ||
4159 | |||
4160 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleTypeNode<R1>> for TupleTypeNode<R2> { | ||
4161 | fn eq(&self, other: &TupleTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
4162 | } | 3025 | } |
4163 | impl<R: TreeRoot<RaTypes>> Eq for TupleTypeNode<R> {} | 3026 | unsafe impl TransparentNewType for TupleType { |
4164 | impl<R: TreeRoot<RaTypes>> Hash for TupleTypeNode<R> { | 3027 | type Repr = rowan::SyntaxNode<RaTypes>; |
4165 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4166 | } | 3028 | } |
4167 | 3029 | ||
4168 | impl<'a> AstNode<'a> for TupleType<'a> { | 3030 | impl AstNode for TupleType { |
4169 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3031 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4170 | match syntax.kind() { | 3032 | match syntax.kind() { |
4171 | TUPLE_TYPE => Some(TupleType { syntax }), | 3033 | TUPLE_TYPE => Some(TupleType::from_repr(syntax.into_repr())), |
4172 | _ => None, | 3034 | _ => None, |
4173 | } | 3035 | } |
4174 | } | 3036 | } |
4175 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3037 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3038 | fn to_owned(&self) -> TreePtr<TupleType> { TreePtr::cast(self.syntax.to_owned()) } | ||
4176 | } | 3039 | } |
4177 | 3040 | ||
4178 | impl<R: TreeRoot<RaTypes>> TupleTypeNode<R> { | ||
4179 | pub fn borrowed(&self) -> TupleType { | ||
4180 | TupleTypeNode { syntax: self.syntax.borrowed() } | ||
4181 | } | ||
4182 | pub fn owned(&self) -> TupleTypeNode { | ||
4183 | TupleTypeNode { syntax: self.syntax.owned() } | ||
4184 | } | ||
4185 | } | ||
4186 | 3041 | ||
4187 | 3042 | impl TupleType { | |
4188 | impl<'a> TupleType<'a> { | 3043 | pub fn fields(&self) -> impl Iterator<Item = &TypeRef> { |
4189 | pub fn fields(self) -> impl Iterator<Item = TypeRef<'a>> + 'a { | ||
4190 | super::children(self) | 3044 | super::children(self) |
4191 | } | 3045 | } |
4192 | } | 3046 | } |
4193 | 3047 | ||
4194 | // TypeDef | 3048 | // TypeDef |
4195 | #[derive(Debug, Clone, Copy,)] | 3049 | #[derive(Debug, PartialEq, Eq, Hash)] |
4196 | pub struct TypeDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3050 | #[repr(transparent)] |
4197 | pub(crate) syntax: SyntaxNode<R>, | 3051 | pub struct TypeDef { |
4198 | } | 3052 | pub(crate) syntax: SyntaxNode, |
4199 | pub type TypeDef<'a> = TypeDefNode<RefRoot<'a>>; | ||
4200 | |||
4201 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeDefNode<R1>> for TypeDefNode<R2> { | ||
4202 | fn eq(&self, other: &TypeDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
4203 | } | 3053 | } |
4204 | impl<R: TreeRoot<RaTypes>> Eq for TypeDefNode<R> {} | 3054 | unsafe impl TransparentNewType for TypeDef { |
4205 | impl<R: TreeRoot<RaTypes>> Hash for TypeDefNode<R> { | 3055 | type Repr = rowan::SyntaxNode<RaTypes>; |
4206 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4207 | } | 3056 | } |
4208 | 3057 | ||
4209 | impl<'a> AstNode<'a> for TypeDef<'a> { | 3058 | impl AstNode for TypeDef { |
4210 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3059 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4211 | match syntax.kind() { | 3060 | match syntax.kind() { |
4212 | TYPE_DEF => Some(TypeDef { syntax }), | 3061 | TYPE_DEF => Some(TypeDef::from_repr(syntax.into_repr())), |
4213 | _ => None, | 3062 | _ => None, |
4214 | } | 3063 | } |
4215 | } | 3064 | } |
4216 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3065 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4217 | } | 3066 | fn to_owned(&self) -> TreePtr<TypeDef> { TreePtr::cast(self.syntax.to_owned()) } |
4218 | |||
4219 | impl<R: TreeRoot<RaTypes>> TypeDefNode<R> { | ||
4220 | pub fn borrowed(&self) -> TypeDef { | ||
4221 | TypeDefNode { syntax: self.syntax.borrowed() } | ||
4222 | } | ||
4223 | pub fn owned(&self) -> TypeDefNode { | ||
4224 | TypeDefNode { syntax: self.syntax.owned() } | ||
4225 | } | ||
4226 | } | 3067 | } |
4227 | 3068 | ||
4228 | 3069 | ||
4229 | impl<'a> ast::VisibilityOwner<'a> for TypeDef<'a> {} | 3070 | impl ast::VisibilityOwner for TypeDef {} |
4230 | impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} | 3071 | impl ast::NameOwner for TypeDef {} |
4231 | impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {} | 3072 | impl ast::TypeParamsOwner for TypeDef {} |
4232 | impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} | 3073 | impl ast::AttrsOwner for TypeDef {} |
4233 | impl<'a> ast::DocCommentsOwner<'a> for TypeDef<'a> {} | 3074 | impl ast::DocCommentsOwner for TypeDef {} |
4234 | impl<'a> TypeDef<'a> {} | 3075 | impl TypeDef {} |
4235 | 3076 | ||
4236 | // TypeParam | 3077 | // TypeParam |
4237 | #[derive(Debug, Clone, Copy,)] | 3078 | #[derive(Debug, PartialEq, Eq, Hash)] |
4238 | pub struct TypeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3079 | #[repr(transparent)] |
4239 | pub(crate) syntax: SyntaxNode<R>, | 3080 | pub struct TypeParam { |
3081 | pub(crate) syntax: SyntaxNode, | ||
4240 | } | 3082 | } |
4241 | pub type TypeParam<'a> = TypeParamNode<RefRoot<'a>>; | 3083 | unsafe impl TransparentNewType for TypeParam { |
4242 | 3084 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4243 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeParamNode<R1>> for TypeParamNode<R2> { | ||
4244 | fn eq(&self, other: &TypeParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
4245 | } | ||
4246 | impl<R: TreeRoot<RaTypes>> Eq for TypeParamNode<R> {} | ||
4247 | impl<R: TreeRoot<RaTypes>> Hash for TypeParamNode<R> { | ||
4248 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4249 | } | 3085 | } |
4250 | 3086 | ||
4251 | impl<'a> AstNode<'a> for TypeParam<'a> { | 3087 | impl AstNode for TypeParam { |
4252 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3088 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4253 | match syntax.kind() { | 3089 | match syntax.kind() { |
4254 | TYPE_PARAM => Some(TypeParam { syntax }), | 3090 | TYPE_PARAM => Some(TypeParam::from_repr(syntax.into_repr())), |
4255 | _ => None, | 3091 | _ => None, |
4256 | } | 3092 | } |
4257 | } | 3093 | } |
4258 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3094 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4259 | } | 3095 | fn to_owned(&self) -> TreePtr<TypeParam> { TreePtr::cast(self.syntax.to_owned()) } |
4260 | |||
4261 | impl<R: TreeRoot<RaTypes>> TypeParamNode<R> { | ||
4262 | pub fn borrowed(&self) -> TypeParam { | ||
4263 | TypeParamNode { syntax: self.syntax.borrowed() } | ||
4264 | } | ||
4265 | pub fn owned(&self) -> TypeParamNode { | ||
4266 | TypeParamNode { syntax: self.syntax.owned() } | ||
4267 | } | ||
4268 | } | 3096 | } |
4269 | 3097 | ||
4270 | 3098 | ||
4271 | impl<'a> ast::NameOwner<'a> for TypeParam<'a> {} | 3099 | impl ast::NameOwner for TypeParam {} |
4272 | impl<'a> TypeParam<'a> {} | 3100 | impl TypeParam {} |
4273 | 3101 | ||
4274 | // TypeParamList | 3102 | // TypeParamList |
4275 | #[derive(Debug, Clone, Copy,)] | 3103 | #[derive(Debug, PartialEq, Eq, Hash)] |
4276 | pub struct TypeParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3104 | #[repr(transparent)] |
4277 | pub(crate) syntax: SyntaxNode<R>, | 3105 | pub struct TypeParamList { |
3106 | pub(crate) syntax: SyntaxNode, | ||
4278 | } | 3107 | } |
4279 | pub type TypeParamList<'a> = TypeParamListNode<RefRoot<'a>>; | 3108 | unsafe impl TransparentNewType for TypeParamList { |
4280 | 3109 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4281 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeParamListNode<R1>> for TypeParamListNode<R2> { | ||
4282 | fn eq(&self, other: &TypeParamListNode<R1>) -> bool { self.syntax == other.syntax } | ||
4283 | } | ||
4284 | impl<R: TreeRoot<RaTypes>> Eq for TypeParamListNode<R> {} | ||
4285 | impl<R: TreeRoot<RaTypes>> Hash for TypeParamListNode<R> { | ||
4286 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4287 | } | 3110 | } |
4288 | 3111 | ||
4289 | impl<'a> AstNode<'a> for TypeParamList<'a> { | 3112 | impl AstNode for TypeParamList { |
4290 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3113 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4291 | match syntax.kind() { | 3114 | match syntax.kind() { |
4292 | TYPE_PARAM_LIST => Some(TypeParamList { syntax }), | 3115 | TYPE_PARAM_LIST => Some(TypeParamList::from_repr(syntax.into_repr())), |
4293 | _ => None, | 3116 | _ => None, |
4294 | } | 3117 | } |
4295 | } | 3118 | } |
4296 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3119 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3120 | fn to_owned(&self) -> TreePtr<TypeParamList> { TreePtr::cast(self.syntax.to_owned()) } | ||
4297 | } | 3121 | } |
4298 | 3122 | ||
4299 | impl<R: TreeRoot<RaTypes>> TypeParamListNode<R> { | ||
4300 | pub fn borrowed(&self) -> TypeParamList { | ||
4301 | TypeParamListNode { syntax: self.syntax.borrowed() } | ||
4302 | } | ||
4303 | pub fn owned(&self) -> TypeParamListNode { | ||
4304 | TypeParamListNode { syntax: self.syntax.owned() } | ||
4305 | } | ||
4306 | } | ||
4307 | 3123 | ||
4308 | 3124 | impl TypeParamList { | |
4309 | impl<'a> TypeParamList<'a> { | 3125 | pub fn type_params(&self) -> impl Iterator<Item = &TypeParam> { |
4310 | pub fn type_params(self) -> impl Iterator<Item = TypeParam<'a>> + 'a { | ||
4311 | super::children(self) | 3126 | super::children(self) |
4312 | } | 3127 | } |
4313 | 3128 | ||
4314 | pub fn lifetime_params(self) -> impl Iterator<Item = LifetimeParam<'a>> + 'a { | 3129 | pub fn lifetime_params(&self) -> impl Iterator<Item = &LifetimeParam> { |
4315 | super::children(self) | 3130 | super::children(self) |
4316 | } | 3131 | } |
4317 | } | 3132 | } |
4318 | 3133 | ||
4319 | // TypeRef | 3134 | // TypeRef |
4320 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 3135 | #[derive(Debug, PartialEq, Eq, Hash)] |
4321 | pub enum TypeRef<'a> { | 3136 | #[repr(transparent)] |
4322 | ParenType(ParenType<'a>), | 3137 | pub struct TypeRef { |
4323 | TupleType(TupleType<'a>), | 3138 | pub(crate) syntax: SyntaxNode, |
4324 | NeverType(NeverType<'a>), | 3139 | } |
4325 | PathType(PathType<'a>), | 3140 | unsafe impl TransparentNewType for TypeRef { |
4326 | PointerType(PointerType<'a>), | 3141 | type Repr = rowan::SyntaxNode<RaTypes>; |
4327 | ArrayType(ArrayType<'a>), | ||
4328 | SliceType(SliceType<'a>), | ||
4329 | ReferenceType(ReferenceType<'a>), | ||
4330 | PlaceholderType(PlaceholderType<'a>), | ||
4331 | FnPointerType(FnPointerType<'a>), | ||
4332 | ForType(ForType<'a>), | ||
4333 | ImplTraitType(ImplTraitType<'a>), | ||
4334 | DynTraitType(DynTraitType<'a>), | ||
4335 | } | ||
4336 | |||
4337 | impl<'a> AstNode<'a> for TypeRef<'a> { | ||
4338 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
4339 | match syntax.kind() { | ||
4340 | PAREN_TYPE => Some(TypeRef::ParenType(ParenType { syntax })), | ||
4341 | TUPLE_TYPE => Some(TypeRef::TupleType(TupleType { syntax })), | ||
4342 | NEVER_TYPE => Some(TypeRef::NeverType(NeverType { syntax })), | ||
4343 | PATH_TYPE => Some(TypeRef::PathType(PathType { syntax })), | ||
4344 | POINTER_TYPE => Some(TypeRef::PointerType(PointerType { syntax })), | ||
4345 | ARRAY_TYPE => Some(TypeRef::ArrayType(ArrayType { syntax })), | ||
4346 | SLICE_TYPE => Some(TypeRef::SliceType(SliceType { syntax })), | ||
4347 | REFERENCE_TYPE => Some(TypeRef::ReferenceType(ReferenceType { syntax })), | ||
4348 | PLACEHOLDER_TYPE => Some(TypeRef::PlaceholderType(PlaceholderType { syntax })), | ||
4349 | FN_POINTER_TYPE => Some(TypeRef::FnPointerType(FnPointerType { syntax })), | ||
4350 | FOR_TYPE => Some(TypeRef::ForType(ForType { syntax })), | ||
4351 | IMPL_TRAIT_TYPE => Some(TypeRef::ImplTraitType(ImplTraitType { syntax })), | ||
4352 | DYN_TRAIT_TYPE => Some(TypeRef::DynTraitType(DynTraitType { syntax })), | ||
4353 | _ => None, | ||
4354 | } | ||
4355 | } | ||
4356 | fn syntax(self) -> SyntaxNodeRef<'a> { | ||
4357 | match self { | ||
4358 | TypeRef::ParenType(inner) => inner.syntax(), | ||
4359 | TypeRef::TupleType(inner) => inner.syntax(), | ||
4360 | TypeRef::NeverType(inner) => inner.syntax(), | ||
4361 | TypeRef::PathType(inner) => inner.syntax(), | ||
4362 | TypeRef::PointerType(inner) => inner.syntax(), | ||
4363 | TypeRef::ArrayType(inner) => inner.syntax(), | ||
4364 | TypeRef::SliceType(inner) => inner.syntax(), | ||
4365 | TypeRef::ReferenceType(inner) => inner.syntax(), | ||
4366 | TypeRef::PlaceholderType(inner) => inner.syntax(), | ||
4367 | TypeRef::FnPointerType(inner) => inner.syntax(), | ||
4368 | TypeRef::ForType(inner) => inner.syntax(), | ||
4369 | TypeRef::ImplTraitType(inner) => inner.syntax(), | ||
4370 | TypeRef::DynTraitType(inner) => inner.syntax(), | ||
4371 | } | ||
4372 | } | ||
4373 | } | 3142 | } |
4374 | 3143 | ||
4375 | impl<'a> TypeRef<'a> {} | 3144 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
3145 | pub enum TypeRefKind<'a> { | ||
3146 | ParenType(&'a ParenType), | ||
3147 | TupleType(&'a TupleType), | ||
3148 | NeverType(&'a NeverType), | ||
3149 | PathType(&'a PathType), | ||
3150 | PointerType(&'a PointerType), | ||
3151 | ArrayType(&'a ArrayType), | ||
3152 | SliceType(&'a SliceType), | ||
3153 | ReferenceType(&'a ReferenceType), | ||
3154 | PlaceholderType(&'a PlaceholderType), | ||
3155 | FnPointerType(&'a FnPointerType), | ||
3156 | ForType(&'a ForType), | ||
3157 | ImplTraitType(&'a ImplTraitType), | ||
3158 | DynTraitType(&'a DynTraitType), | ||
3159 | } | ||
3160 | |||
3161 | impl AstNode for TypeRef { | ||
3162 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
3163 | match syntax.kind() { | ||
3164 | | PAREN_TYPE | ||
3165 | | TUPLE_TYPE | ||
3166 | | NEVER_TYPE | ||
3167 | | PATH_TYPE | ||
3168 | | POINTER_TYPE | ||
3169 | | ARRAY_TYPE | ||
3170 | | SLICE_TYPE | ||
3171 | | REFERENCE_TYPE | ||
3172 | | PLACEHOLDER_TYPE | ||
3173 | | FN_POINTER_TYPE | ||
3174 | | FOR_TYPE | ||
3175 | | IMPL_TRAIT_TYPE | ||
3176 | | DYN_TRAIT_TYPE => Some(TypeRef::from_repr(syntax.into_repr())), | ||
3177 | _ => None, | ||
3178 | } | ||
3179 | } | ||
3180 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3181 | fn to_owned(&self) -> TreePtr<TypeRef> { TreePtr::cast(self.syntax.to_owned()) } | ||
3182 | } | ||
3183 | |||
3184 | impl TypeRef { | ||
3185 | pub fn kind(&self) -> TypeRefKind { | ||
3186 | match self.syntax.kind() { | ||
3187 | PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(&self.syntax).unwrap()), | ||
3188 | TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(&self.syntax).unwrap()), | ||
3189 | NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(&self.syntax).unwrap()), | ||
3190 | PATH_TYPE => TypeRefKind::PathType(PathType::cast(&self.syntax).unwrap()), | ||
3191 | POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(&self.syntax).unwrap()), | ||
3192 | ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(&self.syntax).unwrap()), | ||
3193 | SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(&self.syntax).unwrap()), | ||
3194 | REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(&self.syntax).unwrap()), | ||
3195 | PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(&self.syntax).unwrap()), | ||
3196 | FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(&self.syntax).unwrap()), | ||
3197 | FOR_TYPE => TypeRefKind::ForType(ForType::cast(&self.syntax).unwrap()), | ||
3198 | IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(&self.syntax).unwrap()), | ||
3199 | DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(&self.syntax).unwrap()), | ||
3200 | _ => unreachable!(), | ||
3201 | } | ||
3202 | } | ||
3203 | } | ||
3204 | |||
3205 | impl TypeRef {} | ||
4376 | 3206 | ||
4377 | // UseItem | 3207 | // UseItem |
4378 | #[derive(Debug, Clone, Copy,)] | 3208 | #[derive(Debug, PartialEq, Eq, Hash)] |
4379 | pub struct UseItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3209 | #[repr(transparent)] |
4380 | pub(crate) syntax: SyntaxNode<R>, | 3210 | pub struct UseItem { |
3211 | pub(crate) syntax: SyntaxNode, | ||
4381 | } | 3212 | } |
4382 | pub type UseItem<'a> = UseItemNode<RefRoot<'a>>; | 3213 | unsafe impl TransparentNewType for UseItem { |
4383 | 3214 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4384 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseItemNode<R1>> for UseItemNode<R2> { | ||
4385 | fn eq(&self, other: &UseItemNode<R1>) -> bool { self.syntax == other.syntax } | ||
4386 | } | ||
4387 | impl<R: TreeRoot<RaTypes>> Eq for UseItemNode<R> {} | ||
4388 | impl<R: TreeRoot<RaTypes>> Hash for UseItemNode<R> { | ||
4389 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4390 | } | 3215 | } |
4391 | 3216 | ||
4392 | impl<'a> AstNode<'a> for UseItem<'a> { | 3217 | impl AstNode for UseItem { |
4393 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3218 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4394 | match syntax.kind() { | 3219 | match syntax.kind() { |
4395 | USE_ITEM => Some(UseItem { syntax }), | 3220 | USE_ITEM => Some(UseItem::from_repr(syntax.into_repr())), |
4396 | _ => None, | 3221 | _ => None, |
4397 | } | 3222 | } |
4398 | } | 3223 | } |
4399 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3224 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4400 | } | 3225 | fn to_owned(&self) -> TreePtr<UseItem> { TreePtr::cast(self.syntax.to_owned()) } |
4401 | |||
4402 | impl<R: TreeRoot<RaTypes>> UseItemNode<R> { | ||
4403 | pub fn borrowed(&self) -> UseItem { | ||
4404 | UseItemNode { syntax: self.syntax.borrowed() } | ||
4405 | } | ||
4406 | pub fn owned(&self) -> UseItemNode { | ||
4407 | UseItemNode { syntax: self.syntax.owned() } | ||
4408 | } | ||
4409 | } | 3226 | } |
4410 | 3227 | ||
4411 | 3228 | ||
4412 | impl<'a> UseItem<'a> { | 3229 | impl UseItem { |
4413 | pub fn use_tree(self) -> Option<UseTree<'a>> { | 3230 | pub fn use_tree(&self) -> Option<&UseTree> { |
4414 | super::child_opt(self) | 3231 | super::child_opt(self) |
4415 | } | 3232 | } |
4416 | } | 3233 | } |
4417 | 3234 | ||
4418 | // UseTree | 3235 | // UseTree |
4419 | #[derive(Debug, Clone, Copy,)] | 3236 | #[derive(Debug, PartialEq, Eq, Hash)] |
4420 | pub struct UseTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3237 | #[repr(transparent)] |
4421 | pub(crate) syntax: SyntaxNode<R>, | 3238 | pub struct UseTree { |
3239 | pub(crate) syntax: SyntaxNode, | ||
4422 | } | 3240 | } |
4423 | pub type UseTree<'a> = UseTreeNode<RefRoot<'a>>; | 3241 | unsafe impl TransparentNewType for UseTree { |
4424 | 3242 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4425 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseTreeNode<R1>> for UseTreeNode<R2> { | ||
4426 | fn eq(&self, other: &UseTreeNode<R1>) -> bool { self.syntax == other.syntax } | ||
4427 | } | ||
4428 | impl<R: TreeRoot<RaTypes>> Eq for UseTreeNode<R> {} | ||
4429 | impl<R: TreeRoot<RaTypes>> Hash for UseTreeNode<R> { | ||
4430 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4431 | } | 3243 | } |
4432 | 3244 | ||
4433 | impl<'a> AstNode<'a> for UseTree<'a> { | 3245 | impl AstNode for UseTree { |
4434 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3246 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4435 | match syntax.kind() { | 3247 | match syntax.kind() { |
4436 | USE_TREE => Some(UseTree { syntax }), | 3248 | USE_TREE => Some(UseTree::from_repr(syntax.into_repr())), |
4437 | _ => None, | 3249 | _ => None, |
4438 | } | 3250 | } |
4439 | } | 3251 | } |
4440 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3252 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3253 | fn to_owned(&self) -> TreePtr<UseTree> { TreePtr::cast(self.syntax.to_owned()) } | ||
4441 | } | 3254 | } |
4442 | 3255 | ||
4443 | impl<R: TreeRoot<RaTypes>> UseTreeNode<R> { | ||
4444 | pub fn borrowed(&self) -> UseTree { | ||
4445 | UseTreeNode { syntax: self.syntax.borrowed() } | ||
4446 | } | ||
4447 | pub fn owned(&self) -> UseTreeNode { | ||
4448 | UseTreeNode { syntax: self.syntax.owned() } | ||
4449 | } | ||
4450 | } | ||
4451 | 3256 | ||
4452 | 3257 | impl UseTree { | |
4453 | impl<'a> UseTree<'a> { | 3258 | pub fn path(&self) -> Option<&Path> { |
4454 | pub fn path(self) -> Option<Path<'a>> { | ||
4455 | super::child_opt(self) | 3259 | super::child_opt(self) |
4456 | } | 3260 | } |
4457 | 3261 | ||
4458 | pub fn use_tree_list(self) -> Option<UseTreeList<'a>> { | 3262 | pub fn use_tree_list(&self) -> Option<&UseTreeList> { |
4459 | super::child_opt(self) | 3263 | super::child_opt(self) |
4460 | } | 3264 | } |
4461 | } | 3265 | } |
4462 | 3266 | ||
4463 | // UseTreeList | 3267 | // UseTreeList |
4464 | #[derive(Debug, Clone, Copy,)] | 3268 | #[derive(Debug, PartialEq, Eq, Hash)] |
4465 | pub struct UseTreeListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3269 | #[repr(transparent)] |
4466 | pub(crate) syntax: SyntaxNode<R>, | 3270 | pub struct UseTreeList { |
4467 | } | 3271 | pub(crate) syntax: SyntaxNode, |
4468 | pub type UseTreeList<'a> = UseTreeListNode<RefRoot<'a>>; | ||
4469 | |||
4470 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseTreeListNode<R1>> for UseTreeListNode<R2> { | ||
4471 | fn eq(&self, other: &UseTreeListNode<R1>) -> bool { self.syntax == other.syntax } | ||
4472 | } | 3272 | } |
4473 | impl<R: TreeRoot<RaTypes>> Eq for UseTreeListNode<R> {} | 3273 | unsafe impl TransparentNewType for UseTreeList { |
4474 | impl<R: TreeRoot<RaTypes>> Hash for UseTreeListNode<R> { | 3274 | type Repr = rowan::SyntaxNode<RaTypes>; |
4475 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4476 | } | 3275 | } |
4477 | 3276 | ||
4478 | impl<'a> AstNode<'a> for UseTreeList<'a> { | 3277 | impl AstNode for UseTreeList { |
4479 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3278 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4480 | match syntax.kind() { | 3279 | match syntax.kind() { |
4481 | USE_TREE_LIST => Some(UseTreeList { syntax }), | 3280 | USE_TREE_LIST => Some(UseTreeList::from_repr(syntax.into_repr())), |
4482 | _ => None, | 3281 | _ => None, |
4483 | } | 3282 | } |
4484 | } | 3283 | } |
4485 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3284 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4486 | } | 3285 | fn to_owned(&self) -> TreePtr<UseTreeList> { TreePtr::cast(self.syntax.to_owned()) } |
4487 | |||
4488 | impl<R: TreeRoot<RaTypes>> UseTreeListNode<R> { | ||
4489 | pub fn borrowed(&self) -> UseTreeList { | ||
4490 | UseTreeListNode { syntax: self.syntax.borrowed() } | ||
4491 | } | ||
4492 | pub fn owned(&self) -> UseTreeListNode { | ||
4493 | UseTreeListNode { syntax: self.syntax.owned() } | ||
4494 | } | ||
4495 | } | 3286 | } |
4496 | 3287 | ||
4497 | 3288 | ||
4498 | impl<'a> UseTreeList<'a> { | 3289 | impl UseTreeList { |
4499 | pub fn use_trees(self) -> impl Iterator<Item = UseTree<'a>> + 'a { | 3290 | pub fn use_trees(&self) -> impl Iterator<Item = &UseTree> { |
4500 | super::children(self) | 3291 | super::children(self) |
4501 | } | 3292 | } |
4502 | } | 3293 | } |
4503 | 3294 | ||
4504 | // Visibility | 3295 | // Visibility |
4505 | #[derive(Debug, Clone, Copy,)] | 3296 | #[derive(Debug, PartialEq, Eq, Hash)] |
4506 | pub struct VisibilityNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3297 | #[repr(transparent)] |
4507 | pub(crate) syntax: SyntaxNode<R>, | 3298 | pub struct Visibility { |
3299 | pub(crate) syntax: SyntaxNode, | ||
4508 | } | 3300 | } |
4509 | pub type Visibility<'a> = VisibilityNode<RefRoot<'a>>; | 3301 | unsafe impl TransparentNewType for Visibility { |
4510 | 3302 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4511 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<VisibilityNode<R1>> for VisibilityNode<R2> { | ||
4512 | fn eq(&self, other: &VisibilityNode<R1>) -> bool { self.syntax == other.syntax } | ||
4513 | } | ||
4514 | impl<R: TreeRoot<RaTypes>> Eq for VisibilityNode<R> {} | ||
4515 | impl<R: TreeRoot<RaTypes>> Hash for VisibilityNode<R> { | ||
4516 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4517 | } | 3303 | } |
4518 | 3304 | ||
4519 | impl<'a> AstNode<'a> for Visibility<'a> { | 3305 | impl AstNode for Visibility { |
4520 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3306 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4521 | match syntax.kind() { | 3307 | match syntax.kind() { |
4522 | VISIBILITY => Some(Visibility { syntax }), | 3308 | VISIBILITY => Some(Visibility::from_repr(syntax.into_repr())), |
4523 | _ => None, | 3309 | _ => None, |
4524 | } | 3310 | } |
4525 | } | 3311 | } |
4526 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3312 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4527 | } | 3313 | fn to_owned(&self) -> TreePtr<Visibility> { TreePtr::cast(self.syntax.to_owned()) } |
4528 | |||
4529 | impl<R: TreeRoot<RaTypes>> VisibilityNode<R> { | ||
4530 | pub fn borrowed(&self) -> Visibility { | ||
4531 | VisibilityNode { syntax: self.syntax.borrowed() } | ||
4532 | } | ||
4533 | pub fn owned(&self) -> VisibilityNode { | ||
4534 | VisibilityNode { syntax: self.syntax.owned() } | ||
4535 | } | ||
4536 | } | 3314 | } |
4537 | 3315 | ||
4538 | 3316 | ||
4539 | impl<'a> Visibility<'a> {} | 3317 | impl Visibility {} |
4540 | 3318 | ||
4541 | // WhereClause | 3319 | // WhereClause |
4542 | #[derive(Debug, Clone, Copy,)] | 3320 | #[derive(Debug, PartialEq, Eq, Hash)] |
4543 | pub struct WhereClauseNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3321 | #[repr(transparent)] |
4544 | pub(crate) syntax: SyntaxNode<R>, | 3322 | pub struct WhereClause { |
3323 | pub(crate) syntax: SyntaxNode, | ||
4545 | } | 3324 | } |
4546 | pub type WhereClause<'a> = WhereClauseNode<RefRoot<'a>>; | 3325 | unsafe impl TransparentNewType for WhereClause { |
4547 | 3326 | type Repr = rowan::SyntaxNode<RaTypes>; | |
4548 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhereClauseNode<R1>> for WhereClauseNode<R2> { | ||
4549 | fn eq(&self, other: &WhereClauseNode<R1>) -> bool { self.syntax == other.syntax } | ||
4550 | } | ||
4551 | impl<R: TreeRoot<RaTypes>> Eq for WhereClauseNode<R> {} | ||
4552 | impl<R: TreeRoot<RaTypes>> Hash for WhereClauseNode<R> { | ||
4553 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4554 | } | 3327 | } |
4555 | 3328 | ||
4556 | impl<'a> AstNode<'a> for WhereClause<'a> { | 3329 | impl AstNode for WhereClause { |
4557 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3330 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4558 | match syntax.kind() { | 3331 | match syntax.kind() { |
4559 | WHERE_CLAUSE => Some(WhereClause { syntax }), | 3332 | WHERE_CLAUSE => Some(WhereClause::from_repr(syntax.into_repr())), |
4560 | _ => None, | 3333 | _ => None, |
4561 | } | 3334 | } |
4562 | } | 3335 | } |
4563 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3336 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4564 | } | 3337 | fn to_owned(&self) -> TreePtr<WhereClause> { TreePtr::cast(self.syntax.to_owned()) } |
4565 | |||
4566 | impl<R: TreeRoot<RaTypes>> WhereClauseNode<R> { | ||
4567 | pub fn borrowed(&self) -> WhereClause { | ||
4568 | WhereClauseNode { syntax: self.syntax.borrowed() } | ||
4569 | } | ||
4570 | pub fn owned(&self) -> WhereClauseNode { | ||
4571 | WhereClauseNode { syntax: self.syntax.owned() } | ||
4572 | } | ||
4573 | } | 3338 | } |
4574 | 3339 | ||
4575 | 3340 | ||
4576 | impl<'a> WhereClause<'a> {} | 3341 | impl WhereClause {} |
4577 | 3342 | ||
4578 | // WhileExpr | 3343 | // WhileExpr |
4579 | #[derive(Debug, Clone, Copy,)] | 3344 | #[derive(Debug, PartialEq, Eq, Hash)] |
4580 | pub struct WhileExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3345 | #[repr(transparent)] |
4581 | pub(crate) syntax: SyntaxNode<R>, | 3346 | pub struct WhileExpr { |
4582 | } | 3347 | pub(crate) syntax: SyntaxNode, |
4583 | pub type WhileExpr<'a> = WhileExprNode<RefRoot<'a>>; | ||
4584 | |||
4585 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhileExprNode<R1>> for WhileExprNode<R2> { | ||
4586 | fn eq(&self, other: &WhileExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
4587 | } | 3348 | } |
4588 | impl<R: TreeRoot<RaTypes>> Eq for WhileExprNode<R> {} | 3349 | unsafe impl TransparentNewType for WhileExpr { |
4589 | impl<R: TreeRoot<RaTypes>> Hash for WhileExprNode<R> { | 3350 | type Repr = rowan::SyntaxNode<RaTypes>; |
4590 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4591 | } | 3351 | } |
4592 | 3352 | ||
4593 | impl<'a> AstNode<'a> for WhileExpr<'a> { | 3353 | impl AstNode for WhileExpr { |
4594 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3354 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4595 | match syntax.kind() { | 3355 | match syntax.kind() { |
4596 | WHILE_EXPR => Some(WhileExpr { syntax }), | 3356 | WHILE_EXPR => Some(WhileExpr::from_repr(syntax.into_repr())), |
4597 | _ => None, | 3357 | _ => None, |
4598 | } | 3358 | } |
4599 | } | 3359 | } |
4600 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3360 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3361 | fn to_owned(&self) -> TreePtr<WhileExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
4601 | } | 3362 | } |
4602 | 3363 | ||
4603 | impl<R: TreeRoot<RaTypes>> WhileExprNode<R> { | ||
4604 | pub fn borrowed(&self) -> WhileExpr { | ||
4605 | WhileExprNode { syntax: self.syntax.borrowed() } | ||
4606 | } | ||
4607 | pub fn owned(&self) -> WhileExprNode { | ||
4608 | WhileExprNode { syntax: self.syntax.owned() } | ||
4609 | } | ||
4610 | } | ||
4611 | 3364 | ||
4612 | 3365 | impl ast::LoopBodyOwner for WhileExpr {} | |
4613 | impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} | 3366 | impl WhileExpr { |
4614 | impl<'a> WhileExpr<'a> { | 3367 | pub fn condition(&self) -> Option<&Condition> { |
4615 | pub fn condition(self) -> Option<Condition<'a>> { | ||
4616 | super::child_opt(self) | 3368 | super::child_opt(self) |
4617 | } | 3369 | } |
4618 | } | 3370 | } |
4619 | 3371 | ||
4620 | // Whitespace | 3372 | // Whitespace |
4621 | #[derive(Debug, Clone, Copy,)] | 3373 | #[derive(Debug, PartialEq, Eq, Hash)] |
4622 | pub struct WhitespaceNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3374 | #[repr(transparent)] |
4623 | pub(crate) syntax: SyntaxNode<R>, | 3375 | pub struct Whitespace { |
4624 | } | 3376 | pub(crate) syntax: SyntaxNode, |
4625 | pub type Whitespace<'a> = WhitespaceNode<RefRoot<'a>>; | ||
4626 | |||
4627 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhitespaceNode<R1>> for WhitespaceNode<R2> { | ||
4628 | fn eq(&self, other: &WhitespaceNode<R1>) -> bool { self.syntax == other.syntax } | ||
4629 | } | 3377 | } |
4630 | impl<R: TreeRoot<RaTypes>> Eq for WhitespaceNode<R> {} | 3378 | unsafe impl TransparentNewType for Whitespace { |
4631 | impl<R: TreeRoot<RaTypes>> Hash for WhitespaceNode<R> { | 3379 | type Repr = rowan::SyntaxNode<RaTypes>; |
4632 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4633 | } | 3380 | } |
4634 | 3381 | ||
4635 | impl<'a> AstNode<'a> for Whitespace<'a> { | 3382 | impl AstNode for Whitespace { |
4636 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3383 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4637 | match syntax.kind() { | 3384 | match syntax.kind() { |
4638 | WHITESPACE => Some(Whitespace { syntax }), | 3385 | WHITESPACE => Some(Whitespace::from_repr(syntax.into_repr())), |
4639 | _ => None, | 3386 | _ => None, |
4640 | } | 3387 | } |
4641 | } | 3388 | } |
4642 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3389 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4643 | } | 3390 | fn to_owned(&self) -> TreePtr<Whitespace> { TreePtr::cast(self.syntax.to_owned()) } |
4644 | |||
4645 | impl<R: TreeRoot<RaTypes>> WhitespaceNode<R> { | ||
4646 | pub fn borrowed(&self) -> Whitespace { | ||
4647 | WhitespaceNode { syntax: self.syntax.borrowed() } | ||
4648 | } | ||
4649 | pub fn owned(&self) -> WhitespaceNode { | ||
4650 | WhitespaceNode { syntax: self.syntax.owned() } | ||
4651 | } | ||
4652 | } | 3391 | } |
4653 | 3392 | ||
4654 | 3393 | ||
4655 | impl<'a> Whitespace<'a> {} | 3394 | impl Whitespace {} |
4656 | 3395 | ||
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera index 131ee09ec..0a20fc78e 100644 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ b/crates/ra_syntax/src/ast/generated.rs.tera | |||
@@ -11,89 +11,92 @@ the below applies to the result of this template | |||
11 | 11 | ||
12 | #![cfg_attr(rustfmt, rustfmt_skip)] | 12 | #![cfg_attr(rustfmt, rustfmt_skip)] |
13 | 13 | ||
14 | use std::hash::{Hash, Hasher}; | 14 | use rowan::TransparentNewType; |
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
17 | ast, | 17 | SyntaxNode, SyntaxKind::*, |
18 | SyntaxNode, SyntaxNodeRef, AstNode, | 18 | yellow::{RaTypes, TreePtr}, |
19 | yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot}, | 19 | ast::{self, AstNode}, |
20 | SyntaxKind::*, | ||
21 | }; | 20 | }; |
22 | {% for node, methods in ast %} | 21 | {% for node, methods in ast %} |
23 | // {{ node }} | 22 | // {{ node }} |
24 | 23 | ||
25 | {%- if methods.enum %} | 24 | {%- if methods.enum %} |
25 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
26 | #[repr(transparent)] | ||
27 | pub struct {{ node }} { | ||
28 | pub(crate) syntax: SyntaxNode, | ||
29 | } | ||
30 | unsafe impl TransparentNewType for {{ node }} { | ||
31 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
32 | } | ||
33 | |||
26 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 34 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
27 | pub enum {{ node }}<'a> { | 35 | pub enum {{ node }}Kind<'a> { |
28 | {%- for kind in methods.enum %} | 36 | {%- for kind in methods.enum %} |
29 | {{ kind }}({{ kind }}<'a>), | 37 | {{ kind }}(&'a {{ kind }}), |
30 | {%- endfor %} | 38 | {%- endfor %} |
31 | } | 39 | } |
32 | 40 | ||
33 | impl<'a> AstNode<'a> for {{ node }}<'a> { | 41 | impl AstNode for {{ node }} { |
34 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 42 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
35 | match syntax.kind() { | 43 | match syntax.kind() { |
36 | {%- for kind in methods.enum %} | 44 | {%- for kind in methods.enum %} |
37 | {{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })), | 45 | | {{ kind | SCREAM }} |
38 | {%- endfor %} | 46 | {%- endfor %} => Some({{ node }}::from_repr(syntax.into_repr())), |
39 | _ => None, | 47 | _ => None, |
40 | } | 48 | } |
41 | } | 49 | } |
42 | fn syntax(self) -> SyntaxNodeRef<'a> { | 50 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
43 | match self { | 51 | fn to_owned(&self) -> TreePtr<{{ node }}> { TreePtr::cast(self.syntax.to_owned()) } |
44 | {%- for kind in methods.enum %} | 52 | } |
45 | {{ node }}::{{ kind }}(inner) => inner.syntax(), | 53 | |
46 | {%- endfor %} | 54 | impl {{ node }} { |
55 | pub fn kind(&self) -> {{ node }}Kind { | ||
56 | match self.syntax.kind() { | ||
57 | {%- for kind in methods.enum %} | ||
58 | {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(&self.syntax).unwrap()), | ||
59 | {%- endfor %} | ||
60 | _ => unreachable!(), | ||
47 | } | 61 | } |
48 | } | 62 | } |
49 | } | 63 | } |
50 | {% else %} | 64 | {% else %} |
51 | #[derive(Debug, Clone, Copy,)] | 65 | #[derive(Debug, PartialEq, Eq, Hash)] |
52 | pub struct {{ node }}Node<R: TreeRoot<RaTypes> = OwnedRoot> { | 66 | #[repr(transparent)] |
53 | pub(crate) syntax: SyntaxNode<R>, | 67 | pub struct {{ node }} { |
68 | pub(crate) syntax: SyntaxNode, | ||
54 | } | 69 | } |
55 | pub type {{ node }}<'a> = {{ node }}Node<RefRoot<'a>>; | 70 | unsafe impl TransparentNewType for {{ node }} { |
56 | 71 | type Repr = rowan::SyntaxNode<RaTypes>; | |
57 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<{{node}}Node<R1>> for {{node}}Node<R2> { | ||
58 | fn eq(&self, other: &{{node}}Node<R1>) -> bool { self.syntax == other.syntax } | ||
59 | } | ||
60 | impl<R: TreeRoot<RaTypes>> Eq for {{node}}Node<R> {} | ||
61 | impl<R: TreeRoot<RaTypes>> Hash for {{node}}Node<R> { | ||
62 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
63 | } | 72 | } |
64 | 73 | ||
65 | impl<'a> AstNode<'a> for {{ node }}<'a> { | 74 | impl AstNode for {{ node }} { |
66 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 75 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
67 | match syntax.kind() { | 76 | match syntax.kind() { |
68 | {{ node | SCREAM }} => Some({{ node }} { syntax }), | 77 | {{ node | SCREAM }} => Some({{ node }}::from_repr(syntax.into_repr())), |
69 | _ => None, | 78 | _ => None, |
70 | } | 79 | } |
71 | } | 80 | } |
72 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 81 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
73 | } | 82 | fn to_owned(&self) -> TreePtr<{{ node }}> { TreePtr::cast(self.syntax.to_owned()) } |
74 | |||
75 | impl<R: TreeRoot<RaTypes>> {{ node }}Node<R> { | ||
76 | pub fn borrowed(&self) -> {{ node }} { | ||
77 | {{ node }}Node { syntax: self.syntax.borrowed() } | ||
78 | } | ||
79 | pub fn owned(&self) -> {{ node }}Node { | ||
80 | {{ node }}Node { syntax: self.syntax.owned() } | ||
81 | } | ||
82 | } | 83 | } |
83 | 84 | ||
84 | {% endif %} | 85 | {% endif %} |
85 | {% if methods.traits -%} | 86 | {% if methods.traits -%} |
87 | |||
86 | {%- for t in methods.traits -%} | 88 | {%- for t in methods.traits -%} |
87 | impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {} | 89 | impl ast::{{ t }} for {{ node }} {} |
88 | {% endfor -%} | 90 | {% endfor -%} |
91 | |||
89 | {%- endif -%} | 92 | {%- endif -%} |
90 | 93 | ||
91 | impl<'a> {{ node }}<'a> { | 94 | impl {{ node }} { |
92 | {%- if methods.collections -%} | 95 | {%- if methods.collections -%} |
93 | {%- for m in methods.collections -%} | 96 | {%- for m in methods.collections -%} |
94 | {%- set method_name = m.0 -%} | 97 | {%- set method_name = m.0 -%} |
95 | {%- set ChildName = m.1 %} | 98 | {%- set ChildName = m.1 %} |
96 | pub fn {{ method_name }}(self) -> impl Iterator<Item = {{ ChildName }}<'a>> + 'a { | 99 | pub fn {{ method_name }}(&self) -> impl Iterator<Item = &{{ ChildName }}> { |
97 | super::children(self) | 100 | super::children(self) |
98 | } | 101 | } |
99 | {% endfor -%} | 102 | {% endfor -%} |
@@ -109,7 +112,7 @@ impl<'a> {{ node }}<'a> { | |||
109 | {%- set method_name = m.0 -%} | 112 | {%- set method_name = m.0 -%} |
110 | {%- set ChildName = m.1 %} | 113 | {%- set ChildName = m.1 %} |
111 | {%- endif %} | 114 | {%- endif %} |
112 | pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> { | 115 | pub fn {{ method_name }}(&self) -> Option<&{{ ChildName }}> { |
113 | super::child_opt(self) | 116 | super::child_opt(self) |
114 | } | 117 | } |
115 | {% endfor -%} | 118 | {% endfor -%} |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 6753c513f..a75e641ea 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -42,52 +42,42 @@ pub use crate::{ | |||
42 | ast::AstNode, | 42 | ast::AstNode, |
43 | lexer::{tokenize, Token}, | 43 | lexer::{tokenize, Token}, |
44 | syntax_kinds::SyntaxKind, | 44 | syntax_kinds::SyntaxKind, |
45 | yellow::{ | 45 | yellow::{Direction, SyntaxError, SyntaxNode, WalkEvent, Location, TreePtr}, |
46 | Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location, | ||
47 | }, | ||
48 | }; | 46 | }; |
49 | 47 | ||
50 | use ra_text_edit::AtomTextEdit; | 48 | use ra_text_edit::AtomTextEdit; |
51 | use crate::yellow::GreenNode; | 49 | use crate::yellow::GreenNode; |
52 | 50 | ||
53 | /// `SourceFileNode` represents a parse tree for a single Rust file. | 51 | /// `SourceFile` represents a parse tree for a single Rust file. |
54 | pub use crate::ast::{SourceFile, SourceFileNode}; | 52 | pub use crate::ast::SourceFile; |
55 | 53 | ||
56 | impl SourceFileNode { | 54 | impl SourceFile { |
57 | fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode { | 55 | fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SourceFile> { |
58 | let root = SyntaxNode::new(green, errors); | 56 | let root = SyntaxNode::new(green, errors); |
59 | if cfg!(debug_assertions) { | 57 | if cfg!(debug_assertions) { |
60 | utils::validate_block_structure(root.borrowed()); | 58 | utils::validate_block_structure(&root); |
61 | } | 59 | } |
62 | assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); | 60 | assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); |
63 | ast::SourceFileNode { syntax: root } | 61 | TreePtr::cast(root) |
64 | } | 62 | } |
65 | pub fn parse(text: &str) -> SourceFileNode { | 63 | pub fn parse(text: &str) -> TreePtr<SourceFile> { |
66 | let tokens = tokenize(&text); | 64 | let tokens = tokenize(&text); |
67 | let (green, errors) = | 65 | let (green, errors) = |
68 | parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); | 66 | parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); |
69 | SourceFileNode::new(green, errors) | 67 | SourceFile::new(green, errors) |
70 | } | 68 | } |
71 | pub fn reparse(&self, edit: &AtomTextEdit) -> SourceFileNode { | 69 | pub fn reparse(&self, edit: &AtomTextEdit) -> TreePtr<SourceFile> { |
72 | self.incremental_reparse(edit) | 70 | self.incremental_reparse(edit) |
73 | .unwrap_or_else(|| self.full_reparse(edit)) | 71 | .unwrap_or_else(|| self.full_reparse(edit)) |
74 | } | 72 | } |
75 | pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<SourceFileNode> { | 73 | pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<TreePtr<SourceFile>> { |
76 | reparsing::incremental_reparse(self.syntax(), edit, self.errors()) | 74 | reparsing::incremental_reparse(self.syntax(), edit, self.errors()) |
77 | .map(|(green_node, errors)| SourceFileNode::new(green_node, errors)) | 75 | .map(|(green_node, errors)| SourceFile::new(green_node, errors)) |
78 | } | 76 | } |
79 | fn full_reparse(&self, edit: &AtomTextEdit) -> SourceFileNode { | 77 | fn full_reparse(&self, edit: &AtomTextEdit) -> TreePtr<SourceFile> { |
80 | let text = | 78 | let text = |
81 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); | 79 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); |
82 | SourceFileNode::parse(&text) | 80 | SourceFile::parse(&text) |
83 | } | ||
84 | /// Typed AST representation of the parse tree. | ||
85 | pub fn ast(&self) -> ast::SourceFile { | ||
86 | self.borrowed() | ||
87 | } | ||
88 | /// Untyped homogeneous representation of the parse tree. | ||
89 | pub fn syntax(&self) -> SyntaxNodeRef { | ||
90 | self.syntax.borrowed() | ||
91 | } | 81 | } |
92 | pub fn errors(&self) -> Vec<SyntaxError> { | 82 | pub fn errors(&self) -> Vec<SyntaxError> { |
93 | let mut errors = self.syntax.root_data().clone(); | 83 | let mut errors = self.syntax.root_data().clone(); |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 7ee71a1b6..d5d72e1f8 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -4,12 +4,12 @@ use crate::lexer::{tokenize, Token}; | |||
4 | use crate::parser_api::Parser; | 4 | use crate::parser_api::Parser; |
5 | use crate::parser_impl; | 5 | use crate::parser_impl; |
6 | use crate::text_utils::replace_range; | 6 | use crate::text_utils::replace_range; |
7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; | 7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNode}; |
8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; | 8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; |
9 | use ra_text_edit::AtomTextEdit; | 9 | use ra_text_edit::AtomTextEdit; |
10 | 10 | ||
11 | pub(crate) fn incremental_reparse( | 11 | pub(crate) fn incremental_reparse( |
12 | node: SyntaxNodeRef, | 12 | node: &SyntaxNode, |
13 | edit: &AtomTextEdit, | 13 | edit: &AtomTextEdit, |
14 | errors: Vec<SyntaxError>, | 14 | errors: Vec<SyntaxError>, |
15 | ) -> Option<(GreenNode, Vec<SyntaxError>)> { | 15 | ) -> Option<(GreenNode, Vec<SyntaxError>)> { |
@@ -21,9 +21,9 @@ pub(crate) fn incremental_reparse( | |||
21 | } | 21 | } |
22 | 22 | ||
23 | fn reparse_leaf<'node>( | 23 | fn reparse_leaf<'node>( |
24 | node: SyntaxNodeRef<'node>, | 24 | node: &'node SyntaxNode, |
25 | edit: &AtomTextEdit, | 25 | edit: &AtomTextEdit, |
26 | ) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> { | 26 | ) -> Option<(&'node SyntaxNode, GreenNode, Vec<SyntaxError>)> { |
27 | let node = algo::find_covering_node(node, edit.delete); | 27 | let node = algo::find_covering_node(node, edit.delete); |
28 | match node.kind() { | 28 | match node.kind() { |
29 | WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { | 29 | WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { |
@@ -47,9 +47,9 @@ fn reparse_leaf<'node>( | |||
47 | } | 47 | } |
48 | 48 | ||
49 | fn reparse_block<'node>( | 49 | fn reparse_block<'node>( |
50 | node: SyntaxNodeRef<'node>, | 50 | node: &'node SyntaxNode, |
51 | edit: &AtomTextEdit, | 51 | edit: &AtomTextEdit, |
52 | ) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> { | 52 | ) -> Option<(&'node SyntaxNode, GreenNode, Vec<SyntaxError>)> { |
53 | let (node, reparser) = find_reparsable_node(node, edit.delete)?; | 53 | let (node, reparser) = find_reparsable_node(node, edit.delete)?; |
54 | let text = get_text_after_edit(node, &edit); | 54 | let text = get_text_after_edit(node, &edit); |
55 | let tokens = tokenize(&text); | 55 | let tokens = tokenize(&text); |
@@ -61,7 +61,7 @@ fn reparse_block<'node>( | |||
61 | Some((node, green, new_errors)) | 61 | Some((node, green, new_errors)) |
62 | } | 62 | } |
63 | 63 | ||
64 | fn get_text_after_edit(node: SyntaxNodeRef, edit: &AtomTextEdit) -> String { | 64 | fn get_text_after_edit(node: &SyntaxNode, edit: &AtomTextEdit) -> String { |
65 | replace_range( | 65 | replace_range( |
66 | node.text().to_string(), | 66 | node.text().to_string(), |
67 | edit.delete - node.range().start(), | 67 | edit.delete - node.range().start(), |
@@ -77,17 +77,14 @@ fn is_contextual_kw(text: &str) -> bool { | |||
77 | } | 77 | } |
78 | 78 | ||
79 | type ParseFn = fn(&mut Parser); | 79 | type ParseFn = fn(&mut Parser); |
80 | fn find_reparsable_node( | 80 | fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, ParseFn)> { |
81 | node: SyntaxNodeRef<'_>, | ||
82 | range: TextRange, | ||
83 | ) -> Option<(SyntaxNodeRef<'_>, ParseFn)> { | ||
84 | let node = algo::find_covering_node(node, range); | 81 | let node = algo::find_covering_node(node, range); |
85 | return node | 82 | return node |
86 | .ancestors() | 83 | .ancestors() |
87 | .filter_map(|node| reparser(node).map(|r| (node, r))) | 84 | .filter_map(|node| reparser(node).map(|r| (node, r))) |
88 | .next(); | 85 | .next(); |
89 | 86 | ||
90 | fn reparser(node: SyntaxNodeRef) -> Option<ParseFn> { | 87 | fn reparser(node: &SyntaxNode) -> Option<ParseFn> { |
91 | let res = match node.kind() { | 88 | let res = match node.kind() { |
92 | BLOCK => grammar::block, | 89 | BLOCK => grammar::block, |
93 | NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, | 90 | NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, |
@@ -138,7 +135,7 @@ fn is_balanced(tokens: &[Token]) -> bool { | |||
138 | fn merge_errors( | 135 | fn merge_errors( |
139 | old_errors: Vec<SyntaxError>, | 136 | old_errors: Vec<SyntaxError>, |
140 | new_errors: Vec<SyntaxError>, | 137 | new_errors: Vec<SyntaxError>, |
141 | old_node: SyntaxNodeRef, | 138 | old_node: &SyntaxNode, |
142 | edit: &AtomTextEdit, | 139 | edit: &AtomTextEdit, |
143 | ) -> Vec<SyntaxError> { | 140 | ) -> Vec<SyntaxError> { |
144 | let mut res = Vec::new(); | 141 | let mut res = Vec::new(); |
@@ -159,22 +156,22 @@ fn merge_errors( | |||
159 | mod tests { | 156 | mod tests { |
160 | use test_utils::{extract_range, assert_eq_text}; | 157 | use test_utils::{extract_range, assert_eq_text}; |
161 | 158 | ||
162 | use crate::{SourceFileNode, text_utils::replace_range, utils::dump_tree }; | 159 | use crate::{SourceFile, AstNode, text_utils::replace_range, utils::dump_tree}; |
163 | use super::*; | 160 | use super::*; |
164 | 161 | ||
165 | fn do_check<F>(before: &str, replace_with: &str, reparser: F) | 162 | fn do_check<F>(before: &str, replace_with: &str, reparser: F) |
166 | where | 163 | where |
167 | for<'a> F: Fn( | 164 | for<'a> F: Fn( |
168 | SyntaxNodeRef<'a>, | 165 | &'a SyntaxNode, |
169 | &AtomTextEdit, | 166 | &AtomTextEdit, |
170 | ) -> Option<(SyntaxNodeRef<'a>, GreenNode, Vec<SyntaxError>)>, | 167 | ) -> Option<(&'a SyntaxNode, GreenNode, Vec<SyntaxError>)>, |
171 | { | 168 | { |
172 | let (range, before) = extract_range(before); | 169 | let (range, before) = extract_range(before); |
173 | let after = replace_range(before.clone(), range, replace_with); | 170 | let after = replace_range(before.clone(), range, replace_with); |
174 | 171 | ||
175 | let fully_reparsed = SourceFileNode::parse(&after); | 172 | let fully_reparsed = SourceFile::parse(&after); |
176 | let incrementally_reparsed = { | 173 | let incrementally_reparsed = { |
177 | let f = SourceFileNode::parse(&before); | 174 | let f = SourceFile::parse(&before); |
178 | let edit = AtomTextEdit { | 175 | let edit = AtomTextEdit { |
179 | delete: range, | 176 | delete: range, |
180 | insert: replace_with.to_string(), | 177 | insert: replace_with.to_string(), |
@@ -183,7 +180,7 @@ mod tests { | |||
183 | reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); | 180 | reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); |
184 | let green_root = node.replace_with(green); | 181 | let green_root = node.replace_with(green); |
185 | let errors = super::merge_errors(f.errors(), new_errors, node, &edit); | 182 | let errors = super::merge_errors(f.errors(), new_errors, node, &edit); |
186 | SourceFileNode::new(green_root, errors) | 183 | SourceFile::new(green_root, errors) |
187 | }; | 184 | }; |
188 | 185 | ||
189 | assert_eq_text!( | 186 | assert_eq_text!( |
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 0a2b6afbc..2e1b42da0 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs | |||
@@ -1,11 +1,11 @@ | |||
1 | use crate::{SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent, AstNode}; | 1 | use std::{str, fmt::Write}; |
2 | use std::fmt::Write; | 2 | |
3 | use std::str; | 3 | use crate::{SourceFile, SyntaxKind, WalkEvent, AstNode, SyntaxNode}; |
4 | 4 | ||
5 | /// Parse a file and create a string representation of the resulting parse tree. | 5 | /// Parse a file and create a string representation of the resulting parse tree. |
6 | pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | 6 | pub fn dump_tree(syntax: &SyntaxNode) -> String { |
7 | let mut errors: Vec<_> = match syntax.ancestors().find_map(SourceFileNode::cast) { | 7 | let mut errors: Vec<_> = match syntax.ancestors().find_map(SourceFile::cast) { |
8 | Some(file) => file.owned().errors(), | 8 | Some(file) => file.errors(), |
9 | None => syntax.root_data().to_vec(), | 9 | None => syntax.root_data().to_vec(), |
10 | }; | 10 | }; |
11 | errors.sort_by_key(|e| e.offset()); | 11 | errors.sort_by_key(|e| e.offset()); |
@@ -48,14 +48,13 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | pub fn check_fuzz_invariants(text: &str) { | 50 | pub fn check_fuzz_invariants(text: &str) { |
51 | let file = SourceFileNode::parse(text); | 51 | let file = SourceFile::parse(text); |
52 | let root = file.syntax(); | 52 | let root = file.syntax(); |
53 | validate_block_structure(root); | 53 | validate_block_structure(root); |
54 | let _ = file.ast(); | ||
55 | let _ = file.errors(); | 54 | let _ = file.errors(); |
56 | } | 55 | } |
57 | 56 | ||
58 | pub(crate) fn validate_block_structure(root: SyntaxNodeRef) { | 57 | pub(crate) fn validate_block_structure(root: &SyntaxNode) { |
59 | let mut stack = Vec::new(); | 58 | let mut stack = Vec::new(); |
60 | for node in root.descendants() { | 59 | for node in root.descendants() { |
61 | match node.kind() { | 60 | match node.kind() { |
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index bdee8120c..73e1d20b9 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs | |||
@@ -1,16 +1,15 @@ | |||
1 | use crate::{ | ||
2 | algo::visit::{visitor_ctx, VisitorCtx}, | ||
3 | ast, | ||
4 | SourceFileNode, | ||
5 | yellow::SyntaxError, | ||
6 | }; | ||
7 | |||
8 | mod byte; | 1 | mod byte; |
9 | mod byte_string; | 2 | mod byte_string; |
10 | mod char; | 3 | mod char; |
11 | mod string; | 4 | mod string; |
12 | 5 | ||
13 | pub(crate) fn validate(file: &SourceFileNode) -> Vec<SyntaxError> { | 6 | use crate::{ |
7 | SourceFile, yellow::SyntaxError, AstNode, | ||
8 | ast, | ||
9 | algo::visit::{visitor_ctx, VisitorCtx}, | ||
10 | }; | ||
11 | |||
12 | pub(crate) fn validate(file: &SourceFile) -> Vec<SyntaxError> { | ||
14 | let mut errors = Vec::new(); | 13 | let mut errors = Vec::new(); |
15 | for node in file.syntax().descendants() { | 14 | for node in file.syntax().descendants() { |
16 | let _ = visitor_ctx(&mut errors) | 15 | let _ = visitor_ctx(&mut errors) |
diff --git a/crates/ra_syntax/src/validation/byte.rs b/crates/ra_syntax/src/validation/byte.rs index 714224b09..4deb302a7 100644 --- a/crates/ra_syntax/src/validation/byte.rs +++ b/crates/ra_syntax/src/validation/byte.rs | |||
@@ -11,7 +11,7 @@ use crate::{ | |||
11 | }, | 11 | }, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | pub(super) fn validate_byte_node(node: ast::Byte, errors: &mut Vec<SyntaxError>) { | 14 | pub(super) fn validate_byte_node(node: &ast::Byte, errors: &mut Vec<SyntaxError>) { |
15 | let literal_text = node.text(); | 15 | let literal_text = node.text(); |
16 | let literal_range = node.syntax().range(); | 16 | let literal_range = node.syntax().range(); |
17 | let mut components = string_lexing::parse_byte_literal(literal_text); | 17 | let mut components = string_lexing::parse_byte_literal(literal_text); |
@@ -106,11 +106,11 @@ fn validate_byte_code_escape(text: &str, range: TextRange, errors: &mut Vec<Synt | |||
106 | 106 | ||
107 | #[cfg(test)] | 107 | #[cfg(test)] |
108 | mod test { | 108 | mod test { |
109 | use crate::SourceFileNode; | 109 | use crate::{SourceFile, TreePtr}; |
110 | 110 | ||
111 | fn build_file(literal: &str) -> SourceFileNode { | 111 | fn build_file(literal: &str) -> TreePtr<SourceFile> { |
112 | let src = format!("const C: u8 = b'{}';", literal); | 112 | let src = format!("const C: u8 = b'{}';", literal); |
113 | SourceFileNode::parse(&src) | 113 | SourceFile::parse(&src) |
114 | } | 114 | } |
115 | 115 | ||
116 | fn assert_valid_byte(literal: &str) { | 116 | fn assert_valid_byte(literal: &str) { |
diff --git a/crates/ra_syntax/src/validation/byte_string.rs b/crates/ra_syntax/src/validation/byte_string.rs index f7a4fb156..670c43a09 100644 --- a/crates/ra_syntax/src/validation/byte_string.rs +++ b/crates/ra_syntax/src/validation/byte_string.rs | |||
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | 9 | ||
10 | use super::byte; | 10 | use super::byte; |
11 | 11 | ||
12 | pub(crate) fn validate_byte_string_node(node: ast::ByteString, errors: &mut Vec<SyntaxError>) { | 12 | pub(crate) fn validate_byte_string_node(node: &ast::ByteString, errors: &mut Vec<SyntaxError>) { |
13 | let literal_text = node.text(); | 13 | let literal_text = node.text(); |
14 | let literal_range = node.syntax().range(); | 14 | let literal_range = node.syntax().range(); |
15 | let mut components = string_lexing::parse_byte_string_literal(literal_text); | 15 | let mut components = string_lexing::parse_byte_string_literal(literal_text); |
@@ -43,12 +43,12 @@ pub(crate) fn validate_byte_string_node(node: ast::ByteString, errors: &mut Vec< | |||
43 | 43 | ||
44 | #[cfg(test)] | 44 | #[cfg(test)] |
45 | mod test { | 45 | mod test { |
46 | use crate::SourceFileNode; | 46 | use crate::{SourceFile, TreePtr}; |
47 | 47 | ||
48 | fn build_file(literal: &str) -> SourceFileNode { | 48 | fn build_file(literal: &str) -> TreePtr<SourceFile> { |
49 | let src = format!(r#"const S: &'static [u8] = b"{}";"#, literal); | 49 | let src = format!(r#"const S: &'static [u8] = b"{}";"#, literal); |
50 | println!("Source: {}", src); | 50 | println!("Source: {}", src); |
51 | SourceFileNode::parse(&src) | 51 | SourceFile::parse(&src) |
52 | } | 52 | } |
53 | 53 | ||
54 | fn assert_valid_str(literal: &str) { | 54 | fn assert_valid_str(literal: &str) { |
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index 1d6fe8837..9cbd43fba 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs | |||
@@ -14,7 +14,7 @@ use crate::{ | |||
14 | }, | 14 | }, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | pub(super) fn validate_char_node(node: ast::Char, errors: &mut Vec<SyntaxError>) { | 17 | pub(super) fn validate_char_node(node: &ast::Char, errors: &mut Vec<SyntaxError>) { |
18 | let literal_text = node.text(); | 18 | let literal_text = node.text(); |
19 | let literal_range = node.syntax().range(); | 19 | let literal_range = node.syntax().range(); |
20 | let mut components = string_lexing::parse_char_literal(literal_text); | 20 | let mut components = string_lexing::parse_char_literal(literal_text); |
@@ -175,11 +175,11 @@ fn validate_unicode_escape(text: &str, range: TextRange, errors: &mut Vec<Syntax | |||
175 | 175 | ||
176 | #[cfg(test)] | 176 | #[cfg(test)] |
177 | mod test { | 177 | mod test { |
178 | use crate::SourceFileNode; | 178 | use crate::{SourceFile, TreePtr}; |
179 | 179 | ||
180 | fn build_file(literal: &str) -> SourceFileNode { | 180 | fn build_file(literal: &str) -> TreePtr<SourceFile> { |
181 | let src = format!("const C: char = '{}';", literal); | 181 | let src = format!("const C: char = '{}';", literal); |
182 | SourceFileNode::parse(&src) | 182 | SourceFile::parse(&src) |
183 | } | 183 | } |
184 | 184 | ||
185 | fn assert_valid_char(literal: &str) { | 185 | fn assert_valid_char(literal: &str) { |
diff --git a/crates/ra_syntax/src/validation/string.rs b/crates/ra_syntax/src/validation/string.rs index 1371bb1f0..7b2a68d12 100644 --- a/crates/ra_syntax/src/validation/string.rs +++ b/crates/ra_syntax/src/validation/string.rs | |||
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | 9 | ||
10 | use super::char; | 10 | use super::char; |
11 | 11 | ||
12 | pub(crate) fn validate_string_node(node: ast::String, errors: &mut Vec<SyntaxError>) { | 12 | pub(crate) fn validate_string_node(node: &ast::String, errors: &mut Vec<SyntaxError>) { |
13 | let literal_text = node.text(); | 13 | let literal_text = node.text(); |
14 | let literal_range = node.syntax().range(); | 14 | let literal_range = node.syntax().range(); |
15 | let mut components = string_lexing::parse_string_literal(literal_text); | 15 | let mut components = string_lexing::parse_string_literal(literal_text); |
@@ -38,12 +38,12 @@ pub(crate) fn validate_string_node(node: ast::String, errors: &mut Vec<SyntaxErr | |||
38 | 38 | ||
39 | #[cfg(test)] | 39 | #[cfg(test)] |
40 | mod test { | 40 | mod test { |
41 | use crate::SourceFileNode; | 41 | use crate::{SourceFile, TreePtr}; |
42 | 42 | ||
43 | fn build_file(literal: &str) -> SourceFileNode { | 43 | fn build_file(literal: &str) -> TreePtr<SourceFile> { |
44 | let src = format!(r#"const S: &'static str = "{}";"#, literal); | 44 | let src = format!(r#"const S: &'static str = "{}";"#, literal); |
45 | println!("Source: {}", src); | 45 | println!("Source: {}", src); |
46 | SourceFileNode::parse(&src) | 46 | SourceFile::parse(&src) |
47 | } | 47 | } |
48 | 48 | ||
49 | fn assert_valid_str(literal: &str) { | 49 | fn assert_valid_str(literal: &str) { |
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs index cacd89dc8..1bf1806b9 100644 --- a/crates/ra_syntax/src/yellow.rs +++ b/crates/ra_syntax/src/yellow.rs | |||
@@ -4,15 +4,12 @@ mod syntax_text; | |||
4 | 4 | ||
5 | use self::syntax_text::SyntaxText; | 5 | use self::syntax_text::SyntaxText; |
6 | use crate::{SmolStr, SyntaxKind, TextRange}; | 6 | use crate::{SmolStr, SyntaxKind, TextRange}; |
7 | use rowan::Types; | 7 | use rowan::{Types, TransparentNewType}; |
8 | use std::{ | 8 | use std::fmt; |
9 | fmt, | ||
10 | hash::{Hash, Hasher}, | ||
11 | }; | ||
12 | 9 | ||
13 | pub(crate) use self::builder::GreenBuilder; | 10 | pub(crate) use self::builder::GreenBuilder; |
14 | pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location}; | 11 | pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location}; |
15 | pub use rowan::{TreeRoot, WalkEvent}; | 12 | pub use rowan::WalkEvent; |
16 | 13 | ||
17 | #[derive(Debug, Clone, Copy)] | 14 | #[derive(Debug, Clone, Copy)] |
18 | pub enum RaTypes {} | 15 | pub enum RaTypes {} |
@@ -21,35 +18,76 @@ impl Types for RaTypes { | |||
21 | type RootData = Vec<SyntaxError>; | 18 | type RootData = Vec<SyntaxError>; |
22 | } | 19 | } |
23 | 20 | ||
24 | pub type OwnedRoot = ::rowan::OwnedRoot<RaTypes>; | 21 | pub type GreenNode = rowan::GreenNode<RaTypes>; |
25 | pub type RefRoot<'a> = ::rowan::RefRoot<'a, RaTypes>; | ||
26 | 22 | ||
27 | pub type GreenNode = ::rowan::GreenNode<RaTypes>; | 23 | #[derive(PartialEq, Eq, Hash)] |
24 | pub struct TreePtr<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>( | ||
25 | pub(crate) rowan::TreePtr<RaTypes, T>, | ||
26 | ); | ||
28 | 27 | ||
29 | #[derive(Clone, Copy)] | 28 | impl<T> TreePtr<T> |
30 | pub struct SyntaxNode<R: TreeRoot<RaTypes> = OwnedRoot>(pub(crate) ::rowan::SyntaxNode<RaTypes, R>); | 29 | where |
31 | pub type SyntaxNodeRef<'a> = SyntaxNode<RefRoot<'a>>; | 30 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |
31 | { | ||
32 | pub(crate) fn cast<U>(this: TreePtr<T>) -> TreePtr<U> | ||
33 | where | ||
34 | U: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
35 | { | ||
36 | TreePtr(rowan::TreePtr::cast(this.0)) | ||
37 | } | ||
38 | } | ||
39 | |||
40 | impl<T> std::ops::Deref for TreePtr<T> | ||
41 | where | ||
42 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
43 | { | ||
44 | type Target = T; | ||
45 | fn deref(&self) -> &T { | ||
46 | self.0.deref() | ||
47 | } | ||
48 | } | ||
49 | |||
50 | impl<T> PartialEq<T> for TreePtr<T> | ||
51 | where | ||
52 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
53 | T: PartialEq<T>, | ||
54 | { | ||
55 | fn eq(&self, other: &T) -> bool { | ||
56 | let t: &T = self; | ||
57 | t == other | ||
58 | } | ||
59 | } | ||
32 | 60 | ||
33 | impl<R1, R2> PartialEq<SyntaxNode<R1>> for SyntaxNode<R2> | 61 | impl<T> Clone for TreePtr<T> |
34 | where | 62 | where |
35 | R1: TreeRoot<RaTypes>, | 63 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |
36 | R2: TreeRoot<RaTypes>, | ||
37 | { | 64 | { |
38 | fn eq(&self, other: &SyntaxNode<R1>) -> bool { | 65 | fn clone(&self) -> TreePtr<T> { |
39 | self.0 == other.0 | 66 | TreePtr(self.0.clone()) |
40 | } | 67 | } |
41 | } | 68 | } |
42 | 69 | ||
43 | impl<R: TreeRoot<RaTypes>> Eq for SyntaxNode<R> {} | 70 | impl<T> fmt::Debug for TreePtr<T> |
44 | impl<R: TreeRoot<RaTypes>> Hash for SyntaxNode<R> { | 71 | where |
45 | fn hash<H: Hasher>(&self, state: &mut H) { | 72 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |
46 | self.0.hash(state) | 73 | T: fmt::Debug, |
74 | { | ||
75 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
76 | fmt::Debug::fmt(&self.0, fmt) | ||
47 | } | 77 | } |
48 | } | 78 | } |
49 | 79 | ||
80 | #[derive(PartialEq, Eq, Hash)] | ||
81 | #[repr(transparent)] | ||
82 | pub struct SyntaxNode(pub(crate) rowan::SyntaxNode<RaTypes>); | ||
83 | unsafe impl TransparentNewType for SyntaxNode { | ||
84 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
85 | } | ||
86 | |||
50 | impl SyntaxNode { | 87 | impl SyntaxNode { |
51 | pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SyntaxNode { | 88 | pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SyntaxNode> { |
52 | SyntaxNode(::rowan::SyntaxNode::new(green, errors)) | 89 | let ptr = TreePtr(rowan::SyntaxNode::new(green, errors)); |
90 | TreePtr::cast(ptr) | ||
53 | } | 91 | } |
54 | } | 92 | } |
55 | 93 | ||
@@ -59,45 +97,43 @@ pub enum Direction { | |||
59 | Prev, | 97 | Prev, |
60 | } | 98 | } |
61 | 99 | ||
62 | impl<'a> SyntaxNodeRef<'a> { | 100 | impl SyntaxNode { |
63 | pub fn leaf_text(self) -> Option<&'a SmolStr> { | 101 | pub fn leaf_text(&self) -> Option<&SmolStr> { |
64 | self.0.leaf_text() | 102 | self.0.leaf_text() |
65 | } | 103 | } |
66 | pub fn ancestors(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> { | 104 | pub fn ancestors(&self) -> impl Iterator<Item = &SyntaxNode> { |
67 | crate::algo::generate(Some(self), |&node| node.parent()) | 105 | crate::algo::generate(Some(self), |&node| node.parent()) |
68 | } | 106 | } |
69 | pub fn descendants(self) -> impl Iterator<Item = SyntaxNodeRef<'a>> { | 107 | pub fn descendants(&self) -> impl Iterator<Item = &SyntaxNode> { |
70 | self.preorder().filter_map(|event| match event { | 108 | self.preorder().filter_map(|event| match event { |
71 | WalkEvent::Enter(node) => Some(node), | 109 | WalkEvent::Enter(node) => Some(node), |
72 | WalkEvent::Leave(_) => None, | 110 | WalkEvent::Leave(_) => None, |
73 | }) | 111 | }) |
74 | } | 112 | } |
75 | pub fn siblings(self, direction: Direction) -> impl Iterator<Item = SyntaxNodeRef<'a>> { | 113 | pub fn siblings(&self, direction: Direction) -> impl Iterator<Item = &SyntaxNode> { |
76 | crate::algo::generate(Some(self), move |&node| match direction { | 114 | crate::algo::generate(Some(self), move |&node| match direction { |
77 | Direction::Next => node.next_sibling(), | 115 | Direction::Next => node.next_sibling(), |
78 | Direction::Prev => node.prev_sibling(), | 116 | Direction::Prev => node.prev_sibling(), |
79 | }) | 117 | }) |
80 | } | 118 | } |
81 | pub fn preorder(self) -> impl Iterator<Item = WalkEvent<SyntaxNodeRef<'a>>> { | 119 | pub fn preorder(&self) -> impl Iterator<Item = WalkEvent<&SyntaxNode>> { |
82 | self.0.preorder().map(|event| match event { | 120 | self.0.preorder().map(|event| match event { |
83 | WalkEvent::Enter(n) => WalkEvent::Enter(SyntaxNode(n)), | 121 | WalkEvent::Enter(n) => WalkEvent::Enter(SyntaxNode::from_repr(n)), |
84 | WalkEvent::Leave(n) => WalkEvent::Leave(SyntaxNode(n)), | 122 | WalkEvent::Leave(n) => WalkEvent::Leave(SyntaxNode::from_repr(n)), |
85 | }) | 123 | }) |
86 | } | 124 | } |
87 | } | 125 | } |
88 | 126 | ||
89 | impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { | 127 | impl SyntaxNode { |
90 | pub(crate) fn root_data(&self) -> &Vec<SyntaxError> { | 128 | pub(crate) fn root_data(&self) -> &Vec<SyntaxError> { |
91 | self.0.root_data() | 129 | self.0.root_data() |
92 | } | 130 | } |
93 | pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode { | 131 | pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode { |
94 | self.0.replace_with(replacement) | 132 | self.0.replace_self(replacement) |
95 | } | ||
96 | pub fn borrowed<'a>(&'a self) -> SyntaxNode<RefRoot<'a>> { | ||
97 | SyntaxNode(self.0.borrowed()) | ||
98 | } | 133 | } |
99 | pub fn owned(&self) -> SyntaxNode<OwnedRoot> { | 134 | pub fn to_owned(&self) -> TreePtr<SyntaxNode> { |
100 | SyntaxNode(self.0.owned()) | 135 | let ptr = TreePtr(self.0.to_owned()); |
136 | TreePtr::cast(ptr) | ||
101 | } | 137 | } |
102 | pub fn kind(&self) -> SyntaxKind { | 138 | pub fn kind(&self) -> SyntaxKind { |
103 | self.0.kind() | 139 | self.0.kind() |
@@ -106,32 +142,32 @@ impl<R: TreeRoot<RaTypes>> SyntaxNode<R> { | |||
106 | self.0.range() | 142 | self.0.range() |
107 | } | 143 | } |
108 | pub fn text(&self) -> SyntaxText { | 144 | pub fn text(&self) -> SyntaxText { |
109 | SyntaxText::new(self.borrowed()) | 145 | SyntaxText::new(self) |
110 | } | 146 | } |
111 | pub fn is_leaf(&self) -> bool { | 147 | pub fn is_leaf(&self) -> bool { |
112 | self.0.is_leaf() | 148 | self.0.is_leaf() |
113 | } | 149 | } |
114 | pub fn parent(&self) -> Option<SyntaxNode<R>> { | 150 | pub fn parent(&self) -> Option<&SyntaxNode> { |
115 | self.0.parent().map(SyntaxNode) | 151 | self.0.parent().map(SyntaxNode::from_repr) |
116 | } | 152 | } |
117 | pub fn first_child(&self) -> Option<SyntaxNode<R>> { | 153 | pub fn first_child(&self) -> Option<&SyntaxNode> { |
118 | self.0.first_child().map(SyntaxNode) | 154 | self.0.first_child().map(SyntaxNode::from_repr) |
119 | } | 155 | } |
120 | pub fn last_child(&self) -> Option<SyntaxNode<R>> { | 156 | pub fn last_child(&self) -> Option<&SyntaxNode> { |
121 | self.0.last_child().map(SyntaxNode) | 157 | self.0.last_child().map(SyntaxNode::from_repr) |
122 | } | 158 | } |
123 | pub fn next_sibling(&self) -> Option<SyntaxNode<R>> { | 159 | pub fn next_sibling(&self) -> Option<&SyntaxNode> { |
124 | self.0.next_sibling().map(SyntaxNode) | 160 | self.0.next_sibling().map(SyntaxNode::from_repr) |
125 | } | 161 | } |
126 | pub fn prev_sibling(&self) -> Option<SyntaxNode<R>> { | 162 | pub fn prev_sibling(&self) -> Option<&SyntaxNode> { |
127 | self.0.prev_sibling().map(SyntaxNode) | 163 | self.0.prev_sibling().map(SyntaxNode::from_repr) |
128 | } | 164 | } |
129 | pub fn children(&self) -> SyntaxNodeChildren<R> { | 165 | pub fn children(&self) -> SyntaxNodeChildren { |
130 | SyntaxNodeChildren(self.0.children()) | 166 | SyntaxNodeChildren(self.0.children()) |
131 | } | 167 | } |
132 | } | 168 | } |
133 | 169 | ||
134 | impl<R: TreeRoot<RaTypes>> fmt::Debug for SyntaxNode<R> { | 170 | impl fmt::Debug for SyntaxNode { |
135 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | 171 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
136 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; | 172 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; |
137 | if has_short_text(self.kind()) { | 173 | if has_short_text(self.kind()) { |
@@ -142,13 +178,13 @@ impl<R: TreeRoot<RaTypes>> fmt::Debug for SyntaxNode<R> { | |||
142 | } | 178 | } |
143 | 179 | ||
144 | #[derive(Debug)] | 180 | #[derive(Debug)] |
145 | pub struct SyntaxNodeChildren<R: TreeRoot<RaTypes>>(::rowan::SyntaxNodeChildren<RaTypes, R>); | 181 | pub struct SyntaxNodeChildren<'a>(rowan::SyntaxNodeChildren<'a, RaTypes>); |
146 | 182 | ||
147 | impl<R: TreeRoot<RaTypes>> Iterator for SyntaxNodeChildren<R> { | 183 | impl<'a> Iterator for SyntaxNodeChildren<'a> { |
148 | type Item = SyntaxNode<R>; | 184 | type Item = &'a SyntaxNode; |
149 | 185 | ||
150 | fn next(&mut self) -> Option<SyntaxNode<R>> { | 186 | fn next(&mut self) -> Option<&'a SyntaxNode> { |
151 | self.0.next().map(SyntaxNode) | 187 | self.0.next().map(SyntaxNode::from_repr) |
152 | } | 188 | } |
153 | } | 189 | } |
154 | 190 | ||
diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs index 279a83b61..31db0fdab 100644 --- a/crates/ra_syntax/src/yellow/syntax_text.rs +++ b/crates/ra_syntax/src/yellow/syntax_text.rs | |||
@@ -3,17 +3,17 @@ use std::{fmt, ops}; | |||
3 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 3 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
4 | use crate::{ | 4 | use crate::{ |
5 | text_utils::intersect, | 5 | text_utils::intersect, |
6 | SyntaxNodeRef, TextRange, TextUnit, | 6 | SyntaxNode, TextRange, TextUnit, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | #[derive(Clone)] | 9 | #[derive(Clone)] |
10 | pub struct SyntaxText<'a> { | 10 | pub struct SyntaxText<'a> { |
11 | node: SyntaxNodeRef<'a>, | 11 | node: &'a SyntaxNode, |
12 | range: TextRange, | 12 | range: TextRange, |
13 | } | 13 | } |
14 | 14 | ||
15 | impl<'a> SyntaxText<'a> { | 15 | impl<'a> SyntaxText<'a> { |
16 | pub(crate) fn new(node: SyntaxNodeRef<'a>) -> SyntaxText<'a> { | 16 | pub(crate) fn new(node: &'a SyntaxNode) -> SyntaxText<'a> { |
17 | SyntaxText { | 17 | SyntaxText { |
18 | node, | 18 | node, |
19 | range: node.range(), | 19 | range: node.range(), |
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index 2235dc401..3243b27ae 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs | |||
@@ -9,8 +9,8 @@ use std::{ | |||
9 | 9 | ||
10 | use test_utils::{project_dir, dir_tests, read_text, collect_tests}; | 10 | use test_utils::{project_dir, dir_tests, read_text, collect_tests}; |
11 | use ra_syntax::{ | 11 | use ra_syntax::{ |
12 | SourceFile, AstNode, | ||
12 | utils::{check_fuzz_invariants, dump_tree}, | 13 | utils::{check_fuzz_invariants, dump_tree}, |
13 | SourceFileNode, | ||
14 | }; | 14 | }; |
15 | 15 | ||
16 | #[test] | 16 | #[test] |
@@ -27,7 +27,7 @@ fn parser_tests() { | |||
27 | &test_data_dir(), | 27 | &test_data_dir(), |
28 | &["parser/inline/ok", "parser/ok"], | 28 | &["parser/inline/ok", "parser/ok"], |
29 | |text, path| { | 29 | |text, path| { |
30 | let file = SourceFileNode::parse(text); | 30 | let file = SourceFile::parse(text); |
31 | let errors = file.errors(); | 31 | let errors = file.errors(); |
32 | assert_eq!( | 32 | assert_eq!( |
33 | &*errors, | 33 | &*errors, |
@@ -42,7 +42,7 @@ fn parser_tests() { | |||
42 | &test_data_dir(), | 42 | &test_data_dir(), |
43 | &["parser/err", "parser/inline/err"], | 43 | &["parser/err", "parser/inline/err"], |
44 | |text, path| { | 44 | |text, path| { |
45 | let file = SourceFileNode::parse(text); | 45 | let file = SourceFile::parse(text); |
46 | let errors = file.errors(); | 46 | let errors = file.errors(); |
47 | assert_ne!( | 47 | assert_ne!( |
48 | &*errors, | 48 | &*errors, |
@@ -85,7 +85,7 @@ fn self_hosting_parsing() { | |||
85 | { | 85 | { |
86 | count += 1; | 86 | count += 1; |
87 | let text = read_text(entry.path()); | 87 | let text = read_text(entry.path()); |
88 | let node = SourceFileNode::parse(&text); | 88 | let node = SourceFile::parse(&text); |
89 | let errors = node.errors(); | 89 | let errors = node.errors(); |
90 | assert_eq!( | 90 | assert_eq!( |
91 | &*errors, | 91 | &*errors, |