diff options
70 files changed, 2880 insertions, 3885 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..98554dd4c 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,11 +112,10 @@ 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, |
120 | name: name.text(), | 118 | name: name.text().clone(), |
121 | range: name.syntax().range(), | 119 | range: name.syntax().range(), |
122 | kind: MODULE, | 120 | kind: MODULE, |
123 | ptr: None, | 121 | ptr: None, |
@@ -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..8dd15b40e 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,9 +203,9 @@ 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().clone(); |
209 | let ptr = LocalSyntaxPtr::new(node.syntax()); | 209 | let ptr = LocalSyntaxPtr::new(node.syntax()); |
210 | Some((name, ptr)) | 210 | Some((name, ptr)) |
211 | } | 211 | } |
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..f839f6a7a 100644 --- a/crates/ra_editor/src/assists.rs +++ b/crates/ra_editor/src/assists.rs | |||
@@ -9,12 +9,15 @@ mod add_impl; | |||
9 | mod introduce_variable; | 9 | mod introduce_variable; |
10 | mod change_visibility; | 10 | mod change_visibility; |
11 | mod split_import; | 11 | mod split_import; |
12 | mod replace_if_let_with_match; | ||
12 | 13 | ||
13 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 14 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
14 | use ra_syntax::{ | 15 | use ra_syntax::{ |
15 | Direction, SyntaxNodeRef, TextUnit, TextRange,SourceFileNode, AstNode, | 16 | Direction, SyntaxNode, TextUnit, TextRange, SourceFile, AstNode, |
16 | algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset}, | 17 | algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset}, |
18 | ast::{self, AstToken}, | ||
17 | }; | 19 | }; |
20 | use itertools::Itertools; | ||
18 | 21 | ||
19 | use crate::find_node_at_offset; | 22 | use crate::find_node_at_offset; |
20 | 23 | ||
@@ -25,10 +28,11 @@ pub use self::{ | |||
25 | introduce_variable::introduce_variable, | 28 | introduce_variable::introduce_variable, |
26 | change_visibility::change_visibility, | 29 | change_visibility::change_visibility, |
27 | split_import::split_import, | 30 | split_import::split_import, |
31 | replace_if_let_with_match::replace_if_let_with_match, | ||
28 | }; | 32 | }; |
29 | 33 | ||
30 | /// Return all the assists applicable at the given position. | 34 | /// Return all the assists applicable at the given position. |
31 | pub fn assists(file: &SourceFileNode, range: TextRange) -> Vec<LocalEdit> { | 35 | pub fn assists(file: &SourceFile, range: TextRange) -> Vec<LocalEdit> { |
32 | let ctx = AssistCtx::new(file, range); | 36 | let ctx = AssistCtx::new(file, range); |
33 | [ | 37 | [ |
34 | flip_comma, | 38 | flip_comma, |
@@ -37,6 +41,7 @@ pub fn assists(file: &SourceFileNode, range: TextRange) -> Vec<LocalEdit> { | |||
37 | introduce_variable, | 41 | introduce_variable, |
38 | change_visibility, | 42 | change_visibility, |
39 | split_import, | 43 | split_import, |
44 | replace_if_let_with_match, | ||
40 | ] | 45 | ] |
41 | .iter() | 46 | .iter() |
42 | .filter_map(|&assist| ctx.clone().apply(assist)) | 47 | .filter_map(|&assist| ctx.clone().apply(assist)) |
@@ -50,7 +55,7 @@ pub struct LocalEdit { | |||
50 | pub cursor_position: Option<TextUnit>, | 55 | pub cursor_position: Option<TextUnit>, |
51 | } | 56 | } |
52 | 57 | ||
53 | fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { | 58 | fn non_trivia_sibling(node: &SyntaxNode, direction: Direction) -> Option<&SyntaxNode> { |
54 | node.siblings(direction) | 59 | node.siblings(direction) |
55 | .skip(1) | 60 | .skip(1) |
56 | .find(|node| !node.kind().is_trivia()) | 61 | .find(|node| !node.kind().is_trivia()) |
@@ -88,7 +93,7 @@ fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<Synta | |||
88 | /// easier to just compute the edit eagarly :-) | 93 | /// easier to just compute the edit eagarly :-) |
89 | #[derive(Debug, Clone)] | 94 | #[derive(Debug, Clone)] |
90 | pub struct AssistCtx<'a> { | 95 | pub struct AssistCtx<'a> { |
91 | source_file: &'a SourceFileNode, | 96 | source_file: &'a SourceFile, |
92 | range: TextRange, | 97 | range: TextRange, |
93 | should_compute_edit: bool, | 98 | should_compute_edit: bool, |
94 | } | 99 | } |
@@ -106,7 +111,7 @@ struct AssistBuilder { | |||
106 | } | 111 | } |
107 | 112 | ||
108 | impl<'a> AssistCtx<'a> { | 113 | impl<'a> AssistCtx<'a> { |
109 | pub fn new(source_file: &'a SourceFileNode, range: TextRange) -> AssistCtx { | 114 | pub fn new(source_file: &'a SourceFile, range: TextRange) -> AssistCtx { |
110 | AssistCtx { | 115 | AssistCtx { |
111 | source_file, | 116 | source_file, |
112 | range, | 117 | range, |
@@ -145,13 +150,13 @@ impl<'a> AssistCtx<'a> { | |||
145 | })) | 150 | })) |
146 | } | 151 | } |
147 | 152 | ||
148 | pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<SyntaxNodeRef<'a>> { | 153 | pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<&'a SyntaxNode> { |
149 | find_leaf_at_offset(self.source_file.syntax(), self.range.start()) | 154 | find_leaf_at_offset(self.source_file.syntax(), self.range.start()) |
150 | } | 155 | } |
151 | pub(crate) fn node_at_offset<N: AstNode<'a>>(&self) -> Option<N> { | 156 | pub(crate) fn node_at_offset<N: AstNode>(&self) -> Option<&'a N> { |
152 | find_node_at_offset(self.source_file.syntax(), self.range.start()) | 157 | find_node_at_offset(self.source_file.syntax(), self.range.start()) |
153 | } | 158 | } |
154 | pub(crate) fn covering_node(&self) -> SyntaxNodeRef<'a> { | 159 | pub(crate) fn covering_node(&self) -> &'a SyntaxNode { |
155 | find_covering_node(self.source_file.syntax(), self.range) | 160 | find_covering_node(self.source_file.syntax(), self.range) |
156 | } | 161 | } |
157 | } | 162 | } |
@@ -160,6 +165,13 @@ impl AssistBuilder { | |||
160 | fn replace(&mut self, range: TextRange, replace_with: impl Into<String>) { | 165 | fn replace(&mut self, range: TextRange, replace_with: impl Into<String>) { |
161 | self.edit.replace(range, replace_with.into()) | 166 | self.edit.replace(range, replace_with.into()) |
162 | } | 167 | } |
168 | fn replace_node_and_indent(&mut self, node: &SyntaxNode, replace_with: impl Into<String>) { | ||
169 | let mut replace_with = replace_with.into(); | ||
170 | if let Some(indent) = calc_indent(node) { | ||
171 | replace_with = reindent(&replace_with, indent) | ||
172 | } | ||
173 | self.replace(node.range(), replace_with) | ||
174 | } | ||
163 | #[allow(unused)] | 175 | #[allow(unused)] |
164 | fn delete(&mut self, range: TextRange) { | 176 | fn delete(&mut self, range: TextRange) { |
165 | self.edit.delete(range) | 177 | self.edit.delete(range) |
@@ -172,6 +184,17 @@ impl AssistBuilder { | |||
172 | } | 184 | } |
173 | } | 185 | } |
174 | 186 | ||
187 | fn calc_indent(node: &SyntaxNode) -> Option<&str> { | ||
188 | let prev = node.prev_sibling()?; | ||
189 | let ws_text = ast::Whitespace::cast(prev)?.text(); | ||
190 | ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..]) | ||
191 | } | ||
192 | |||
193 | fn reindent(text: &str, indent: &str) -> String { | ||
194 | let indent = format!("\n{}", indent); | ||
195 | text.lines().intersperse(&indent).collect() | ||
196 | } | ||
197 | |||
175 | #[cfg(test)] | 198 | #[cfg(test)] |
176 | fn check_assist(assist: fn(AssistCtx) -> Option<Assist>, before: &str, after: &str) { | 199 | fn check_assist(assist: fn(AssistCtx) -> Option<Assist>, before: &str, after: &str) { |
177 | crate::test_utils::check_action(before, after, |file, off| { | 200 | crate::test_utils::check_action(before, after, |file, off| { |
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/add_impl.rs b/crates/ra_editor/src/assists/add_impl.rs index 9353e2717..2eda7cae2 100644 --- a/crates/ra_editor/src/assists/add_impl.rs +++ b/crates/ra_editor/src/assists/add_impl.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use join_to_string::join; | 1 | use join_to_string::join; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, AstNode, NameOwner, TypeParamsOwner}, | 3 | ast::{self, AstNode, AstToken, NameOwner, TypeParamsOwner}, |
4 | TextUnit, | 4 | TextUnit, |
5 | }; | 5 | }; |
6 | 6 | ||
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/assists/replace_if_let_with_match.rs b/crates/ra_editor/src/assists/replace_if_let_with_match.rs new file mode 100644 index 000000000..30c371480 --- /dev/null +++ b/crates/ra_editor/src/assists/replace_if_let_with_match.rs | |||
@@ -0,0 +1,92 @@ | |||
1 | use ra_syntax::{ | ||
2 | AstNode, SyntaxKind::{L_CURLY, R_CURLY, WHITESPACE}, | ||
3 | ast, | ||
4 | }; | ||
5 | |||
6 | use crate::assists::{AssistCtx, Assist}; | ||
7 | |||
8 | pub fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> { | ||
9 | let if_expr: &ast::IfExpr = ctx.node_at_offset()?; | ||
10 | let cond = if_expr.condition()?; | ||
11 | let pat = cond.pat()?; | ||
12 | let expr = cond.expr()?; | ||
13 | let then_block = if_expr.then_branch()?; | ||
14 | let else_block = if_expr.else_branch()?; | ||
15 | |||
16 | ctx.build("replace with match", |edit| { | ||
17 | let match_expr = build_match_expr(expr, pat, then_block, else_block); | ||
18 | edit.replace_node_and_indent(if_expr.syntax(), match_expr); | ||
19 | edit.set_cursor(if_expr.syntax().range().start()) | ||
20 | }) | ||
21 | } | ||
22 | |||
23 | fn build_match_expr( | ||
24 | expr: &ast::Expr, | ||
25 | pat1: &ast::Pat, | ||
26 | arm1: &ast::Block, | ||
27 | arm2: &ast::Block, | ||
28 | ) -> String { | ||
29 | let mut buf = String::new(); | ||
30 | buf.push_str(&format!("match {} {{\n", expr.syntax().text())); | ||
31 | buf.push_str(&format!( | ||
32 | " {} => {}\n", | ||
33 | pat1.syntax().text(), | ||
34 | format_arm(arm1) | ||
35 | )); | ||
36 | buf.push_str(&format!(" _ => {}\n", format_arm(arm2))); | ||
37 | buf.push_str("}"); | ||
38 | buf | ||
39 | } | ||
40 | |||
41 | fn format_arm(block: &ast::Block) -> String { | ||
42 | match extract_expression(block) { | ||
43 | None => block.syntax().text().to_string(), | ||
44 | Some(e) => format!("{},", e.syntax().text()), | ||
45 | } | ||
46 | } | ||
47 | |||
48 | fn extract_expression(block: &ast::Block) -> Option<&ast::Expr> { | ||
49 | let expr = block.expr()?; | ||
50 | let non_trivial_children = block.syntax().children().filter(|it| { | ||
51 | !(it == &expr.syntax() | ||
52 | || it.kind() == L_CURLY | ||
53 | || it.kind() == R_CURLY | ||
54 | || it.kind() == WHITESPACE) | ||
55 | }); | ||
56 | if non_trivial_children.count() > 0 { | ||
57 | return None; | ||
58 | } | ||
59 | Some(expr) | ||
60 | } | ||
61 | |||
62 | #[cfg(test)] | ||
63 | mod tests { | ||
64 | use super::*; | ||
65 | use crate::assists::check_assist; | ||
66 | |||
67 | #[test] | ||
68 | fn test_replace_if_let_with_match_unwraps_simple_expressions() { | ||
69 | check_assist( | ||
70 | replace_if_let_with_match, | ||
71 | " | ||
72 | impl VariantData { | ||
73 | pub fn is_struct(&self) -> bool { | ||
74 | if <|>let VariantData::Struct(..) = *self { | ||
75 | true | ||
76 | } else { | ||
77 | false | ||
78 | } | ||
79 | } | ||
80 | } ", | ||
81 | " | ||
82 | impl VariantData { | ||
83 | pub fn is_struct(&self) -> bool { | ||
84 | <|>match *self { | ||
85 | VariantData::Struct(..) => true, | ||
86 | _ => false, | ||
87 | } | ||
88 | } | ||
89 | } ", | ||
90 | ) | ||
91 | } | ||
92 | } | ||
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..dc2470aa3 100644 --- a/crates/ra_editor/src/test_utils.rs +++ b/crates/ra_editor/src/test_utils.rs | |||
@@ -1,32 +1,35 @@ | |||
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 { |
16 | None => result.edit.apply_to_offset(before_cursor_pos).unwrap(), | 16 | None => result |
17 | .edit | ||
18 | .apply_to_offset(before_cursor_pos) | ||
19 | .expect("cursor position is affected by the edit"), | ||
17 | Some(off) => off, | 20 | Some(off) => off, |
18 | }; | 21 | }; |
19 | let actual = add_cursor(&actual, actual_cursor_pos); | 22 | let actual = add_cursor(&actual, actual_cursor_pos); |
20 | assert_eq_text!(after, &actual); | 23 | assert_eq_text!(after, &actual); |
21 | } | 24 | } |
22 | 25 | ||
23 | pub fn check_action_range<F: Fn(&SourceFileNode, TextRange) -> Option<LocalEdit>>( | 26 | pub fn check_action_range<F: Fn(&SourceFile, TextRange) -> Option<LocalEdit>>( |
24 | before: &str, | 27 | before: &str, |
25 | after: &str, | 28 | after: &str, |
26 | f: F, | 29 | f: F, |
27 | ) { | 30 | ) { |
28 | let (range, before) = extract_range(before); | 31 | let (range, before) = extract_range(before); |
29 | let file = SourceFileNode::parse(&before); | 32 | let file = SourceFile::parse(&before); |
30 | let result = f(&file, range).expect("code action is not applicable"); | 33 | let result = f(&file, range).expect("code action is not applicable"); |
31 | let actual = result.edit.apply(&before); | 34 | let actual = result.edit.apply(&before); |
32 | let actual_cursor_pos = match result.cursor_position { | 35 | 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..b75adda84 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() |
@@ -171,24 +171,21 @@ impl VariantData { | |||
171 | } | 171 | } |
172 | } | 172 | } |
173 | pub fn is_struct(&self) -> bool { | 173 | pub fn is_struct(&self) -> bool { |
174 | if let VariantData::Struct(..) = *self { | 174 | match self { |
175 | true | 175 | VariantData::Struct(..) => true, |
176 | } else { | 176 | _ => false, |
177 | false | ||
178 | } | 177 | } |
179 | } | 178 | } |
180 | pub fn is_tuple(&self) -> bool { | 179 | pub fn is_tuple(&self) -> bool { |
181 | if let VariantData::Tuple(..) = *self { | 180 | match self { |
182 | true | 181 | VariantData::Tuple(..) => true, |
183 | } else { | 182 | _ => false, |
184 | false | ||
185 | } | 183 | } |
186 | } | 184 | } |
187 | pub fn is_unit(&self) -> bool { | 185 | pub fn is_unit(&self) -> bool { |
188 | if let VariantData::Unit = *self { | 186 | match self { |
189 | true | 187 | VariantData::Unit => true, |
190 | } else { | 188 | _ => false, |
191 | false | ||
192 | } | 189 | } |
193 | } | 190 | } |
194 | } | 191 | } |
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 90229bc54..3e6ce8b95 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir/src/name.rs | |||
@@ -59,6 +59,9 @@ impl Name { | |||
59 | "u128" => KnownName::U128, | 59 | "u128" => KnownName::U128, |
60 | "f32" => KnownName::F32, | 60 | "f32" => KnownName::F32, |
61 | "f64" => KnownName::F64, | 61 | "f64" => KnownName::F64, |
62 | "bool" => KnownName::Bool, | ||
63 | "char" => KnownName::Char, | ||
64 | "str" => KnownName::Str, | ||
62 | "Self" => KnownName::SelfType, | 65 | "Self" => KnownName::SelfType, |
63 | "self" => KnownName::SelfParam, | 66 | "self" => KnownName::SelfParam, |
64 | _ => return None, | 67 | _ => return None, |
@@ -71,15 +74,15 @@ pub(crate) trait AsName { | |||
71 | fn as_name(&self) -> Name; | 74 | fn as_name(&self) -> Name; |
72 | } | 75 | } |
73 | 76 | ||
74 | impl AsName for ast::NameRef<'_> { | 77 | impl AsName for ast::NameRef { |
75 | fn as_name(&self) -> Name { | 78 | fn as_name(&self) -> Name { |
76 | Name::new(self.text()) | 79 | Name::new(self.text().clone()) |
77 | } | 80 | } |
78 | } | 81 | } |
79 | 82 | ||
80 | impl AsName for ast::Name<'_> { | 83 | impl AsName for ast::Name { |
81 | fn as_name(&self) -> Name { | 84 | fn as_name(&self) -> Name { |
82 | Name::new(self.text()) | 85 | Name::new(self.text().clone()) |
83 | } | 86 | } |
84 | } | 87 | } |
85 | 88 | ||
@@ -113,6 +116,10 @@ pub(crate) enum KnownName { | |||
113 | F32, | 116 | F32, |
114 | F64, | 117 | F64, |
115 | 118 | ||
119 | Bool, | ||
120 | Char, | ||
121 | Str, | ||
122 | |||
116 | SelfType, | 123 | SelfType, |
117 | SelfParam, | 124 | SelfParam, |
118 | } | 125 | } |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index bd66b5d2c..4181bf4b8 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..59a803761 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,15 +170,14 @@ 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) { |
178 | if let Some(name) = trait_def.name() { | 177 | if let Some(name) = trait_def.name() { |
179 | let dst_range = name.syntax().range(); | 178 | let dst_range = name.syntax().range(); |
180 | if let Some(src_range) = exp.map_range_back(dst_range) { | 179 | if let Some(src_range) = exp.map_range_back(dst_range) { |
181 | res.push((name.text(), src_range + off)) | 180 | res.push((name.text().clone(), src_range + off)) |
182 | } | 181 | } |
183 | } | 182 | } |
184 | } | 183 | } |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index bba8527b7..8adeedddb 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -308,7 +308,13 @@ impl Ty { | |||
308 | path: &Path, | 308 | path: &Path, |
309 | ) -> Cancelable<Self> { | 309 | ) -> Cancelable<Self> { |
310 | if let Some(name) = path.as_ident() { | 310 | if let Some(name) = path.as_ident() { |
311 | if let Some(int_ty) = primitive::IntTy::from_name(name) { | 311 | if let Some(KnownName::Bool) = name.as_known_name() { |
312 | return Ok(Ty::Bool); | ||
313 | } else if let Some(KnownName::Char) = name.as_known_name() { | ||
314 | return Ok(Ty::Char); | ||
315 | } else if let Some(KnownName::Str) = name.as_known_name() { | ||
316 | return Ok(Ty::Str); | ||
317 | } else if let Some(int_ty) = primitive::IntTy::from_name(name) { | ||
312 | return Ok(Ty::Int(int_ty)); | 318 | return Ok(Ty::Int(int_ty)); |
313 | } else if let Some(uint_ty) = primitive::UintTy::from_name(name) { | 319 | } else if let Some(uint_ty) = primitive::UintTy::from_name(name) { |
314 | return Ok(Ty::Uint(uint_ty)); | 320 | return Ok(Ty::Uint(uint_ty)); |
@@ -527,9 +533,7 @@ struct InferenceContext<'a, D: HirDatabase> { | |||
527 | return_ty: Ty, | 533 | return_ty: Ty, |
528 | } | 534 | } |
529 | 535 | ||
530 | // helper function that determines whether a binary operator | 536 | fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { |
531 | // always returns a boolean | ||
532 | fn is_boolean_operator(op: BinaryOp) -> bool { | ||
533 | match op { | 537 | match op { |
534 | BinaryOp::BooleanOr | 538 | BinaryOp::BooleanOr |
535 | | BinaryOp::BooleanAnd | 539 | | BinaryOp::BooleanAnd |
@@ -537,7 +541,70 @@ fn is_boolean_operator(op: BinaryOp) -> bool { | |||
537 | | BinaryOp::LesserEqualTest | 541 | | BinaryOp::LesserEqualTest |
538 | | BinaryOp::GreaterEqualTest | 542 | | BinaryOp::GreaterEqualTest |
539 | | BinaryOp::LesserTest | 543 | | BinaryOp::LesserTest |
540 | | BinaryOp::GreaterTest => true, | 544 | | BinaryOp::GreaterTest => Ty::Bool, |
545 | BinaryOp::Assignment | ||
546 | | BinaryOp::AddAssign | ||
547 | | BinaryOp::SubAssign | ||
548 | | BinaryOp::DivAssign | ||
549 | | BinaryOp::MulAssign | ||
550 | | BinaryOp::RemAssign | ||
551 | | BinaryOp::ShrAssign | ||
552 | | BinaryOp::ShlAssign | ||
553 | | BinaryOp::BitAndAssign | ||
554 | | BinaryOp::BitOrAssign | ||
555 | | BinaryOp::BitXorAssign => Ty::unit(), | ||
556 | BinaryOp::Addition | ||
557 | | BinaryOp::Subtraction | ||
558 | | BinaryOp::Multiplication | ||
559 | | BinaryOp::Division | ||
560 | | BinaryOp::Remainder | ||
561 | | BinaryOp::LeftShift | ||
562 | | BinaryOp::RightShift | ||
563 | | BinaryOp::BitwiseAnd | ||
564 | | BinaryOp::BitwiseOr | ||
565 | | BinaryOp::BitwiseXor => match rhs_ty { | ||
566 | Ty::Uint(..) | Ty::Int(..) | Ty::Float(..) => rhs_ty, | ||
567 | _ => Ty::Unknown, | ||
568 | }, | ||
569 | BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown, | ||
570 | } | ||
571 | } | ||
572 | |||
573 | fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { | ||
574 | match op { | ||
575 | BinaryOp::BooleanAnd | BinaryOp::BooleanOr => Ty::Bool, | ||
576 | BinaryOp::Assignment | BinaryOp::EqualityTest => match lhs_ty { | ||
577 | Ty::Uint(..) | Ty::Int(..) | Ty::Float(..) | Ty::Str | Ty::Char | Ty::Bool => lhs_ty, | ||
578 | _ => Ty::Unknown, | ||
579 | }, | ||
580 | BinaryOp::LesserEqualTest | ||
581 | | BinaryOp::GreaterEqualTest | ||
582 | | BinaryOp::LesserTest | ||
583 | | BinaryOp::GreaterTest | ||
584 | | BinaryOp::AddAssign | ||
585 | | BinaryOp::SubAssign | ||
586 | | BinaryOp::DivAssign | ||
587 | | BinaryOp::MulAssign | ||
588 | | BinaryOp::RemAssign | ||
589 | | BinaryOp::ShrAssign | ||
590 | | BinaryOp::ShlAssign | ||
591 | | BinaryOp::BitAndAssign | ||
592 | | BinaryOp::BitOrAssign | ||
593 | | BinaryOp::BitXorAssign | ||
594 | | BinaryOp::Addition | ||
595 | | BinaryOp::Subtraction | ||
596 | | BinaryOp::Multiplication | ||
597 | | BinaryOp::Division | ||
598 | | BinaryOp::Remainder | ||
599 | | BinaryOp::LeftShift | ||
600 | | BinaryOp::RightShift | ||
601 | | BinaryOp::BitwiseAnd | ||
602 | | BinaryOp::BitwiseOr | ||
603 | | BinaryOp::BitwiseXor => match lhs_ty { | ||
604 | Ty::Uint(..) | Ty::Int(..) | Ty::Float(..) => lhs_ty, | ||
605 | _ => Ty::Unknown, | ||
606 | }, | ||
607 | _ => Ty::Unknown, | ||
541 | } | 608 | } |
542 | } | 609 | } |
543 | 610 | ||
@@ -889,20 +956,20 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
889 | } | 956 | } |
890 | Expr::BinaryOp { lhs, rhs, op } => match op { | 957 | Expr::BinaryOp { lhs, rhs, op } => match op { |
891 | Some(op) => { | 958 | Some(op) => { |
892 | let subtype_expectation = match op { | 959 | let lhs_expectation = match op { |
893 | BinaryOp::BooleanAnd | BinaryOp::BooleanOr => { | 960 | BinaryOp::BooleanAnd | BinaryOp::BooleanOr => { |
894 | Expectation::has_type(Ty::Bool) | 961 | Expectation::has_type(Ty::Bool) |
895 | } | 962 | } |
896 | _ => Expectation::none(), | 963 | _ => Expectation::none(), |
897 | }; | 964 | }; |
898 | let _lhs_ty = self.infer_expr(*lhs, &subtype_expectation)?; | 965 | let lhs_ty = self.infer_expr(*lhs, &lhs_expectation)?; |
899 | let _rhs_ty = self.infer_expr(*rhs, &subtype_expectation)?; | 966 | // TODO: find implementation of trait corresponding to operation |
900 | 967 | // symbol and resolve associated `Output` type | |
901 | if is_boolean_operator(*op) { | 968 | let rhs_expectation = binary_op_rhs_expectation(*op, lhs_ty); |
902 | Ty::Bool | 969 | let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation))?; |
903 | } else { | 970 | |
904 | Ty::Unknown | 971 | // TODO: similar as above, return ty is often associated trait type |
905 | } | 972 | binary_op_return_ty(*op, rhs_ty) |
906 | } | 973 | } |
907 | _ => Ty::Unknown, | 974 | _ => Ty::Unknown, |
908 | }, | 975 | }, |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index e6c7e225b..2749d740c 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -157,7 +157,7 @@ impl S { | |||
157 | } | 157 | } |
158 | 158 | ||
159 | #[test] | 159 | #[test] |
160 | fn infer_boolean_op() { | 160 | fn infer_binary_op() { |
161 | check_inference( | 161 | check_inference( |
162 | r#" | 162 | r#" |
163 | fn f(x: bool) -> i32 { | 163 | fn f(x: bool) -> i32 { |
@@ -168,15 +168,18 @@ fn test() { | |||
168 | let x = a && b; | 168 | let x = a && b; |
169 | let y = true || false; | 169 | let y = true || false; |
170 | let z = x == y; | 170 | let z = x == y; |
171 | let h = CONST_1 <= CONST_2; | 171 | let minus_forty: isize = -40isize; |
172 | let h = minus_forty <= CONST_2; | ||
172 | let c = f(z || y) + 5; | 173 | let c = f(z || y) + 5; |
173 | let d = b; | 174 | let d = b; |
174 | let e = 3i32 && "hello world"; | 175 | let g = minus_forty ^= i; |
176 | let ten: usize = 10; | ||
177 | let ten_is_eleven = ten == some_num; | ||
175 | 178 | ||
176 | 10 < 3 | 179 | ten < 3 |
177 | } | 180 | } |
178 | "#, | 181 | "#, |
179 | "boolean_op.txt", | 182 | "binary_op.txt", |
180 | ); | 183 | ); |
181 | } | 184 | } |
182 | 185 | ||
diff --git a/crates/ra_hir/src/ty/tests/data/basics.txt b/crates/ra_hir/src/ty/tests/data/basics.txt index 8ea244ba8..ac7faae0a 100644 --- a/crates/ra_hir/src/ty/tests/data/basics.txt +++ b/crates/ra_hir/src/ty/tests/data/basics.txt | |||
@@ -1,12 +1,12 @@ | |||
1 | [9; 10) 'a': u32 | 1 | [9; 10) 'a': u32 |
2 | [17; 18) 'b': isize | 2 | [17; 18) 'b': isize |
3 | [27; 28) 'c': ! | 3 | [27; 28) 'c': ! |
4 | [33; 34) 'd': &[unknown] | 4 | [33; 34) 'd': &str |
5 | [42; 121) '{ ...f32; }': () | 5 | [42; 121) '{ ...f32; }': () |
6 | [48; 49) 'a': u32 | 6 | [48; 49) 'a': u32 |
7 | [55; 56) 'b': isize | 7 | [55; 56) 'b': isize |
8 | [62; 63) 'c': ! | 8 | [62; 63) 'c': ! |
9 | [69; 70) 'd': &[unknown] | 9 | [69; 70) 'd': &str |
10 | [76; 82) '1usize': [unknown] | 10 | [76; 82) '1usize': [unknown] |
11 | [88; 94) '1isize': [unknown] | 11 | [88; 94) '1isize': [unknown] |
12 | [100; 106) '"test"': [unknown] | 12 | [100; 106) '"test"': [unknown] |
diff --git a/crates/ra_hir/src/ty/tests/data/binary_op.txt b/crates/ra_hir/src/ty/tests/data/binary_op.txt new file mode 100644 index 000000000..0fb9dc097 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/binary_op.txt | |||
@@ -0,0 +1,46 @@ | |||
1 | [6; 7) 'x': bool | ||
2 | [22; 34) '{ 0i32 }': i32 | ||
3 | [28; 32) '0i32': i32 | ||
4 | [46; 342) '{ ... < 3 }': bool | ||
5 | [56; 57) 'x': bool | ||
6 | [60; 61) 'a': bool | ||
7 | [60; 66) 'a && b': bool | ||
8 | [65; 66) 'b': bool | ||
9 | [76; 77) 'y': bool | ||
10 | [80; 84) 'true': bool | ||
11 | [80; 93) 'true || false': bool | ||
12 | [88; 93) 'false': bool | ||
13 | [103; 104) 'z': bool | ||
14 | [107; 108) 'x': bool | ||
15 | [107; 113) 'x == y': bool | ||
16 | [112; 113) 'y': bool | ||
17 | [123; 134) 'minus_forty': isize | ||
18 | [144; 152) '-40isize': isize | ||
19 | [145; 152) '40isize': [unknown] | ||
20 | [162; 163) 'h': bool | ||
21 | [166; 177) 'minus_forty': isize | ||
22 | [166; 188) 'minus_...ONST_2': bool | ||
23 | [181; 188) 'CONST_2': isize | ||
24 | [198; 199) 'c': i32 | ||
25 | [202; 203) 'f': fn(bool,) -> i32 | ||
26 | [202; 211) 'f(z || y)': i32 | ||
27 | [202; 215) 'f(z || y) + 5': i32 | ||
28 | [204; 205) 'z': bool | ||
29 | [204; 210) 'z || y': bool | ||
30 | [209; 210) 'y': bool | ||
31 | [214; 215) '5': i32 | ||
32 | [225; 226) 'd': [unknown] | ||
33 | [229; 230) 'b': [unknown] | ||
34 | [240; 241) 'g': () | ||
35 | [244; 255) 'minus_forty': isize | ||
36 | [244; 260) 'minus_...y ^= i': () | ||
37 | [259; 260) 'i': isize | ||
38 | [270; 273) 'ten': usize | ||
39 | [283; 285) '10': usize | ||
40 | [295; 308) 'ten_is_eleven': bool | ||
41 | [311; 314) 'ten': usize | ||
42 | [311; 326) 'ten == some_num': bool | ||
43 | [318; 326) 'some_num': usize | ||
44 | [333; 336) 'ten': usize | ||
45 | [333; 340) 'ten < 3': bool | ||
46 | [339; 340) '3': usize | ||
diff --git a/crates/ra_hir/src/ty/tests/data/boolean_op.txt b/crates/ra_hir/src/ty/tests/data/boolean_op.txt deleted file mode 100644 index cce8d68fb..000000000 --- a/crates/ra_hir/src/ty/tests/data/boolean_op.txt +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | [6; 7) 'x': [unknown] | ||
2 | [22; 34) '{ 0i32 }': i32 | ||
3 | [28; 32) '0i32': i32 | ||
4 | [46; 237) '{ ... < 3 }': bool | ||
5 | [56; 57) 'x': bool | ||
6 | [60; 61) 'a': bool | ||
7 | [60; 66) 'a && b': bool | ||
8 | [65; 66) 'b': bool | ||
9 | [76; 77) 'y': bool | ||
10 | [80; 84) 'true': bool | ||
11 | [80; 93) 'true || false': bool | ||
12 | [88; 93) 'false': bool | ||
13 | [103; 104) 'z': bool | ||
14 | [107; 108) 'x': bool | ||
15 | [107; 113) 'x == y': bool | ||
16 | [112; 113) 'y': bool | ||
17 | [123; 124) 'h': bool | ||
18 | [127; 134) 'CONST_1': [unknown] | ||
19 | [127; 145) 'CONST_...ONST_2': bool | ||
20 | [138; 145) 'CONST_2': [unknown] | ||
21 | [155; 156) 'c': [unknown] | ||
22 | [159; 172) 'f(z || y) + 5': [unknown] | ||
23 | [182; 183) 'd': [unknown] | ||
24 | [186; 187) 'b': [unknown] | ||
25 | [197; 198) 'e': bool | ||
26 | [201; 205) '3i32': bool | ||
27 | [201; 222) '3i32 &...world"': bool | ||
28 | [209; 222) '"hello world"': bool | ||
29 | [229; 231) '10': [unknown] | ||
30 | [229; 235) '10 < 3': bool | ||
31 | [234; 235) '3': [unknown] | ||
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 9df8ec663..d25b5642b 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -1,119 +1,121 @@ | |||
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 AstToken: AstNode { |
28 | fn name(self) -> Option<Name<'a>> { | 27 | fn text(&self) -> &SmolStr { |
28 | self.syntax().leaf_text().unwrap() | ||
29 | } | ||
30 | } | ||
31 | |||
32 | pub trait NameOwner: AstNode { | ||
33 | fn name(&self) -> Option<&Name> { | ||
29 | child_opt(self) | 34 | child_opt(self) |
30 | } | 35 | } |
31 | } | 36 | } |
32 | 37 | ||
33 | pub trait VisibilityOwner<'a>: AstNode<'a> { | 38 | pub trait VisibilityOwner: AstNode { |
34 | fn visibility(self) -> Option<Visibility<'a>> { | 39 | fn visibility(&self) -> Option<&Visibility> { |
35 | child_opt(self) | 40 | child_opt(self) |
36 | } | 41 | } |
37 | } | 42 | } |
38 | 43 | ||
39 | pub trait LoopBodyOwner<'a>: AstNode<'a> { | 44 | pub trait LoopBodyOwner: AstNode { |
40 | fn loop_body(self) -> Option<Block<'a>> { | 45 | fn loop_body(&self) -> Option<&Block> { |
41 | child_opt(self) | 46 | child_opt(self) |
42 | } | 47 | } |
43 | } | 48 | } |
44 | 49 | ||
45 | pub trait ArgListOwner<'a>: AstNode<'a> { | 50 | pub trait ArgListOwner: AstNode { |
46 | fn arg_list(self) -> Option<ArgList<'a>> { | 51 | fn arg_list(&self) -> Option<&ArgList> { |
47 | child_opt(self) | 52 | child_opt(self) |
48 | } | 53 | } |
49 | } | 54 | } |
50 | 55 | ||
51 | pub trait FnDefOwner<'a>: AstNode<'a> { | 56 | pub trait FnDefOwner: AstNode { |
52 | fn functions(self) -> AstChildren<'a, FnDef<'a>> { | 57 | fn functions(&self) -> AstChildren<FnDef> { |
53 | children(self) | 58 | children(self) |
54 | } | 59 | } |
55 | } | 60 | } |
56 | 61 | ||
57 | // ModuleItem | ||
58 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 62 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
59 | pub enum ItemOrMacro<'a> { | 63 | pub enum ItemOrMacro<'a> { |
60 | Item(ModuleItem<'a>), | 64 | Item(&'a ModuleItem), |
61 | Macro(MacroCall<'a>), | 65 | Macro(&'a MacroCall), |
62 | } | 66 | } |
63 | 67 | ||
64 | impl<'a> AstNode<'a> for ItemOrMacro<'a> { | 68 | pub trait ModuleItemOwner: AstNode { |
65 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 69 | fn items(&self) -> AstChildren<ModuleItem> { |
66 | let res = if let Some(item) = ModuleItem::cast(syntax) { | 70 | 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 | } | 71 | } |
75 | fn syntax(self) -> SyntaxNodeRef<'a> { | 72 | fn items_with_macros(&self) -> ItemOrMacroIter { |
76 | match self { | 73 | ItemOrMacroIter(self.syntax().children()) |
77 | ItemOrMacro::Item(it) => it.syntax(), | ||
78 | ItemOrMacro::Macro(it) => it.syntax(), | ||
79 | } | ||
80 | } | 74 | } |
81 | } | 75 | } |
82 | 76 | ||
83 | pub trait ModuleItemOwner<'a>: AstNode<'a> { | 77 | #[derive(Debug)] |
84 | fn items(self) -> AstChildren<'a, ModuleItem<'a>> { | 78 | pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>); |
85 | children(self) | ||
86 | } | ||
87 | 79 | ||
88 | fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> { | 80 | impl<'a> Iterator for ItemOrMacroIter<'a> { |
89 | children(self) | 81 | type Item = ItemOrMacro<'a>; |
82 | fn next(&mut self) -> Option<ItemOrMacro<'a>> { | ||
83 | loop { | ||
84 | let n = self.0.next()?; | ||
85 | if let Some(item) = ModuleItem::cast(n) { | ||
86 | return Some(ItemOrMacro::Item(item)); | ||
87 | } | ||
88 | if let Some(call) = MacroCall::cast(n) { | ||
89 | return Some(ItemOrMacro::Macro(call)); | ||
90 | } | ||
91 | } | ||
90 | } | 92 | } |
91 | } | 93 | } |
92 | 94 | ||
93 | pub trait TypeParamsOwner<'a>: AstNode<'a> { | 95 | pub trait TypeParamsOwner: AstNode { |
94 | fn type_param_list(self) -> Option<TypeParamList<'a>> { | 96 | fn type_param_list(&self) -> Option<&TypeParamList> { |
95 | child_opt(self) | 97 | child_opt(self) |
96 | } | 98 | } |
97 | 99 | ||
98 | fn where_clause(self) -> Option<WhereClause<'a>> { | 100 | fn where_clause(&self) -> Option<&WhereClause> { |
99 | child_opt(self) | 101 | child_opt(self) |
100 | } | 102 | } |
101 | } | 103 | } |
102 | 104 | ||
103 | pub trait AttrsOwner<'a>: AstNode<'a> { | 105 | pub trait AttrsOwner: AstNode { |
104 | fn attrs(self) -> AstChildren<'a, Attr<'a>> { | 106 | fn attrs(&self) -> AstChildren<Attr> { |
105 | children(self) | 107 | children(self) |
106 | } | 108 | } |
107 | } | 109 | } |
108 | 110 | ||
109 | pub trait DocCommentsOwner<'a>: AstNode<'a> { | 111 | pub trait DocCommentsOwner: AstNode { |
110 | fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { | 112 | fn doc_comments(&self) -> AstChildren<Comment> { |
111 | children(self) | 113 | children(self) |
112 | } | 114 | } |
113 | 115 | ||
114 | /// Returns the textual content of a doc comment block as a single string. | 116 | /// Returns the textual content of a doc comment block as a single string. |
115 | /// That is, strips leading `///` and joins lines | 117 | /// That is, strips leading `///` and joins lines |
116 | fn doc_comment_text(self) -> RustString { | 118 | fn doc_comment_text(&self) -> std::string::String { |
117 | self.doc_comments() | 119 | self.doc_comments() |
118 | .filter(|comment| comment.is_doc_comment()) | 120 | .filter(|comment| comment.is_doc_comment()) |
119 | .map(|comment| { | 121 | .map(|comment| { |
@@ -130,13 +132,13 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> { | |||
130 | } | 132 | } |
131 | } | 133 | } |
132 | 134 | ||
133 | impl<'a> FnDef<'a> { | 135 | impl FnDef { |
134 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 136 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
135 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) | 137 | self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) |
136 | } | 138 | } |
137 | } | 139 | } |
138 | 140 | ||
139 | impl<'a> Attr<'a> { | 141 | impl Attr { |
140 | pub fn as_atom(&self) -> Option<SmolStr> { | 142 | pub fn as_atom(&self) -> Option<SmolStr> { |
141 | let tt = self.value()?; | 143 | let tt = self.value()?; |
142 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; | 144 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; |
@@ -147,7 +149,7 @@ impl<'a> Attr<'a> { | |||
147 | } | 149 | } |
148 | } | 150 | } |
149 | 151 | ||
150 | pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> { | 152 | pub fn as_call(&self) -> Option<(SmolStr, &TokenTree)> { |
151 | let tt = self.value()?; | 153 | let tt = self.value()?; |
152 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; | 154 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; |
153 | let args = TokenTree::cast(args)?; | 155 | let args = TokenTree::cast(args)?; |
@@ -159,41 +161,7 @@ impl<'a> Attr<'a> { | |||
159 | } | 161 | } |
160 | } | 162 | } |
161 | 163 | ||
162 | impl<'a> Lifetime<'a> { | 164 | impl Comment { |
163 | pub fn text(&self) -> SmolStr { | ||
164 | self.syntax().leaf_text().unwrap().clone() | ||
165 | } | ||
166 | } | ||
167 | |||
168 | impl<'a> Char<'a> { | ||
169 | pub fn text(&self) -> &SmolStr { | ||
170 | &self.syntax().leaf_text().unwrap() | ||
171 | } | ||
172 | } | ||
173 | |||
174 | impl<'a> Byte<'a> { | ||
175 | pub fn text(&self) -> &SmolStr { | ||
176 | &self.syntax().leaf_text().unwrap() | ||
177 | } | ||
178 | } | ||
179 | |||
180 | impl<'a> ByteString<'a> { | ||
181 | pub fn text(&self) -> &SmolStr { | ||
182 | &self.syntax().leaf_text().unwrap() | ||
183 | } | ||
184 | } | ||
185 | |||
186 | impl<'a> String<'a> { | ||
187 | pub fn text(&self) -> &SmolStr { | ||
188 | &self.syntax().leaf_text().unwrap() | ||
189 | } | ||
190 | } | ||
191 | |||
192 | impl<'a> Comment<'a> { | ||
193 | pub fn text(&self) -> &SmolStr { | ||
194 | self.syntax().leaf_text().unwrap() | ||
195 | } | ||
196 | |||
197 | pub fn flavor(&self) -> CommentFlavor { | 165 | pub fn flavor(&self) -> CommentFlavor { |
198 | let text = self.text(); | 166 | let text = self.text(); |
199 | if text.starts_with("///") { | 167 | if text.starts_with("///") { |
@@ -251,50 +219,46 @@ impl CommentFlavor { | |||
251 | } | 219 | } |
252 | } | 220 | } |
253 | 221 | ||
254 | impl<'a> Whitespace<'a> { | 222 | impl Whitespace { |
255 | pub fn text(&self) -> &SmolStr { | ||
256 | &self.syntax().leaf_text().unwrap() | ||
257 | } | ||
258 | |||
259 | pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> { | 223 | pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> { |
260 | self.text().chars().filter(|&c| c == '\n').map(|_| &()) | 224 | self.text().chars().filter(|&c| c == '\n').map(|_| &()) |
261 | } | 225 | } |
262 | 226 | ||
263 | pub fn has_newlines(&self) -> bool { | 227 | pub fn has_newlines(&self) -> bool { |
264 | self.count_newlines_lazy().count() > 0 | 228 | self.text().contains('\n') |
265 | } | 229 | } |
266 | } | 230 | } |
267 | 231 | ||
268 | impl<'a> Name<'a> { | 232 | impl Name { |
269 | pub fn text(&self) -> SmolStr { | 233 | pub fn text(&self) -> &SmolStr { |
270 | let ident = self.syntax().first_child().unwrap(); | 234 | let ident = self.syntax().first_child().unwrap(); |
271 | ident.leaf_text().unwrap().clone() | 235 | ident.leaf_text().unwrap() |
272 | } | 236 | } |
273 | } | 237 | } |
274 | 238 | ||
275 | impl<'a> NameRef<'a> { | 239 | impl NameRef { |
276 | pub fn text(&self) -> SmolStr { | 240 | pub fn text(&self) -> &SmolStr { |
277 | let ident = self.syntax().first_child().unwrap(); | 241 | let ident = self.syntax().first_child().unwrap(); |
278 | ident.leaf_text().unwrap().clone() | 242 | ident.leaf_text().unwrap() |
279 | } | 243 | } |
280 | } | 244 | } |
281 | 245 | ||
282 | impl<'a> ImplBlock<'a> { | 246 | impl ImplBlock { |
283 | pub fn target_type(self) -> Option<TypeRef<'a>> { | 247 | pub fn target_type(&self) -> Option<&TypeRef> { |
284 | match self.target() { | 248 | match self.target() { |
285 | (Some(t), None) | (_, Some(t)) => Some(t), | 249 | (Some(t), None) | (_, Some(t)) => Some(t), |
286 | _ => None, | 250 | _ => None, |
287 | } | 251 | } |
288 | } | 252 | } |
289 | 253 | ||
290 | pub fn target_trait(self) -> Option<TypeRef<'a>> { | 254 | pub fn target_trait(&self) -> Option<&TypeRef> { |
291 | match self.target() { | 255 | match self.target() { |
292 | (Some(t), Some(_)) => Some(t), | 256 | (Some(t), Some(_)) => Some(t), |
293 | _ => None, | 257 | _ => None, |
294 | } | 258 | } |
295 | } | 259 | } |
296 | 260 | ||
297 | fn target(self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) { | 261 | fn target(&self) -> (Option<&TypeRef>, Option<&TypeRef>) { |
298 | let mut types = children(self); | 262 | let mut types = children(self); |
299 | let first = types.next(); | 263 | let first = types.next(); |
300 | let second = types.next(); | 264 | let second = types.next(); |
@@ -302,8 +266,8 @@ impl<'a> ImplBlock<'a> { | |||
302 | } | 266 | } |
303 | } | 267 | } |
304 | 268 | ||
305 | impl<'a> Module<'a> { | 269 | impl Module { |
306 | pub fn has_semi(self) -> bool { | 270 | pub fn has_semi(&self) -> bool { |
307 | match self.syntax().last_child() { | 271 | match self.syntax().last_child() { |
308 | None => false, | 272 | None => false, |
309 | Some(node) => node.kind() == SEMI, | 273 | Some(node) => node.kind() == SEMI, |
@@ -311,8 +275,8 @@ impl<'a> Module<'a> { | |||
311 | } | 275 | } |
312 | } | 276 | } |
313 | 277 | ||
314 | impl<'a> LetStmt<'a> { | 278 | impl LetStmt { |
315 | pub fn has_semi(self) -> bool { | 279 | pub fn has_semi(&self) -> bool { |
316 | match self.syntax().last_child() { | 280 | match self.syntax().last_child() { |
317 | None => false, | 281 | None => false, |
318 | Some(node) => node.kind() == SEMI, | 282 | Some(node) => node.kind() == SEMI, |
@@ -320,35 +284,35 @@ impl<'a> LetStmt<'a> { | |||
320 | } | 284 | } |
321 | } | 285 | } |
322 | 286 | ||
323 | impl<'a> IfExpr<'a> { | 287 | impl IfExpr { |
324 | pub fn then_branch(self) -> Option<Block<'a>> { | 288 | pub fn then_branch(&self) -> Option<&Block> { |
325 | self.blocks().nth(0) | 289 | self.blocks().nth(0) |
326 | } | 290 | } |
327 | pub fn else_branch(self) -> Option<Block<'a>> { | 291 | pub fn else_branch(&self) -> Option<&Block> { |
328 | self.blocks().nth(1) | 292 | self.blocks().nth(1) |
329 | } | 293 | } |
330 | fn blocks(self) -> AstChildren<'a, Block<'a>> { | 294 | fn blocks(&self) -> AstChildren<Block> { |
331 | children(self) | 295 | children(self) |
332 | } | 296 | } |
333 | } | 297 | } |
334 | 298 | ||
335 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 299 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
336 | pub enum PathSegmentKind<'a> { | 300 | pub enum PathSegmentKind<'a> { |
337 | Name(NameRef<'a>), | 301 | Name(&'a NameRef), |
338 | SelfKw, | 302 | SelfKw, |
339 | SuperKw, | 303 | SuperKw, |
340 | CrateKw, | 304 | CrateKw, |
341 | } | 305 | } |
342 | 306 | ||
343 | impl<'a> PathSegment<'a> { | 307 | impl PathSegment { |
344 | pub fn parent_path(self) -> Path<'a> { | 308 | pub fn parent_path(&self) -> &Path { |
345 | self.syntax() | 309 | self.syntax() |
346 | .parent() | 310 | .parent() |
347 | .and_then(Path::cast) | 311 | .and_then(Path::cast) |
348 | .expect("segments are always nested in paths") | 312 | .expect("segments are always nested in paths") |
349 | } | 313 | } |
350 | 314 | ||
351 | pub fn kind(self) -> Option<PathSegmentKind<'a>> { | 315 | pub fn kind(&self) -> Option<PathSegmentKind> { |
352 | let res = if let Some(name_ref) = self.name_ref() { | 316 | let res = if let Some(name_ref) = self.name_ref() { |
353 | PathSegmentKind::Name(name_ref) | 317 | PathSegmentKind::Name(name_ref) |
354 | } else { | 318 | } else { |
@@ -363,20 +327,20 @@ impl<'a> PathSegment<'a> { | |||
363 | } | 327 | } |
364 | } | 328 | } |
365 | 329 | ||
366 | impl<'a> Path<'a> { | 330 | impl Path { |
367 | pub fn parent_path(self) -> Option<Path<'a>> { | 331 | pub fn parent_path(&self) -> Option<&Path> { |
368 | self.syntax().parent().and_then(Path::cast) | 332 | self.syntax().parent().and_then(Path::cast) |
369 | } | 333 | } |
370 | } | 334 | } |
371 | 335 | ||
372 | impl<'a> UseTree<'a> { | 336 | impl UseTree { |
373 | pub fn has_star(self) -> bool { | 337 | pub fn has_star(&self) -> bool { |
374 | self.syntax().children().any(|it| it.kind() == STAR) | 338 | self.syntax().children().any(|it| it.kind() == STAR) |
375 | } | 339 | } |
376 | } | 340 | } |
377 | 341 | ||
378 | impl<'a> UseTreeList<'a> { | 342 | impl UseTreeList { |
379 | pub fn parent_use_tree(self) -> UseTree<'a> { | 343 | pub fn parent_use_tree(&self) -> &UseTree { |
380 | self.syntax() | 344 | self.syntax() |
381 | .parent() | 345 | .parent() |
382 | .and_then(UseTree::cast) | 346 | .and_then(UseTree::cast) |
@@ -384,22 +348,22 @@ impl<'a> UseTreeList<'a> { | |||
384 | } | 348 | } |
385 | } | 349 | } |
386 | 350 | ||
387 | fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { | 351 | fn child_opt<P: AstNode, C: AstNode>(parent: &P) -> Option<&C> { |
388 | children(parent).next() | 352 | children(parent).next() |
389 | } | 353 | } |
390 | 354 | ||
391 | fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> { | 355 | fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> { |
392 | AstChildren::new(parent.syntax()) | 356 | AstChildren::new(parent.syntax()) |
393 | } | 357 | } |
394 | 358 | ||
395 | #[derive(Debug)] | 359 | #[derive(Debug)] |
396 | pub struct AstChildren<'a, N> { | 360 | pub struct AstChildren<'a, N> { |
397 | inner: SyntaxNodeChildren<RefRoot<'a>>, | 361 | inner: SyntaxNodeChildren<'a>, |
398 | ph: PhantomData<N>, | 362 | ph: PhantomData<N>, |
399 | } | 363 | } |
400 | 364 | ||
401 | impl<'a, N> AstChildren<'a, N> { | 365 | impl<'a, N> AstChildren<'a, N> { |
402 | fn new(parent: SyntaxNodeRef<'a>) -> Self { | 366 | fn new(parent: &'a SyntaxNode) -> Self { |
403 | AstChildren { | 367 | AstChildren { |
404 | inner: parent.children(), | 368 | inner: parent.children(), |
405 | ph: PhantomData, | 369 | ph: PhantomData, |
@@ -407,9 +371,9 @@ impl<'a, N> AstChildren<'a, N> { | |||
407 | } | 371 | } |
408 | } | 372 | } |
409 | 373 | ||
410 | impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | 374 | impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> { |
411 | type Item = N; | 375 | type Item = &'a N; |
412 | fn next(&mut self) -> Option<N> { | 376 | fn next(&mut self) -> Option<&'a N> { |
413 | loop { | 377 | loop { |
414 | if let Some(n) = N::cast(self.inner.next()?) { | 378 | if let Some(n) = N::cast(self.inner.next()?) { |
415 | return Some(n); | 379 | return Some(n); |
@@ -420,13 +384,13 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | |||
420 | 384 | ||
421 | #[derive(Debug, Clone, PartialEq, Eq)] | 385 | #[derive(Debug, Clone, PartialEq, Eq)] |
422 | pub enum StructFlavor<'a> { | 386 | pub enum StructFlavor<'a> { |
423 | Tuple(PosFieldList<'a>), | 387 | Tuple(&'a PosFieldList), |
424 | Named(NamedFieldDefList<'a>), | 388 | Named(&'a NamedFieldDefList), |
425 | Unit, | 389 | Unit, |
426 | } | 390 | } |
427 | 391 | ||
428 | impl<'a> StructFlavor<'a> { | 392 | impl StructFlavor<'_> { |
429 | fn from_node<N: AstNode<'a>>(node: N) -> StructFlavor<'a> { | 393 | fn from_node<N: AstNode>(node: &N) -> StructFlavor { |
430 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { | 394 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { |
431 | StructFlavor::Named(nfdl) | 395 | StructFlavor::Named(nfdl) |
432 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { | 396 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { |
@@ -437,31 +401,31 @@ impl<'a> StructFlavor<'a> { | |||
437 | } | 401 | } |
438 | } | 402 | } |
439 | 403 | ||
440 | impl<'a> StructDef<'a> { | 404 | impl StructDef { |
441 | pub fn flavor(self) -> StructFlavor<'a> { | 405 | pub fn flavor(&self) -> StructFlavor { |
442 | StructFlavor::from_node(self) | 406 | StructFlavor::from_node(self) |
443 | } | 407 | } |
444 | } | 408 | } |
445 | 409 | ||
446 | impl<'a> EnumVariant<'a> { | 410 | impl EnumVariant { |
447 | pub fn flavor(self) -> StructFlavor<'a> { | 411 | pub fn flavor(&self) -> StructFlavor { |
448 | StructFlavor::from_node(self) | 412 | StructFlavor::from_node(self) |
449 | } | 413 | } |
450 | } | 414 | } |
451 | 415 | ||
452 | impl<'a> PointerType<'a> { | 416 | impl PointerType { |
453 | pub fn is_mut(&self) -> bool { | 417 | pub fn is_mut(&self) -> bool { |
454 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 418 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
455 | } | 419 | } |
456 | } | 420 | } |
457 | 421 | ||
458 | impl<'a> ReferenceType<'a> { | 422 | impl ReferenceType { |
459 | pub fn is_mut(&self) -> bool { | 423 | pub fn is_mut(&self) -> bool { |
460 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 424 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
461 | } | 425 | } |
462 | } | 426 | } |
463 | 427 | ||
464 | impl<'a> RefExpr<'a> { | 428 | impl RefExpr { |
465 | pub fn is_mut(&self) -> bool { | 429 | pub fn is_mut(&self) -> bool { |
466 | self.syntax().children().any(|n| n.kind() == MUT_KW) | 430 | self.syntax().children().any(|n| n.kind() == MUT_KW) |
467 | } | 431 | } |
@@ -477,7 +441,7 @@ pub enum PrefixOp { | |||
477 | Neg, | 441 | Neg, |
478 | } | 442 | } |
479 | 443 | ||
480 | impl<'a> PrefixExpr<'a> { | 444 | impl PrefixExpr { |
481 | pub fn op(&self) -> Option<PrefixOp> { | 445 | pub fn op(&self) -> Option<PrefixOp> { |
482 | match self.syntax().first_child()?.kind() { | 446 | match self.syntax().first_child()?.kind() { |
483 | STAR => Some(PrefixOp::Deref), | 447 | STAR => Some(PrefixOp::Deref), |
@@ -504,10 +468,55 @@ pub enum BinOp { | |||
504 | LesserTest, | 468 | LesserTest, |
505 | /// The `>` operator for comparison | 469 | /// The `>` operator for comparison |
506 | GreaterTest, | 470 | GreaterTest, |
507 | // TODO: lots of others | 471 | /// The `+` operator for addition |
508 | } | 472 | Addition, |
509 | 473 | /// The `*` operator for multiplication | |
510 | impl<'a> BinExpr<'a> { | 474 | Multiplication, |
475 | /// The `-` operator for subtraction | ||
476 | Subtraction, | ||
477 | /// The `/` operator for division | ||
478 | Division, | ||
479 | /// The `%` operator for remainder after division | ||
480 | Remainder, | ||
481 | /// The `<<` operator for left shift | ||
482 | LeftShift, | ||
483 | /// The `>>` operator for right shift | ||
484 | RightShift, | ||
485 | /// The `^` operator for bitwise XOR | ||
486 | BitwiseXor, | ||
487 | /// The `|` operator for bitwise OR | ||
488 | BitwiseOr, | ||
489 | /// The `&` operator for bitwise AND | ||
490 | BitwiseAnd, | ||
491 | /// The `..` operator for right-open ranges | ||
492 | RangeRightOpen, | ||
493 | /// The `..=` operator for right-closed ranges | ||
494 | RangeRightClosed, | ||
495 | /// The `=` operator for assignment | ||
496 | Assignment, | ||
497 | /// The `+=` operator for assignment after additon | ||
498 | AddAssign, | ||
499 | /// The `/=` operator for assignment after division | ||
500 | DivAssign, | ||
501 | /// The `*=` operator for assignment after multiplication | ||
502 | MulAssign, | ||
503 | /// The `%=` operator for assignment after remainders | ||
504 | RemAssign, | ||
505 | /// The `>>=` operator for assignment after shifting right | ||
506 | ShrAssign, | ||
507 | /// The `<<=` operator for assignment after shifting left | ||
508 | ShlAssign, | ||
509 | /// The `-=` operator for assignment after subtraction | ||
510 | SubAssign, | ||
511 | /// The `|=` operator for assignment after bitwise OR | ||
512 | BitOrAssign, | ||
513 | /// The `&=` operator for assignment after bitwise AND | ||
514 | BitAndAssign, | ||
515 | /// The `^=` operator for assignment after bitwise XOR | ||
516 | BitXorAssign, | ||
517 | } | ||
518 | |||
519 | impl BinExpr { | ||
511 | pub fn op(&self) -> Option<BinOp> { | 520 | pub fn op(&self) -> Option<BinOp> { |
512 | self.syntax() | 521 | self.syntax() |
513 | .children() | 522 | .children() |
@@ -519,20 +528,43 @@ impl<'a> BinExpr<'a> { | |||
519 | GTEQ => Some(BinOp::GreaterEqualTest), | 528 | GTEQ => Some(BinOp::GreaterEqualTest), |
520 | L_ANGLE => Some(BinOp::LesserTest), | 529 | L_ANGLE => Some(BinOp::LesserTest), |
521 | R_ANGLE => Some(BinOp::GreaterTest), | 530 | R_ANGLE => Some(BinOp::GreaterTest), |
531 | PLUS => Some(BinOp::Addition), | ||
532 | STAR => Some(BinOp::Multiplication), | ||
533 | MINUS => Some(BinOp::Subtraction), | ||
534 | SLASH => Some(BinOp::Division), | ||
535 | PERCENT => Some(BinOp::Remainder), | ||
536 | SHL => Some(BinOp::LeftShift), | ||
537 | SHR => Some(BinOp::RightShift), | ||
538 | CARET => Some(BinOp::BitwiseXor), | ||
539 | PIPE => Some(BinOp::BitwiseOr), | ||
540 | AMP => Some(BinOp::BitwiseAnd), | ||
541 | DOTDOT => Some(BinOp::RangeRightOpen), | ||
542 | DOTDOTEQ => Some(BinOp::RangeRightClosed), | ||
543 | EQ => Some(BinOp::Assignment), | ||
544 | PLUSEQ => Some(BinOp::AddAssign), | ||
545 | SLASHEQ => Some(BinOp::DivAssign), | ||
546 | STAREQ => Some(BinOp::MulAssign), | ||
547 | PERCENTEQ => Some(BinOp::RemAssign), | ||
548 | SHREQ => Some(BinOp::ShrAssign), | ||
549 | SHLEQ => Some(BinOp::ShlAssign), | ||
550 | MINUSEQ => Some(BinOp::SubAssign), | ||
551 | PIPEEQ => Some(BinOp::BitOrAssign), | ||
552 | AMPEQ => Some(BinOp::BitAndAssign), | ||
553 | CARETEQ => Some(BinOp::BitXorAssign), | ||
522 | _ => None, | 554 | _ => None, |
523 | }) | 555 | }) |
524 | .next() | 556 | .next() |
525 | } | 557 | } |
526 | 558 | ||
527 | pub fn lhs(self) -> Option<Expr<'a>> { | 559 | pub fn lhs(&self) -> Option<&Expr> { |
528 | children(self).nth(0) | 560 | children(self).nth(0) |
529 | } | 561 | } |
530 | 562 | ||
531 | pub fn rhs(self) -> Option<Expr<'a>> { | 563 | pub fn rhs(&self) -> Option<&Expr> { |
532 | children(self).nth(1) | 564 | children(self).nth(1) |
533 | } | 565 | } |
534 | 566 | ||
535 | pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) { | 567 | pub fn sub_exprs(&self) -> (Option<&Expr>, Option<&Expr>) { |
536 | let mut children = children(self); | 568 | let mut children = children(self); |
537 | let first = children.next(); | 569 | let first = children.next(); |
538 | let second = children.next(); | 570 | let second = children.next(); |
@@ -550,7 +582,7 @@ pub enum SelfParamFlavor { | |||
550 | MutRef, | 582 | MutRef, |
551 | } | 583 | } |
552 | 584 | ||
553 | impl<'a> SelfParam<'a> { | 585 | impl SelfParam { |
554 | pub fn flavor(&self) -> SelfParamFlavor { | 586 | pub fn flavor(&self) -> SelfParamFlavor { |
555 | let borrowed = self.syntax().children().any(|n| n.kind() == AMP); | 587 | let borrowed = self.syntax().children().any(|n| n.kind() == AMP); |
556 | if borrowed { | 588 | if borrowed { |
@@ -573,7 +605,7 @@ impl<'a> SelfParam<'a> { | |||
573 | 605 | ||
574 | #[test] | 606 | #[test] |
575 | fn test_doc_comment_of_items() { | 607 | fn test_doc_comment_of_items() { |
576 | let file = SourceFileNode::parse( | 608 | let file = SourceFile::parse( |
577 | r#" | 609 | r#" |
578 | //! doc | 610 | //! doc |
579 | // non-doc | 611 | // non-doc |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 24f72393a..547e3c003 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -9,4648 +9,3394 @@ | |||
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 ast::AstToken for Byte {} |
292 | impl Byte {} | ||
423 | 293 | ||
424 | // ByteString | 294 | // ByteString |
425 | #[derive(Debug, Clone, Copy,)] | 295 | #[derive(Debug, PartialEq, Eq, Hash)] |
426 | pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 296 | #[repr(transparent)] |
427 | pub(crate) syntax: SyntaxNode<R>, | 297 | pub struct ByteString { |
428 | } | 298 | 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 | } | 299 | } |
434 | impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {} | 300 | unsafe impl TransparentNewType for ByteString { |
435 | impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> { | 301 | type Repr = rowan::SyntaxNode<RaTypes>; |
436 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
437 | } | 302 | } |
438 | 303 | ||
439 | impl<'a> AstNode<'a> for ByteString<'a> { | 304 | impl AstNode for ByteString { |
440 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 305 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
441 | match syntax.kind() { | 306 | match syntax.kind() { |
442 | BYTE_STRING => Some(ByteString { syntax }), | 307 | BYTE_STRING => Some(ByteString::from_repr(syntax.into_repr())), |
443 | _ => None, | 308 | _ => None, |
444 | } | 309 | } |
445 | } | 310 | } |
446 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 311 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
447 | } | 312 | 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 | } | 313 | } |
457 | 314 | ||
458 | 315 | ||
459 | impl<'a> ByteString<'a> {} | 316 | impl ast::AstToken for ByteString {} |
317 | impl ByteString {} | ||
460 | 318 | ||
461 | // CallExpr | 319 | // CallExpr |
462 | #[derive(Debug, Clone, Copy,)] | 320 | #[derive(Debug, PartialEq, Eq, Hash)] |
463 | pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 321 | #[repr(transparent)] |
464 | pub(crate) syntax: SyntaxNode<R>, | 322 | pub struct CallExpr { |
465 | } | 323 | 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 | } | 324 | } |
471 | impl<R: TreeRoot<RaTypes>> Eq for CallExprNode<R> {} | 325 | unsafe impl TransparentNewType for CallExpr { |
472 | impl<R: TreeRoot<RaTypes>> Hash for CallExprNode<R> { | 326 | type Repr = rowan::SyntaxNode<RaTypes>; |
473 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
474 | } | 327 | } |
475 | 328 | ||
476 | impl<'a> AstNode<'a> for CallExpr<'a> { | 329 | impl AstNode for CallExpr { |
477 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 330 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
478 | match syntax.kind() { | 331 | match syntax.kind() { |
479 | CALL_EXPR => Some(CallExpr { syntax }), | 332 | CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())), |
480 | _ => None, | 333 | _ => None, |
481 | } | 334 | } |
482 | } | 335 | } |
483 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 336 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
484 | } | 337 | 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 | } | 338 | } |
494 | 339 | ||
495 | 340 | ||
496 | impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} | 341 | impl ast::ArgListOwner for CallExpr {} |
497 | impl<'a> CallExpr<'a> { | 342 | impl CallExpr { |
498 | pub fn expr(self) -> Option<Expr<'a>> { | 343 | pub fn expr(&self) -> Option<&Expr> { |
499 | super::child_opt(self) | 344 | super::child_opt(self) |
500 | } | 345 | } |
501 | } | 346 | } |
502 | 347 | ||
503 | // CastExpr | 348 | // CastExpr |
504 | #[derive(Debug, Clone, Copy,)] | 349 | #[derive(Debug, PartialEq, Eq, Hash)] |
505 | pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 350 | #[repr(transparent)] |
506 | pub(crate) syntax: SyntaxNode<R>, | 351 | pub struct CastExpr { |
352 | pub(crate) syntax: SyntaxNode, | ||
507 | } | 353 | } |
508 | pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; | 354 | unsafe impl TransparentNewType for CastExpr { |
509 | 355 | 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 | } | 356 | } |
517 | 357 | ||
518 | impl<'a> AstNode<'a> for CastExpr<'a> { | 358 | impl AstNode for CastExpr { |
519 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 359 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
520 | match syntax.kind() { | 360 | match syntax.kind() { |
521 | CAST_EXPR => Some(CastExpr { syntax }), | 361 | CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())), |
522 | _ => None, | 362 | _ => None, |
523 | } | 363 | } |
524 | } | 364 | } |
525 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 365 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
526 | } | 366 | 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 | } | 367 | } |
536 | 368 | ||
537 | 369 | ||
538 | impl<'a> CastExpr<'a> { | 370 | impl CastExpr { |
539 | pub fn expr(self) -> Option<Expr<'a>> { | 371 | pub fn expr(&self) -> Option<&Expr> { |
540 | super::child_opt(self) | 372 | super::child_opt(self) |
541 | } | 373 | } |
542 | 374 | ||
543 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 375 | pub fn type_ref(&self) -> Option<&TypeRef> { |
544 | super::child_opt(self) | 376 | super::child_opt(self) |
545 | } | 377 | } |
546 | } | 378 | } |
547 | 379 | ||
548 | // Char | 380 | // Char |
549 | #[derive(Debug, Clone, Copy,)] | 381 | #[derive(Debug, PartialEq, Eq, Hash)] |
550 | pub struct CharNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 382 | #[repr(transparent)] |
551 | pub(crate) syntax: SyntaxNode<R>, | 383 | pub struct Char { |
552 | } | 384 | 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 | } | 385 | } |
558 | impl<R: TreeRoot<RaTypes>> Eq for CharNode<R> {} | 386 | unsafe impl TransparentNewType for Char { |
559 | impl<R: TreeRoot<RaTypes>> Hash for CharNode<R> { | 387 | type Repr = rowan::SyntaxNode<RaTypes>; |
560 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
561 | } | 388 | } |
562 | 389 | ||
563 | impl<'a> AstNode<'a> for Char<'a> { | 390 | impl AstNode for Char { |
564 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 391 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
565 | match syntax.kind() { | 392 | match syntax.kind() { |
566 | CHAR => Some(Char { syntax }), | 393 | CHAR => Some(Char::from_repr(syntax.into_repr())), |
567 | _ => None, | 394 | _ => None, |
568 | } | 395 | } |
569 | } | 396 | } |
570 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 397 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
398 | fn to_owned(&self) -> TreePtr<Char> { TreePtr::cast(self.syntax.to_owned()) } | ||
571 | } | 399 | } |
572 | 400 | ||
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 | 401 | ||
582 | 402 | impl ast::AstToken for Char {} | |
583 | impl<'a> Char<'a> {} | 403 | impl Char {} |
584 | 404 | ||
585 | // Comment | 405 | // Comment |
586 | #[derive(Debug, Clone, Copy,)] | 406 | #[derive(Debug, PartialEq, Eq, Hash)] |
587 | pub struct CommentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 407 | #[repr(transparent)] |
588 | pub(crate) syntax: SyntaxNode<R>, | 408 | pub struct Comment { |
589 | } | 409 | 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 | } | 410 | } |
595 | impl<R: TreeRoot<RaTypes>> Eq for CommentNode<R> {} | 411 | unsafe impl TransparentNewType for Comment { |
596 | impl<R: TreeRoot<RaTypes>> Hash for CommentNode<R> { | 412 | type Repr = rowan::SyntaxNode<RaTypes>; |
597 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
598 | } | 413 | } |
599 | 414 | ||
600 | impl<'a> AstNode<'a> for Comment<'a> { | 415 | impl AstNode for Comment { |
601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 416 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
602 | match syntax.kind() { | 417 | match syntax.kind() { |
603 | COMMENT => Some(Comment { syntax }), | 418 | COMMENT => Some(Comment::from_repr(syntax.into_repr())), |
604 | _ => None, | 419 | _ => None, |
605 | } | 420 | } |
606 | } | 421 | } |
607 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 422 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
608 | } | 423 | 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 | } | 424 | } |
618 | 425 | ||
619 | 426 | ||
620 | impl<'a> Comment<'a> {} | 427 | impl ast::AstToken for Comment {} |
428 | impl Comment {} | ||
621 | 429 | ||
622 | // Condition | 430 | // Condition |
623 | #[derive(Debug, Clone, Copy,)] | 431 | #[derive(Debug, PartialEq, Eq, Hash)] |
624 | pub struct ConditionNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 432 | #[repr(transparent)] |
625 | pub(crate) syntax: SyntaxNode<R>, | 433 | pub struct Condition { |
434 | pub(crate) syntax: SyntaxNode, | ||
626 | } | 435 | } |
627 | pub type Condition<'a> = ConditionNode<RefRoot<'a>>; | 436 | unsafe impl TransparentNewType for Condition { |
628 | 437 | 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 | } | 438 | } |
636 | 439 | ||
637 | impl<'a> AstNode<'a> for Condition<'a> { | 440 | impl AstNode for Condition { |
638 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 441 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
639 | match syntax.kind() { | 442 | match syntax.kind() { |
640 | CONDITION => Some(Condition { syntax }), | 443 | CONDITION => Some(Condition::from_repr(syntax.into_repr())), |
641 | _ => None, | 444 | _ => None, |
642 | } | 445 | } |
643 | } | 446 | } |
644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 447 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
645 | } | 448 | 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 | } | 449 | } |
655 | 450 | ||
656 | 451 | ||
657 | impl<'a> Condition<'a> { | 452 | impl Condition { |
658 | pub fn pat(self) -> Option<Pat<'a>> { | 453 | pub fn pat(&self) -> Option<&Pat> { |
659 | super::child_opt(self) | 454 | super::child_opt(self) |
660 | } | 455 | } |
661 | 456 | ||
662 | pub fn expr(self) -> Option<Expr<'a>> { | 457 | pub fn expr(&self) -> Option<&Expr> { |
663 | super::child_opt(self) | 458 | super::child_opt(self) |
664 | } | 459 | } |
665 | } | 460 | } |
666 | 461 | ||
667 | // ConstDef | 462 | // ConstDef |
668 | #[derive(Debug, Clone, Copy,)] | 463 | #[derive(Debug, PartialEq, Eq, Hash)] |
669 | pub struct ConstDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 464 | #[repr(transparent)] |
670 | pub(crate) syntax: SyntaxNode<R>, | 465 | pub struct ConstDef { |
466 | pub(crate) syntax: SyntaxNode, | ||
671 | } | 467 | } |
672 | pub type ConstDef<'a> = ConstDefNode<RefRoot<'a>>; | 468 | unsafe impl TransparentNewType for ConstDef { |
673 | 469 | 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 | } | 470 | } |
681 | 471 | ||
682 | impl<'a> AstNode<'a> for ConstDef<'a> { | 472 | impl AstNode for ConstDef { |
683 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 473 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
684 | match syntax.kind() { | 474 | match syntax.kind() { |
685 | CONST_DEF => Some(ConstDef { syntax }), | 475 | CONST_DEF => Some(ConstDef::from_repr(syntax.into_repr())), |
686 | _ => None, | 476 | _ => None, |
687 | } | 477 | } |
688 | } | 478 | } |
689 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 479 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
690 | } | 480 | 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 | } | 481 | } |
700 | 482 | ||
701 | 483 | ||
702 | impl<'a> ast::VisibilityOwner<'a> for ConstDef<'a> {} | 484 | impl ast::VisibilityOwner for ConstDef {} |
703 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} | 485 | impl ast::NameOwner for ConstDef {} |
704 | impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} | 486 | impl ast::TypeParamsOwner for ConstDef {} |
705 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} | 487 | impl ast::AttrsOwner for ConstDef {} |
706 | impl<'a> ast::DocCommentsOwner<'a> for ConstDef<'a> {} | 488 | impl ast::DocCommentsOwner for ConstDef {} |
707 | impl<'a> ConstDef<'a> {} | 489 | impl ConstDef {} |
708 | 490 | ||
709 | // ContinueExpr | 491 | // ContinueExpr |
710 | #[derive(Debug, Clone, Copy,)] | 492 | #[derive(Debug, PartialEq, Eq, Hash)] |
711 | pub struct ContinueExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 493 | #[repr(transparent)] |
712 | pub(crate) syntax: SyntaxNode<R>, | 494 | pub struct ContinueExpr { |
495 | pub(crate) syntax: SyntaxNode, | ||
713 | } | 496 | } |
714 | pub type ContinueExpr<'a> = ContinueExprNode<RefRoot<'a>>; | 497 | unsafe impl TransparentNewType for ContinueExpr { |
715 | 498 | 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 | } | 499 | } |
723 | 500 | ||
724 | impl<'a> AstNode<'a> for ContinueExpr<'a> { | 501 | impl AstNode for ContinueExpr { |
725 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 502 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
726 | match syntax.kind() { | 503 | match syntax.kind() { |
727 | CONTINUE_EXPR => Some(ContinueExpr { syntax }), | 504 | CONTINUE_EXPR => Some(ContinueExpr::from_repr(syntax.into_repr())), |
728 | _ => None, | 505 | _ => None, |
729 | } | 506 | } |
730 | } | 507 | } |
731 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 508 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
509 | fn to_owned(&self) -> TreePtr<ContinueExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
732 | } | 510 | } |
733 | 511 | ||
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 | 512 | ||
743 | 513 | impl ContinueExpr {} | |
744 | impl<'a> ContinueExpr<'a> {} | ||
745 | 514 | ||
746 | // DynTraitType | 515 | // DynTraitType |
747 | #[derive(Debug, Clone, Copy,)] | 516 | #[derive(Debug, PartialEq, Eq, Hash)] |
748 | pub struct DynTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 517 | #[repr(transparent)] |
749 | pub(crate) syntax: SyntaxNode<R>, | 518 | pub struct DynTraitType { |
750 | } | 519 | 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 | } | 520 | } |
756 | impl<R: TreeRoot<RaTypes>> Eq for DynTraitTypeNode<R> {} | 521 | unsafe impl TransparentNewType for DynTraitType { |
757 | impl<R: TreeRoot<RaTypes>> Hash for DynTraitTypeNode<R> { | 522 | type Repr = rowan::SyntaxNode<RaTypes>; |
758 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
759 | } | 523 | } |
760 | 524 | ||
761 | impl<'a> AstNode<'a> for DynTraitType<'a> { | 525 | impl AstNode for DynTraitType { |
762 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 526 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
763 | match syntax.kind() { | 527 | match syntax.kind() { |
764 | DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), | 528 | DYN_TRAIT_TYPE => Some(DynTraitType::from_repr(syntax.into_repr())), |
765 | _ => None, | 529 | _ => None, |
766 | } | 530 | } |
767 | } | 531 | } |
768 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 532 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
533 | fn to_owned(&self) -> TreePtr<DynTraitType> { TreePtr::cast(self.syntax.to_owned()) } | ||
769 | } | 534 | } |
770 | 535 | ||
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 | 536 | ||
780 | 537 | impl DynTraitType {} | |
781 | impl<'a> DynTraitType<'a> {} | ||
782 | 538 | ||
783 | // EnumDef | 539 | // EnumDef |
784 | #[derive(Debug, Clone, Copy,)] | 540 | #[derive(Debug, PartialEq, Eq, Hash)] |
785 | pub struct EnumDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 541 | #[repr(transparent)] |
786 | pub(crate) syntax: SyntaxNode<R>, | 542 | pub struct EnumDef { |
787 | } | 543 | 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 | } | 544 | } |
793 | impl<R: TreeRoot<RaTypes>> Eq for EnumDefNode<R> {} | 545 | unsafe impl TransparentNewType for EnumDef { |
794 | impl<R: TreeRoot<RaTypes>> Hash for EnumDefNode<R> { | 546 | type Repr = rowan::SyntaxNode<RaTypes>; |
795 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
796 | } | 547 | } |
797 | 548 | ||
798 | impl<'a> AstNode<'a> for EnumDef<'a> { | 549 | impl AstNode for EnumDef { |
799 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 550 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
800 | match syntax.kind() { | 551 | match syntax.kind() { |
801 | ENUM_DEF => Some(EnumDef { syntax }), | 552 | ENUM_DEF => Some(EnumDef::from_repr(syntax.into_repr())), |
802 | _ => None, | 553 | _ => None, |
803 | } | 554 | } |
804 | } | 555 | } |
805 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 556 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
806 | } | 557 | 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 | } | 558 | } |
816 | 559 | ||
817 | 560 | ||
818 | impl<'a> ast::VisibilityOwner<'a> for EnumDef<'a> {} | 561 | impl ast::VisibilityOwner for EnumDef {} |
819 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} | 562 | impl ast::NameOwner for EnumDef {} |
820 | impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} | 563 | impl ast::TypeParamsOwner for EnumDef {} |
821 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} | 564 | impl ast::AttrsOwner for EnumDef {} |
822 | impl<'a> ast::DocCommentsOwner<'a> for EnumDef<'a> {} | 565 | impl ast::DocCommentsOwner for EnumDef {} |
823 | impl<'a> EnumDef<'a> { | 566 | impl EnumDef { |
824 | pub fn variant_list(self) -> Option<EnumVariantList<'a>> { | 567 | pub fn variant_list(&self) -> Option<&EnumVariantList> { |
825 | super::child_opt(self) | 568 | super::child_opt(self) |
826 | } | 569 | } |
827 | } | 570 | } |
828 | 571 | ||
829 | // EnumVariant | 572 | // EnumVariant |
830 | #[derive(Debug, Clone, Copy,)] | 573 | #[derive(Debug, PartialEq, Eq, Hash)] |
831 | pub struct EnumVariantNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 574 | #[repr(transparent)] |
832 | pub(crate) syntax: SyntaxNode<R>, | 575 | pub struct EnumVariant { |
576 | pub(crate) syntax: SyntaxNode, | ||
833 | } | 577 | } |
834 | pub type EnumVariant<'a> = EnumVariantNode<RefRoot<'a>>; | 578 | unsafe impl TransparentNewType for EnumVariant { |
835 | 579 | 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 | } | 580 | } |
843 | 581 | ||
844 | impl<'a> AstNode<'a> for EnumVariant<'a> { | 582 | impl AstNode for EnumVariant { |
845 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 583 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
846 | match syntax.kind() { | 584 | match syntax.kind() { |
847 | ENUM_VARIANT => Some(EnumVariant { syntax }), | 585 | ENUM_VARIANT => Some(EnumVariant::from_repr(syntax.into_repr())), |
848 | _ => None, | 586 | _ => None, |
849 | } | 587 | } |
850 | } | 588 | } |
851 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 589 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
852 | } | 590 | 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 | } | 591 | } |
862 | 592 | ||
863 | 593 | ||
864 | impl<'a> ast::NameOwner<'a> for EnumVariant<'a> {} | 594 | impl ast::NameOwner for EnumVariant {} |
865 | impl<'a> EnumVariant<'a> { | 595 | impl EnumVariant { |
866 | pub fn expr(self) -> Option<Expr<'a>> { | 596 | pub fn expr(&self) -> Option<&Expr> { |
867 | super::child_opt(self) | 597 | super::child_opt(self) |
868 | } | 598 | } |
869 | } | 599 | } |
870 | 600 | ||
871 | // EnumVariantList | 601 | // EnumVariantList |
872 | #[derive(Debug, Clone, Copy,)] | 602 | #[derive(Debug, PartialEq, Eq, Hash)] |
873 | pub struct EnumVariantListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 603 | #[repr(transparent)] |
874 | pub(crate) syntax: SyntaxNode<R>, | 604 | pub struct EnumVariantList { |
875 | } | 605 | 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 | } | 606 | } |
881 | impl<R: TreeRoot<RaTypes>> Eq for EnumVariantListNode<R> {} | 607 | unsafe impl TransparentNewType for EnumVariantList { |
882 | impl<R: TreeRoot<RaTypes>> Hash for EnumVariantListNode<R> { | 608 | type Repr = rowan::SyntaxNode<RaTypes>; |
883 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
884 | } | 609 | } |
885 | 610 | ||
886 | impl<'a> AstNode<'a> for EnumVariantList<'a> { | 611 | impl AstNode for EnumVariantList { |
887 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 612 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
888 | match syntax.kind() { | 613 | match syntax.kind() { |
889 | ENUM_VARIANT_LIST => Some(EnumVariantList { syntax }), | 614 | ENUM_VARIANT_LIST => Some(EnumVariantList::from_repr(syntax.into_repr())), |
890 | _ => None, | 615 | _ => None, |
891 | } | 616 | } |
892 | } | 617 | } |
893 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 618 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
619 | fn to_owned(&self) -> TreePtr<EnumVariantList> { TreePtr::cast(self.syntax.to_owned()) } | ||
894 | } | 620 | } |
895 | 621 | ||
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 | 622 | ||
905 | 623 | impl EnumVariantList { | |
906 | impl<'a> EnumVariantList<'a> { | 624 | pub fn variants(&self) -> impl Iterator<Item = &EnumVariant> { |
907 | pub fn variants(self) -> impl Iterator<Item = EnumVariant<'a>> + 'a { | ||
908 | super::children(self) | 625 | super::children(self) |
909 | } | 626 | } |
910 | } | 627 | } |
911 | 628 | ||
912 | // Expr | 629 | // Expr |
913 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 630 | #[derive(Debug, PartialEq, Eq, Hash)] |
914 | pub enum Expr<'a> { | 631 | #[repr(transparent)] |
915 | TupleExpr(TupleExpr<'a>), | 632 | pub struct Expr { |
916 | ArrayExpr(ArrayExpr<'a>), | 633 | pub(crate) syntax: SyntaxNode, |
917 | ParenExpr(ParenExpr<'a>), | 634 | } |
918 | PathExpr(PathExpr<'a>), | 635 | unsafe impl TransparentNewType for Expr { |
919 | LambdaExpr(LambdaExpr<'a>), | 636 | 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 | } | 637 | } |
1009 | 638 | ||
1010 | impl<'a> Expr<'a> {} | 639 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
640 | pub enum ExprKind<'a> { | ||
641 | TupleExpr(&'a TupleExpr), | ||
642 | ArrayExpr(&'a ArrayExpr), | ||
643 | ParenExpr(&'a ParenExpr), | ||
644 | PathExpr(&'a PathExpr), | ||
645 | LambdaExpr(&'a LambdaExpr), | ||
646 | IfExpr(&'a IfExpr), | ||
647 | LoopExpr(&'a LoopExpr), | ||
648 | ForExpr(&'a ForExpr), | ||
649 | WhileExpr(&'a WhileExpr), | ||
650 | ContinueExpr(&'a ContinueExpr), | ||
651 | BreakExpr(&'a BreakExpr), | ||
652 | Label(&'a Label), | ||
653 | BlockExpr(&'a BlockExpr), | ||
654 | ReturnExpr(&'a ReturnExpr), | ||
655 | MatchExpr(&'a MatchExpr), | ||
656 | StructLit(&'a StructLit), | ||
657 | CallExpr(&'a CallExpr), | ||
658 | IndexExpr(&'a IndexExpr), | ||
659 | MethodCallExpr(&'a MethodCallExpr), | ||
660 | FieldExpr(&'a FieldExpr), | ||
661 | TryExpr(&'a TryExpr), | ||
662 | CastExpr(&'a CastExpr), | ||
663 | RefExpr(&'a RefExpr), | ||
664 | PrefixExpr(&'a PrefixExpr), | ||
665 | RangeExpr(&'a RangeExpr), | ||
666 | BinExpr(&'a BinExpr), | ||
667 | Literal(&'a Literal), | ||
668 | } | ||
669 | |||
670 | impl AstNode for Expr { | ||
671 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
672 | match syntax.kind() { | ||
673 | | TUPLE_EXPR | ||
674 | | ARRAY_EXPR | ||
675 | | PAREN_EXPR | ||
676 | | PATH_EXPR | ||
677 | | LAMBDA_EXPR | ||
678 | | IF_EXPR | ||
679 | | LOOP_EXPR | ||
680 | | FOR_EXPR | ||
681 | | WHILE_EXPR | ||
682 | | CONTINUE_EXPR | ||
683 | | BREAK_EXPR | ||
684 | | LABEL | ||
685 | | BLOCK_EXPR | ||
686 | | RETURN_EXPR | ||
687 | | MATCH_EXPR | ||
688 | | STRUCT_LIT | ||
689 | | CALL_EXPR | ||
690 | | INDEX_EXPR | ||
691 | | METHOD_CALL_EXPR | ||
692 | | FIELD_EXPR | ||
693 | | TRY_EXPR | ||
694 | | CAST_EXPR | ||
695 | | REF_EXPR | ||
696 | | PREFIX_EXPR | ||
697 | | RANGE_EXPR | ||
698 | | BIN_EXPR | ||
699 | | LITERAL => Some(Expr::from_repr(syntax.into_repr())), | ||
700 | _ => None, | ||
701 | } | ||
702 | } | ||
703 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
704 | fn to_owned(&self) -> TreePtr<Expr> { TreePtr::cast(self.syntax.to_owned()) } | ||
705 | } | ||
706 | |||
707 | impl Expr { | ||
708 | pub fn kind(&self) -> ExprKind { | ||
709 | match self.syntax.kind() { | ||
710 | TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(&self.syntax).unwrap()), | ||
711 | ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(&self.syntax).unwrap()), | ||
712 | PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(&self.syntax).unwrap()), | ||
713 | PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(&self.syntax).unwrap()), | ||
714 | LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(&self.syntax).unwrap()), | ||
715 | IF_EXPR => ExprKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()), | ||
716 | LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(&self.syntax).unwrap()), | ||
717 | FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(&self.syntax).unwrap()), | ||
718 | WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(&self.syntax).unwrap()), | ||
719 | CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(&self.syntax).unwrap()), | ||
720 | BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(&self.syntax).unwrap()), | ||
721 | LABEL => ExprKind::Label(Label::cast(&self.syntax).unwrap()), | ||
722 | BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(&self.syntax).unwrap()), | ||
723 | RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(&self.syntax).unwrap()), | ||
724 | MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(&self.syntax).unwrap()), | ||
725 | STRUCT_LIT => ExprKind::StructLit(StructLit::cast(&self.syntax).unwrap()), | ||
726 | CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(&self.syntax).unwrap()), | ||
727 | INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(&self.syntax).unwrap()), | ||
728 | METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()), | ||
729 | FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()), | ||
730 | TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()), | ||
731 | CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()), | ||
732 | REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()), | ||
733 | PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()), | ||
734 | RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()), | ||
735 | BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()), | ||
736 | LITERAL => ExprKind::Literal(Literal::cast(&self.syntax).unwrap()), | ||
737 | _ => unreachable!(), | ||
738 | } | ||
739 | } | ||
740 | } | ||
741 | |||
742 | impl Expr {} | ||
1011 | 743 | ||
1012 | // ExprStmt | 744 | // ExprStmt |
1013 | #[derive(Debug, Clone, Copy,)] | 745 | #[derive(Debug, PartialEq, Eq, Hash)] |
1014 | pub struct ExprStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 746 | #[repr(transparent)] |
1015 | pub(crate) syntax: SyntaxNode<R>, | 747 | pub struct ExprStmt { |
748 | pub(crate) syntax: SyntaxNode, | ||
1016 | } | 749 | } |
1017 | pub type ExprStmt<'a> = ExprStmtNode<RefRoot<'a>>; | 750 | unsafe impl TransparentNewType for ExprStmt { |
1018 | 751 | 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 | } | 752 | } |
1026 | 753 | ||
1027 | impl<'a> AstNode<'a> for ExprStmt<'a> { | 754 | impl AstNode for ExprStmt { |
1028 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 755 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1029 | match syntax.kind() { | 756 | match syntax.kind() { |
1030 | EXPR_STMT => Some(ExprStmt { syntax }), | 757 | EXPR_STMT => Some(ExprStmt::from_repr(syntax.into_repr())), |
1031 | _ => None, | 758 | _ => None, |
1032 | } | 759 | } |
1033 | } | 760 | } |
1034 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 761 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1035 | } | 762 | 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 | } | 763 | } |
1045 | 764 | ||
1046 | 765 | ||
1047 | impl<'a> ExprStmt<'a> { | 766 | impl ExprStmt { |
1048 | pub fn expr(self) -> Option<Expr<'a>> { | 767 | pub fn expr(&self) -> Option<&Expr> { |
1049 | super::child_opt(self) | 768 | super::child_opt(self) |
1050 | } | 769 | } |
1051 | } | 770 | } |
1052 | 771 | ||
1053 | // ExternCrateItem | 772 | // ExternCrateItem |
1054 | #[derive(Debug, Clone, Copy,)] | 773 | #[derive(Debug, PartialEq, Eq, Hash)] |
1055 | pub struct ExternCrateItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 774 | #[repr(transparent)] |
1056 | pub(crate) syntax: SyntaxNode<R>, | 775 | pub struct ExternCrateItem { |
1057 | } | 776 | 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 | } | 777 | } |
1063 | impl<R: TreeRoot<RaTypes>> Eq for ExternCrateItemNode<R> {} | 778 | unsafe impl TransparentNewType for ExternCrateItem { |
1064 | impl<R: TreeRoot<RaTypes>> Hash for ExternCrateItemNode<R> { | 779 | type Repr = rowan::SyntaxNode<RaTypes>; |
1065 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1066 | } | 780 | } |
1067 | 781 | ||
1068 | impl<'a> AstNode<'a> for ExternCrateItem<'a> { | 782 | impl AstNode for ExternCrateItem { |
1069 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 783 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1070 | match syntax.kind() { | 784 | match syntax.kind() { |
1071 | EXTERN_CRATE_ITEM => Some(ExternCrateItem { syntax }), | 785 | EXTERN_CRATE_ITEM => Some(ExternCrateItem::from_repr(syntax.into_repr())), |
1072 | _ => None, | 786 | _ => None, |
1073 | } | 787 | } |
1074 | } | 788 | } |
1075 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 789 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
790 | fn to_owned(&self) -> TreePtr<ExternCrateItem> { TreePtr::cast(self.syntax.to_owned()) } | ||
1076 | } | 791 | } |
1077 | 792 | ||
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 | 793 | ||
1087 | 794 | impl ExternCrateItem {} | |
1088 | impl<'a> ExternCrateItem<'a> {} | ||
1089 | 795 | ||
1090 | // FieldExpr | 796 | // FieldExpr |
1091 | #[derive(Debug, Clone, Copy,)] | 797 | #[derive(Debug, PartialEq, Eq, Hash)] |
1092 | pub struct FieldExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 798 | #[repr(transparent)] |
1093 | pub(crate) syntax: SyntaxNode<R>, | 799 | pub struct FieldExpr { |
1094 | } | 800 | 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 | } | 801 | } |
1100 | impl<R: TreeRoot<RaTypes>> Eq for FieldExprNode<R> {} | 802 | unsafe impl TransparentNewType for FieldExpr { |
1101 | impl<R: TreeRoot<RaTypes>> Hash for FieldExprNode<R> { | 803 | type Repr = rowan::SyntaxNode<RaTypes>; |
1102 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1103 | } | 804 | } |
1104 | 805 | ||
1105 | impl<'a> AstNode<'a> for FieldExpr<'a> { | 806 | impl AstNode for FieldExpr { |
1106 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 807 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1107 | match syntax.kind() { | 808 | match syntax.kind() { |
1108 | FIELD_EXPR => Some(FieldExpr { syntax }), | 809 | FIELD_EXPR => Some(FieldExpr::from_repr(syntax.into_repr())), |
1109 | _ => None, | 810 | _ => None, |
1110 | } | 811 | } |
1111 | } | 812 | } |
1112 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 813 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
814 | fn to_owned(&self) -> TreePtr<FieldExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
1113 | } | 815 | } |
1114 | 816 | ||
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 | 817 | ||
1124 | 818 | impl FieldExpr { | |
1125 | impl<'a> FieldExpr<'a> { | 819 | pub fn expr(&self) -> Option<&Expr> { |
1126 | pub fn expr(self) -> Option<Expr<'a>> { | ||
1127 | super::child_opt(self) | 820 | super::child_opt(self) |
1128 | } | 821 | } |
1129 | 822 | ||
1130 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 823 | pub fn name_ref(&self) -> Option<&NameRef> { |
1131 | super::child_opt(self) | 824 | super::child_opt(self) |
1132 | } | 825 | } |
1133 | } | 826 | } |
1134 | 827 | ||
1135 | // FieldPatList | 828 | // FieldPatList |
1136 | #[derive(Debug, Clone, Copy,)] | 829 | #[derive(Debug, PartialEq, Eq, Hash)] |
1137 | pub struct FieldPatListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 830 | #[repr(transparent)] |
1138 | pub(crate) syntax: SyntaxNode<R>, | 831 | pub struct FieldPatList { |
832 | pub(crate) syntax: SyntaxNode, | ||
1139 | } | 833 | } |
1140 | pub type FieldPatList<'a> = FieldPatListNode<RefRoot<'a>>; | 834 | unsafe impl TransparentNewType for FieldPatList { |
1141 | 835 | 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 | } | 836 | } |
1149 | 837 | ||
1150 | impl<'a> AstNode<'a> for FieldPatList<'a> { | 838 | impl AstNode for FieldPatList { |
1151 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 839 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1152 | match syntax.kind() { | 840 | match syntax.kind() { |
1153 | FIELD_PAT_LIST => Some(FieldPatList { syntax }), | 841 | FIELD_PAT_LIST => Some(FieldPatList::from_repr(syntax.into_repr())), |
1154 | _ => None, | 842 | _ => None, |
1155 | } | 843 | } |
1156 | } | 844 | } |
1157 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 845 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1158 | } | 846 | 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 | } | 847 | } |
1168 | 848 | ||
1169 | 849 | ||
1170 | impl<'a> FieldPatList<'a> {} | 850 | impl FieldPatList {} |
1171 | 851 | ||
1172 | // FnDef | 852 | // FnDef |
1173 | #[derive(Debug, Clone, Copy,)] | 853 | #[derive(Debug, PartialEq, Eq, Hash)] |
1174 | pub struct FnDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 854 | #[repr(transparent)] |
1175 | pub(crate) syntax: SyntaxNode<R>, | 855 | pub struct FnDef { |
856 | pub(crate) syntax: SyntaxNode, | ||
1176 | } | 857 | } |
1177 | pub type FnDef<'a> = FnDefNode<RefRoot<'a>>; | 858 | unsafe impl TransparentNewType for FnDef { |
1178 | 859 | 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 | } | 860 | } |
1186 | 861 | ||
1187 | impl<'a> AstNode<'a> for FnDef<'a> { | 862 | impl AstNode for FnDef { |
1188 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 863 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1189 | match syntax.kind() { | 864 | match syntax.kind() { |
1190 | FN_DEF => Some(FnDef { syntax }), | 865 | FN_DEF => Some(FnDef::from_repr(syntax.into_repr())), |
1191 | _ => None, | 866 | _ => None, |
1192 | } | 867 | } |
1193 | } | 868 | } |
1194 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 869 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1195 | } | 870 | 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 | } | 871 | } |
1205 | 872 | ||
1206 | 873 | ||
1207 | impl<'a> ast::VisibilityOwner<'a> for FnDef<'a> {} | 874 | impl ast::VisibilityOwner for FnDef {} |
1208 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} | 875 | impl ast::NameOwner for FnDef {} |
1209 | impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} | 876 | impl ast::TypeParamsOwner for FnDef {} |
1210 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} | 877 | impl ast::AttrsOwner for FnDef {} |
1211 | impl<'a> ast::DocCommentsOwner<'a> for FnDef<'a> {} | 878 | impl ast::DocCommentsOwner for FnDef {} |
1212 | impl<'a> FnDef<'a> { | 879 | impl FnDef { |
1213 | pub fn param_list(self) -> Option<ParamList<'a>> { | 880 | pub fn param_list(&self) -> Option<&ParamList> { |
1214 | super::child_opt(self) | 881 | super::child_opt(self) |
1215 | } | 882 | } |
1216 | 883 | ||
1217 | pub fn body(self) -> Option<Block<'a>> { | 884 | pub fn body(&self) -> Option<&Block> { |
1218 | super::child_opt(self) | 885 | super::child_opt(self) |
1219 | } | 886 | } |
1220 | 887 | ||
1221 | pub fn ret_type(self) -> Option<RetType<'a>> { | 888 | pub fn ret_type(&self) -> Option<&RetType> { |
1222 | super::child_opt(self) | 889 | super::child_opt(self) |
1223 | } | 890 | } |
1224 | } | 891 | } |
1225 | 892 | ||
1226 | // FnPointerType | 893 | // FnPointerType |
1227 | #[derive(Debug, Clone, Copy,)] | 894 | #[derive(Debug, PartialEq, Eq, Hash)] |
1228 | pub struct FnPointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 895 | #[repr(transparent)] |
1229 | pub(crate) syntax: SyntaxNode<R>, | 896 | pub struct FnPointerType { |
1230 | } | 897 | 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 | } | 898 | } |
1236 | impl<R: TreeRoot<RaTypes>> Eq for FnPointerTypeNode<R> {} | 899 | unsafe impl TransparentNewType for FnPointerType { |
1237 | impl<R: TreeRoot<RaTypes>> Hash for FnPointerTypeNode<R> { | 900 | type Repr = rowan::SyntaxNode<RaTypes>; |
1238 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1239 | } | 901 | } |
1240 | 902 | ||
1241 | impl<'a> AstNode<'a> for FnPointerType<'a> { | 903 | impl AstNode for FnPointerType { |
1242 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 904 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1243 | match syntax.kind() { | 905 | match syntax.kind() { |
1244 | FN_POINTER_TYPE => Some(FnPointerType { syntax }), | 906 | FN_POINTER_TYPE => Some(FnPointerType::from_repr(syntax.into_repr())), |
1245 | _ => None, | 907 | _ => None, |
1246 | } | 908 | } |
1247 | } | 909 | } |
1248 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 910 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
911 | fn to_owned(&self) -> TreePtr<FnPointerType> { TreePtr::cast(self.syntax.to_owned()) } | ||
1249 | } | 912 | } |
1250 | 913 | ||
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 | 914 | ||
1260 | 915 | impl FnPointerType { | |
1261 | impl<'a> FnPointerType<'a> { | 916 | pub fn param_list(&self) -> Option<&ParamList> { |
1262 | pub fn param_list(self) -> Option<ParamList<'a>> { | ||
1263 | super::child_opt(self) | 917 | super::child_opt(self) |
1264 | } | 918 | } |
1265 | 919 | ||
1266 | pub fn ret_type(self) -> Option<RetType<'a>> { | 920 | pub fn ret_type(&self) -> Option<&RetType> { |
1267 | super::child_opt(self) | 921 | super::child_opt(self) |
1268 | } | 922 | } |
1269 | } | 923 | } |
1270 | 924 | ||
1271 | // ForExpr | 925 | // ForExpr |
1272 | #[derive(Debug, Clone, Copy,)] | 926 | #[derive(Debug, PartialEq, Eq, Hash)] |
1273 | pub struct ForExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 927 | #[repr(transparent)] |
1274 | pub(crate) syntax: SyntaxNode<R>, | 928 | pub struct ForExpr { |
1275 | } | 929 | 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 | } | 930 | } |
1281 | impl<R: TreeRoot<RaTypes>> Eq for ForExprNode<R> {} | 931 | unsafe impl TransparentNewType for ForExpr { |
1282 | impl<R: TreeRoot<RaTypes>> Hash for ForExprNode<R> { | 932 | type Repr = rowan::SyntaxNode<RaTypes>; |
1283 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1284 | } | 933 | } |
1285 | 934 | ||
1286 | impl<'a> AstNode<'a> for ForExpr<'a> { | 935 | impl AstNode for ForExpr { |
1287 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 936 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1288 | match syntax.kind() { | 937 | match syntax.kind() { |
1289 | FOR_EXPR => Some(ForExpr { syntax }), | 938 | FOR_EXPR => Some(ForExpr::from_repr(syntax.into_repr())), |
1290 | _ => None, | 939 | _ => None, |
1291 | } | 940 | } |
1292 | } | 941 | } |
1293 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 942 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1294 | } | 943 | 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 | } | 944 | } |
1304 | 945 | ||
1305 | 946 | ||
1306 | impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} | 947 | impl ast::LoopBodyOwner for ForExpr {} |
1307 | impl<'a> ForExpr<'a> { | 948 | impl ForExpr { |
1308 | pub fn pat(self) -> Option<Pat<'a>> { | 949 | pub fn pat(&self) -> Option<&Pat> { |
1309 | super::child_opt(self) | 950 | super::child_opt(self) |
1310 | } | 951 | } |
1311 | 952 | ||
1312 | pub fn iterable(self) -> Option<Expr<'a>> { | 953 | pub fn iterable(&self) -> Option<&Expr> { |
1313 | super::child_opt(self) | 954 | super::child_opt(self) |
1314 | } | 955 | } |
1315 | } | 956 | } |
1316 | 957 | ||
1317 | // ForType | 958 | // ForType |
1318 | #[derive(Debug, Clone, Copy,)] | 959 | #[derive(Debug, PartialEq, Eq, Hash)] |
1319 | pub struct ForTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 960 | #[repr(transparent)] |
1320 | pub(crate) syntax: SyntaxNode<R>, | 961 | pub struct ForType { |
1321 | } | 962 | 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 | } | 963 | } |
1327 | impl<R: TreeRoot<RaTypes>> Eq for ForTypeNode<R> {} | 964 | unsafe impl TransparentNewType for ForType { |
1328 | impl<R: TreeRoot<RaTypes>> Hash for ForTypeNode<R> { | 965 | type Repr = rowan::SyntaxNode<RaTypes>; |
1329 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1330 | } | 966 | } |
1331 | 967 | ||
1332 | impl<'a> AstNode<'a> for ForType<'a> { | 968 | impl AstNode for ForType { |
1333 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 969 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1334 | match syntax.kind() { | 970 | match syntax.kind() { |
1335 | FOR_TYPE => Some(ForType { syntax }), | 971 | FOR_TYPE => Some(ForType::from_repr(syntax.into_repr())), |
1336 | _ => None, | 972 | _ => None, |
1337 | } | 973 | } |
1338 | } | 974 | } |
1339 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 975 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1340 | } | 976 | 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 | } | 977 | } |
1350 | 978 | ||
1351 | 979 | ||
1352 | impl<'a> ForType<'a> { | 980 | impl ForType { |
1353 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 981 | pub fn type_ref(&self) -> Option<&TypeRef> { |
1354 | super::child_opt(self) | 982 | super::child_opt(self) |
1355 | } | 983 | } |
1356 | } | 984 | } |
1357 | 985 | ||
1358 | // IfExpr | 986 | // IfExpr |
1359 | #[derive(Debug, Clone, Copy,)] | 987 | #[derive(Debug, PartialEq, Eq, Hash)] |
1360 | pub struct IfExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 988 | #[repr(transparent)] |
1361 | pub(crate) syntax: SyntaxNode<R>, | 989 | pub struct IfExpr { |
990 | pub(crate) syntax: SyntaxNode, | ||
1362 | } | 991 | } |
1363 | pub type IfExpr<'a> = IfExprNode<RefRoot<'a>>; | 992 | unsafe impl TransparentNewType for IfExpr { |
1364 | 993 | 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 | } | 994 | } |
1372 | 995 | ||
1373 | impl<'a> AstNode<'a> for IfExpr<'a> { | 996 | impl AstNode for IfExpr { |
1374 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 997 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1375 | match syntax.kind() { | 998 | match syntax.kind() { |
1376 | IF_EXPR => Some(IfExpr { syntax }), | 999 | IF_EXPR => Some(IfExpr::from_repr(syntax.into_repr())), |
1377 | _ => None, | 1000 | _ => None, |
1378 | } | 1001 | } |
1379 | } | 1002 | } |
1380 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1003 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1381 | } | 1004 | 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 | } | 1005 | } |
1391 | 1006 | ||
1392 | 1007 | ||
1393 | impl<'a> IfExpr<'a> { | 1008 | impl IfExpr { |
1394 | pub fn condition(self) -> Option<Condition<'a>> { | 1009 | pub fn condition(&self) -> Option<&Condition> { |
1395 | super::child_opt(self) | 1010 | super::child_opt(self) |
1396 | } | 1011 | } |
1397 | } | 1012 | } |
1398 | 1013 | ||
1399 | // ImplBlock | 1014 | // ImplBlock |
1400 | #[derive(Debug, Clone, Copy,)] | 1015 | #[derive(Debug, PartialEq, Eq, Hash)] |
1401 | pub struct ImplBlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1016 | #[repr(transparent)] |
1402 | pub(crate) syntax: SyntaxNode<R>, | 1017 | pub struct ImplBlock { |
1018 | pub(crate) syntax: SyntaxNode, | ||
1403 | } | 1019 | } |
1404 | pub type ImplBlock<'a> = ImplBlockNode<RefRoot<'a>>; | 1020 | unsafe impl TransparentNewType for ImplBlock { |
1405 | 1021 | 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 | } | 1022 | } |
1413 | 1023 | ||
1414 | impl<'a> AstNode<'a> for ImplBlock<'a> { | 1024 | impl AstNode for ImplBlock { |
1415 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1025 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1416 | match syntax.kind() { | 1026 | match syntax.kind() { |
1417 | IMPL_BLOCK => Some(ImplBlock { syntax }), | 1027 | IMPL_BLOCK => Some(ImplBlock::from_repr(syntax.into_repr())), |
1418 | _ => None, | 1028 | _ => None, |
1419 | } | 1029 | } |
1420 | } | 1030 | } |
1421 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1031 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1422 | } | 1032 | 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 | } | 1033 | } |
1432 | 1034 | ||
1433 | 1035 | ||
1434 | impl<'a> ImplBlock<'a> { | 1036 | impl ImplBlock { |
1435 | pub fn item_list(self) -> Option<ItemList<'a>> { | 1037 | pub fn item_list(&self) -> Option<&ItemList> { |
1436 | super::child_opt(self) | 1038 | super::child_opt(self) |
1437 | } | 1039 | } |
1438 | } | 1040 | } |
1439 | 1041 | ||
1440 | // ImplItem | 1042 | // ImplItem |
1043 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1044 | #[repr(transparent)] | ||
1045 | pub struct ImplItem { | ||
1046 | pub(crate) syntax: SyntaxNode, | ||
1047 | } | ||
1048 | unsafe impl TransparentNewType for ImplItem { | ||
1049 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1050 | } | ||
1051 | |||
1441 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1052 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1442 | pub enum ImplItem<'a> { | 1053 | pub enum ImplItemKind<'a> { |
1443 | FnDef(FnDef<'a>), | 1054 | FnDef(&'a FnDef), |
1444 | TypeDef(TypeDef<'a>), | 1055 | TypeDef(&'a TypeDef), |
1445 | ConstDef(ConstDef<'a>), | 1056 | ConstDef(&'a ConstDef), |
1446 | } | 1057 | } |
1447 | 1058 | ||
1448 | impl<'a> AstNode<'a> for ImplItem<'a> { | 1059 | impl AstNode for ImplItem { |
1449 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1060 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1450 | match syntax.kind() { | 1061 | match syntax.kind() { |
1451 | FN_DEF => Some(ImplItem::FnDef(FnDef { syntax })), | 1062 | | FN_DEF |
1452 | TYPE_DEF => Some(ImplItem::TypeDef(TypeDef { syntax })), | 1063 | | TYPE_DEF |
1453 | CONST_DEF => Some(ImplItem::ConstDef(ConstDef { syntax })), | 1064 | | CONST_DEF => Some(ImplItem::from_repr(syntax.into_repr())), |
1454 | _ => None, | 1065 | _ => None, |
1455 | } | 1066 | } |
1456 | } | 1067 | } |
1457 | fn syntax(self) -> SyntaxNodeRef<'a> { | 1068 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1458 | match self { | 1069 | fn to_owned(&self) -> TreePtr<ImplItem> { TreePtr::cast(self.syntax.to_owned()) } |
1459 | ImplItem::FnDef(inner) => inner.syntax(), | 1070 | } |
1460 | ImplItem::TypeDef(inner) => inner.syntax(), | 1071 | |
1461 | ImplItem::ConstDef(inner) => inner.syntax(), | 1072 | impl ImplItem { |
1073 | pub fn kind(&self) -> ImplItemKind { | ||
1074 | match self.syntax.kind() { | ||
1075 | FN_DEF => ImplItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), | ||
1076 | TYPE_DEF => ImplItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), | ||
1077 | CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), | ||
1078 | _ => unreachable!(), | ||
1462 | } | 1079 | } |
1463 | } | 1080 | } |
1464 | } | 1081 | } |
1465 | 1082 | ||
1466 | impl<'a> ImplItem<'a> {} | 1083 | impl ImplItem {} |
1467 | 1084 | ||
1468 | // ImplTraitType | 1085 | // ImplTraitType |
1469 | #[derive(Debug, Clone, Copy,)] | 1086 | #[derive(Debug, PartialEq, Eq, Hash)] |
1470 | pub struct ImplTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1087 | #[repr(transparent)] |
1471 | pub(crate) syntax: SyntaxNode<R>, | 1088 | pub struct ImplTraitType { |
1472 | } | 1089 | 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 | } | 1090 | } |
1478 | impl<R: TreeRoot<RaTypes>> Eq for ImplTraitTypeNode<R> {} | 1091 | unsafe impl TransparentNewType for ImplTraitType { |
1479 | impl<R: TreeRoot<RaTypes>> Hash for ImplTraitTypeNode<R> { | 1092 | type Repr = rowan::SyntaxNode<RaTypes>; |
1480 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1481 | } | 1093 | } |
1482 | 1094 | ||
1483 | impl<'a> AstNode<'a> for ImplTraitType<'a> { | 1095 | impl AstNode for ImplTraitType { |
1484 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1096 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1485 | match syntax.kind() { | 1097 | match syntax.kind() { |
1486 | IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), | 1098 | IMPL_TRAIT_TYPE => Some(ImplTraitType::from_repr(syntax.into_repr())), |
1487 | _ => None, | 1099 | _ => None, |
1488 | } | 1100 | } |
1489 | } | 1101 | } |
1490 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1102 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1103 | fn to_owned(&self) -> TreePtr<ImplTraitType> { TreePtr::cast(self.syntax.to_owned()) } | ||
1491 | } | 1104 | } |
1492 | 1105 | ||
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 | 1106 | ||
1502 | 1107 | impl ImplTraitType {} | |
1503 | impl<'a> ImplTraitType<'a> {} | ||
1504 | 1108 | ||
1505 | // IndexExpr | 1109 | // IndexExpr |
1506 | #[derive(Debug, Clone, Copy,)] | 1110 | #[derive(Debug, PartialEq, Eq, Hash)] |
1507 | pub struct IndexExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1111 | #[repr(transparent)] |
1508 | pub(crate) syntax: SyntaxNode<R>, | 1112 | pub struct IndexExpr { |
1113 | pub(crate) syntax: SyntaxNode, | ||
1509 | } | 1114 | } |
1510 | pub type IndexExpr<'a> = IndexExprNode<RefRoot<'a>>; | 1115 | unsafe impl TransparentNewType for IndexExpr { |
1511 | 1116 | 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 | } | 1117 | } |
1519 | 1118 | ||
1520 | impl<'a> AstNode<'a> for IndexExpr<'a> { | 1119 | impl AstNode for IndexExpr { |
1521 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1120 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1522 | match syntax.kind() { | 1121 | match syntax.kind() { |
1523 | INDEX_EXPR => Some(IndexExpr { syntax }), | 1122 | INDEX_EXPR => Some(IndexExpr::from_repr(syntax.into_repr())), |
1524 | _ => None, | 1123 | _ => None, |
1525 | } | 1124 | } |
1526 | } | 1125 | } |
1527 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1126 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1528 | } | 1127 | 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 | } | 1128 | } |
1538 | 1129 | ||
1539 | 1130 | ||
1540 | impl<'a> IndexExpr<'a> {} | 1131 | impl IndexExpr {} |
1541 | 1132 | ||
1542 | // ItemList | 1133 | // ItemList |
1543 | #[derive(Debug, Clone, Copy,)] | 1134 | #[derive(Debug, PartialEq, Eq, Hash)] |
1544 | pub struct ItemListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1135 | #[repr(transparent)] |
1545 | pub(crate) syntax: SyntaxNode<R>, | 1136 | pub struct ItemList { |
1137 | pub(crate) syntax: SyntaxNode, | ||
1546 | } | 1138 | } |
1547 | pub type ItemList<'a> = ItemListNode<RefRoot<'a>>; | 1139 | unsafe impl TransparentNewType for ItemList { |
1548 | 1140 | 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 | } | 1141 | } |
1556 | 1142 | ||
1557 | impl<'a> AstNode<'a> for ItemList<'a> { | 1143 | impl AstNode for ItemList { |
1558 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1144 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1559 | match syntax.kind() { | 1145 | match syntax.kind() { |
1560 | ITEM_LIST => Some(ItemList { syntax }), | 1146 | ITEM_LIST => Some(ItemList::from_repr(syntax.into_repr())), |
1561 | _ => None, | 1147 | _ => None, |
1562 | } | 1148 | } |
1563 | } | 1149 | } |
1564 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1150 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1565 | } | 1151 | 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 | } | 1152 | } |
1575 | 1153 | ||
1576 | 1154 | ||
1577 | impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} | 1155 | impl ast::FnDefOwner for ItemList {} |
1578 | impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} | 1156 | impl ast::ModuleItemOwner for ItemList {} |
1579 | impl<'a> ItemList<'a> { | 1157 | impl ItemList { |
1580 | pub fn impl_items(self) -> impl Iterator<Item = ImplItem<'a>> + 'a { | 1158 | pub fn impl_items(&self) -> impl Iterator<Item = &ImplItem> { |
1581 | super::children(self) | 1159 | super::children(self) |
1582 | } | 1160 | } |
1583 | } | 1161 | } |
1584 | 1162 | ||
1585 | // Label | 1163 | // Label |
1586 | #[derive(Debug, Clone, Copy,)] | 1164 | #[derive(Debug, PartialEq, Eq, Hash)] |
1587 | pub struct LabelNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1165 | #[repr(transparent)] |
1588 | pub(crate) syntax: SyntaxNode<R>, | 1166 | pub struct Label { |
1167 | pub(crate) syntax: SyntaxNode, | ||
1589 | } | 1168 | } |
1590 | pub type Label<'a> = LabelNode<RefRoot<'a>>; | 1169 | unsafe impl TransparentNewType for Label { |
1591 | 1170 | 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 | } | 1171 | } |
1599 | 1172 | ||
1600 | impl<'a> AstNode<'a> for Label<'a> { | 1173 | impl AstNode for Label { |
1601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1174 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1602 | match syntax.kind() { | 1175 | match syntax.kind() { |
1603 | LABEL => Some(Label { syntax }), | 1176 | LABEL => Some(Label::from_repr(syntax.into_repr())), |
1604 | _ => None, | 1177 | _ => None, |
1605 | } | 1178 | } |
1606 | } | 1179 | } |
1607 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1180 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1608 | } | 1181 | 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 | } | 1182 | } |
1618 | 1183 | ||
1619 | 1184 | ||
1620 | impl<'a> Label<'a> {} | 1185 | impl Label {} |
1621 | 1186 | ||
1622 | // LambdaExpr | 1187 | // LambdaExpr |
1623 | #[derive(Debug, Clone, Copy,)] | 1188 | #[derive(Debug, PartialEq, Eq, Hash)] |
1624 | pub struct LambdaExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1189 | #[repr(transparent)] |
1625 | pub(crate) syntax: SyntaxNode<R>, | 1190 | pub struct LambdaExpr { |
1626 | } | 1191 | 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 | } | 1192 | } |
1632 | impl<R: TreeRoot<RaTypes>> Eq for LambdaExprNode<R> {} | 1193 | unsafe impl TransparentNewType for LambdaExpr { |
1633 | impl<R: TreeRoot<RaTypes>> Hash for LambdaExprNode<R> { | 1194 | type Repr = rowan::SyntaxNode<RaTypes>; |
1634 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1635 | } | 1195 | } |
1636 | 1196 | ||
1637 | impl<'a> AstNode<'a> for LambdaExpr<'a> { | 1197 | impl AstNode for LambdaExpr { |
1638 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1198 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1639 | match syntax.kind() { | 1199 | match syntax.kind() { |
1640 | LAMBDA_EXPR => Some(LambdaExpr { syntax }), | 1200 | LAMBDA_EXPR => Some(LambdaExpr::from_repr(syntax.into_repr())), |
1641 | _ => None, | 1201 | _ => None, |
1642 | } | 1202 | } |
1643 | } | 1203 | } |
1644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1204 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1645 | } | 1205 | 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 | } | 1206 | } |
1655 | 1207 | ||
1656 | 1208 | ||
1657 | impl<'a> LambdaExpr<'a> { | 1209 | impl LambdaExpr { |
1658 | pub fn param_list(self) -> Option<ParamList<'a>> { | 1210 | pub fn param_list(&self) -> Option<&ParamList> { |
1659 | super::child_opt(self) | 1211 | super::child_opt(self) |
1660 | } | 1212 | } |
1661 | 1213 | ||
1662 | pub fn body(self) -> Option<Expr<'a>> { | 1214 | pub fn body(&self) -> Option<&Expr> { |
1663 | super::child_opt(self) | 1215 | super::child_opt(self) |
1664 | } | 1216 | } |
1665 | } | 1217 | } |
1666 | 1218 | ||
1667 | // LetStmt | 1219 | // LetStmt |
1668 | #[derive(Debug, Clone, Copy,)] | 1220 | #[derive(Debug, PartialEq, Eq, Hash)] |
1669 | pub struct LetStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1221 | #[repr(transparent)] |
1670 | pub(crate) syntax: SyntaxNode<R>, | 1222 | pub struct LetStmt { |
1671 | } | 1223 | 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 | } | 1224 | } |
1677 | impl<R: TreeRoot<RaTypes>> Eq for LetStmtNode<R> {} | 1225 | unsafe impl TransparentNewType for LetStmt { |
1678 | impl<R: TreeRoot<RaTypes>> Hash for LetStmtNode<R> { | 1226 | type Repr = rowan::SyntaxNode<RaTypes>; |
1679 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1680 | } | 1227 | } |
1681 | 1228 | ||
1682 | impl<'a> AstNode<'a> for LetStmt<'a> { | 1229 | impl AstNode for LetStmt { |
1683 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1230 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1684 | match syntax.kind() { | 1231 | match syntax.kind() { |
1685 | LET_STMT => Some(LetStmt { syntax }), | 1232 | LET_STMT => Some(LetStmt::from_repr(syntax.into_repr())), |
1686 | _ => None, | 1233 | _ => None, |
1687 | } | 1234 | } |
1688 | } | 1235 | } |
1689 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1236 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1690 | } | 1237 | 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 | } | 1238 | } |
1700 | 1239 | ||
1701 | 1240 | ||
1702 | impl<'a> LetStmt<'a> { | 1241 | impl LetStmt { |
1703 | pub fn pat(self) -> Option<Pat<'a>> { | 1242 | pub fn pat(&self) -> Option<&Pat> { |
1704 | super::child_opt(self) | 1243 | super::child_opt(self) |
1705 | } | 1244 | } |
1706 | 1245 | ||
1707 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1246 | pub fn type_ref(&self) -> Option<&TypeRef> { |
1708 | super::child_opt(self) | 1247 | super::child_opt(self) |
1709 | } | 1248 | } |
1710 | 1249 | ||
1711 | pub fn initializer(self) -> Option<Expr<'a>> { | 1250 | pub fn initializer(&self) -> Option<&Expr> { |
1712 | super::child_opt(self) | 1251 | super::child_opt(self) |
1713 | } | 1252 | } |
1714 | } | 1253 | } |
1715 | 1254 | ||
1716 | // Lifetime | 1255 | // Lifetime |
1717 | #[derive(Debug, Clone, Copy,)] | 1256 | #[derive(Debug, PartialEq, Eq, Hash)] |
1718 | pub struct LifetimeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1257 | #[repr(transparent)] |
1719 | pub(crate) syntax: SyntaxNode<R>, | 1258 | pub struct Lifetime { |
1259 | pub(crate) syntax: SyntaxNode, | ||
1720 | } | 1260 | } |
1721 | pub type Lifetime<'a> = LifetimeNode<RefRoot<'a>>; | 1261 | unsafe impl TransparentNewType for Lifetime { |
1722 | 1262 | 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 | } | 1263 | } |
1730 | 1264 | ||
1731 | impl<'a> AstNode<'a> for Lifetime<'a> { | 1265 | impl AstNode for Lifetime { |
1732 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1266 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1733 | match syntax.kind() { | 1267 | match syntax.kind() { |
1734 | LIFETIME => Some(Lifetime { syntax }), | 1268 | LIFETIME => Some(Lifetime::from_repr(syntax.into_repr())), |
1735 | _ => None, | 1269 | _ => None, |
1736 | } | 1270 | } |
1737 | } | 1271 | } |
1738 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1272 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1739 | } | 1273 | 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 | } | 1274 | } |
1749 | 1275 | ||
1750 | 1276 | ||
1751 | impl<'a> Lifetime<'a> {} | 1277 | impl ast::AstToken for Lifetime {} |
1278 | impl Lifetime {} | ||
1752 | 1279 | ||
1753 | // LifetimeParam | 1280 | // LifetimeParam |
1754 | #[derive(Debug, Clone, Copy,)] | 1281 | #[derive(Debug, PartialEq, Eq, Hash)] |
1755 | pub struct LifetimeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1282 | #[repr(transparent)] |
1756 | pub(crate) syntax: SyntaxNode<R>, | 1283 | pub struct LifetimeParam { |
1757 | } | 1284 | 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 | } | 1285 | } |
1763 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeParamNode<R> {} | 1286 | unsafe impl TransparentNewType for LifetimeParam { |
1764 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeParamNode<R> { | 1287 | type Repr = rowan::SyntaxNode<RaTypes>; |
1765 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1766 | } | 1288 | } |
1767 | 1289 | ||
1768 | impl<'a> AstNode<'a> for LifetimeParam<'a> { | 1290 | impl AstNode for LifetimeParam { |
1769 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1291 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1770 | match syntax.kind() { | 1292 | match syntax.kind() { |
1771 | LIFETIME_PARAM => Some(LifetimeParam { syntax }), | 1293 | LIFETIME_PARAM => Some(LifetimeParam::from_repr(syntax.into_repr())), |
1772 | _ => None, | 1294 | _ => None, |
1773 | } | 1295 | } |
1774 | } | 1296 | } |
1775 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1297 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1298 | fn to_owned(&self) -> TreePtr<LifetimeParam> { TreePtr::cast(self.syntax.to_owned()) } | ||
1776 | } | 1299 | } |
1777 | 1300 | ||
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 | 1301 | ||
1787 | 1302 | impl LifetimeParam { | |
1788 | impl<'a> LifetimeParam<'a> { | 1303 | pub fn lifetime(&self) -> Option<&Lifetime> { |
1789 | pub fn lifetime(self) -> Option<Lifetime<'a>> { | ||
1790 | super::child_opt(self) | 1304 | super::child_opt(self) |
1791 | } | 1305 | } |
1792 | } | 1306 | } |
1793 | 1307 | ||
1794 | // Literal | 1308 | // Literal |
1795 | #[derive(Debug, Clone, Copy,)] | 1309 | #[derive(Debug, PartialEq, Eq, Hash)] |
1796 | pub struct LiteralNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1310 | #[repr(transparent)] |
1797 | pub(crate) syntax: SyntaxNode<R>, | 1311 | pub struct Literal { |
1798 | } | 1312 | 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 | } | 1313 | } |
1804 | impl<R: TreeRoot<RaTypes>> Eq for LiteralNode<R> {} | 1314 | unsafe impl TransparentNewType for Literal { |
1805 | impl<R: TreeRoot<RaTypes>> Hash for LiteralNode<R> { | 1315 | type Repr = rowan::SyntaxNode<RaTypes>; |
1806 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1807 | } | 1316 | } |
1808 | 1317 | ||
1809 | impl<'a> AstNode<'a> for Literal<'a> { | 1318 | impl AstNode for Literal { |
1810 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1319 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1811 | match syntax.kind() { | 1320 | match syntax.kind() { |
1812 | LITERAL => Some(Literal { syntax }), | 1321 | LITERAL => Some(Literal::from_repr(syntax.into_repr())), |
1813 | _ => None, | 1322 | _ => None, |
1814 | } | 1323 | } |
1815 | } | 1324 | } |
1816 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1325 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1817 | } | 1326 | 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 | } | 1327 | } |
1827 | 1328 | ||
1828 | 1329 | ||
1829 | impl<'a> Literal<'a> {} | 1330 | impl Literal {} |
1830 | 1331 | ||
1831 | // LoopExpr | 1332 | // LoopExpr |
1832 | #[derive(Debug, Clone, Copy,)] | 1333 | #[derive(Debug, PartialEq, Eq, Hash)] |
1833 | pub struct LoopExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1334 | #[repr(transparent)] |
1834 | pub(crate) syntax: SyntaxNode<R>, | 1335 | pub struct LoopExpr { |
1336 | pub(crate) syntax: SyntaxNode, | ||
1835 | } | 1337 | } |
1836 | pub type LoopExpr<'a> = LoopExprNode<RefRoot<'a>>; | 1338 | unsafe impl TransparentNewType for LoopExpr { |
1837 | 1339 | 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 | } | 1340 | } |
1845 | 1341 | ||
1846 | impl<'a> AstNode<'a> for LoopExpr<'a> { | 1342 | impl AstNode for LoopExpr { |
1847 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1343 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1848 | match syntax.kind() { | 1344 | match syntax.kind() { |
1849 | LOOP_EXPR => Some(LoopExpr { syntax }), | 1345 | LOOP_EXPR => Some(LoopExpr::from_repr(syntax.into_repr())), |
1850 | _ => None, | 1346 | _ => None, |
1851 | } | 1347 | } |
1852 | } | 1348 | } |
1853 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1349 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1854 | } | 1350 | 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 | } | 1351 | } |
1864 | 1352 | ||
1865 | 1353 | ||
1866 | impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} | 1354 | impl ast::LoopBodyOwner for LoopExpr {} |
1867 | impl<'a> LoopExpr<'a> {} | 1355 | impl LoopExpr {} |
1868 | 1356 | ||
1869 | // MacroCall | 1357 | // MacroCall |
1870 | #[derive(Debug, Clone, Copy,)] | 1358 | #[derive(Debug, PartialEq, Eq, Hash)] |
1871 | pub struct MacroCallNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1359 | #[repr(transparent)] |
1872 | pub(crate) syntax: SyntaxNode<R>, | 1360 | pub struct MacroCall { |
1361 | pub(crate) syntax: SyntaxNode, | ||
1873 | } | 1362 | } |
1874 | pub type MacroCall<'a> = MacroCallNode<RefRoot<'a>>; | 1363 | unsafe impl TransparentNewType for MacroCall { |
1875 | 1364 | 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 | } | 1365 | } |
1883 | 1366 | ||
1884 | impl<'a> AstNode<'a> for MacroCall<'a> { | 1367 | impl AstNode for MacroCall { |
1885 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1368 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1886 | match syntax.kind() { | 1369 | match syntax.kind() { |
1887 | MACRO_CALL => Some(MacroCall { syntax }), | 1370 | MACRO_CALL => Some(MacroCall::from_repr(syntax.into_repr())), |
1888 | _ => None, | 1371 | _ => None, |
1889 | } | 1372 | } |
1890 | } | 1373 | } |
1891 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1374 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1892 | } | 1375 | 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 | } | 1376 | } |
1902 | 1377 | ||
1903 | 1378 | ||
1904 | impl<'a> MacroCall<'a> { | 1379 | impl MacroCall { |
1905 | pub fn token_tree(self) -> Option<TokenTree<'a>> { | 1380 | pub fn token_tree(&self) -> Option<&TokenTree> { |
1906 | super::child_opt(self) | 1381 | super::child_opt(self) |
1907 | } | 1382 | } |
1908 | 1383 | ||
1909 | pub fn path(self) -> Option<Path<'a>> { | 1384 | pub fn path(&self) -> Option<&Path> { |
1910 | super::child_opt(self) | 1385 | super::child_opt(self) |
1911 | } | 1386 | } |
1912 | } | 1387 | } |
1913 | 1388 | ||
1914 | // MatchArm | 1389 | // MatchArm |
1915 | #[derive(Debug, Clone, Copy,)] | 1390 | #[derive(Debug, PartialEq, Eq, Hash)] |
1916 | pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1391 | #[repr(transparent)] |
1917 | pub(crate) syntax: SyntaxNode<R>, | 1392 | pub struct MatchArm { |
1393 | pub(crate) syntax: SyntaxNode, | ||
1918 | } | 1394 | } |
1919 | pub type MatchArm<'a> = MatchArmNode<RefRoot<'a>>; | 1395 | unsafe impl TransparentNewType for MatchArm { |
1920 | 1396 | 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 | } | 1397 | } |
1928 | 1398 | ||
1929 | impl<'a> AstNode<'a> for MatchArm<'a> { | 1399 | impl AstNode for MatchArm { |
1930 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1400 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1931 | match syntax.kind() { | 1401 | match syntax.kind() { |
1932 | MATCH_ARM => Some(MatchArm { syntax }), | 1402 | MATCH_ARM => Some(MatchArm::from_repr(syntax.into_repr())), |
1933 | _ => None, | 1403 | _ => None, |
1934 | } | 1404 | } |
1935 | } | 1405 | } |
1936 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1406 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1407 | fn to_owned(&self) -> TreePtr<MatchArm> { TreePtr::cast(self.syntax.to_owned()) } | ||
1937 | } | 1408 | } |
1938 | 1409 | ||
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 | 1410 | ||
1948 | 1411 | impl MatchArm { | |
1949 | impl<'a> MatchArm<'a> { | 1412 | pub fn pats(&self) -> impl Iterator<Item = &Pat> { |
1950 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { | ||
1951 | super::children(self) | 1413 | super::children(self) |
1952 | } | 1414 | } |
1953 | 1415 | ||
1954 | pub fn guard(self) -> Option<MatchGuard<'a>> { | 1416 | pub fn guard(&self) -> Option<&MatchGuard> { |
1955 | super::child_opt(self) | 1417 | super::child_opt(self) |
1956 | } | 1418 | } |
1957 | 1419 | ||
1958 | pub fn expr(self) -> Option<Expr<'a>> { | 1420 | pub fn expr(&self) -> Option<&Expr> { |
1959 | super::child_opt(self) | 1421 | super::child_opt(self) |
1960 | } | 1422 | } |
1961 | } | 1423 | } |
1962 | 1424 | ||
1963 | // MatchArmList | 1425 | // MatchArmList |
1964 | #[derive(Debug, Clone, Copy,)] | 1426 | #[derive(Debug, PartialEq, Eq, Hash)] |
1965 | pub struct MatchArmListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1427 | #[repr(transparent)] |
1966 | pub(crate) syntax: SyntaxNode<R>, | 1428 | pub struct MatchArmList { |
1967 | } | 1429 | 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 | } | 1430 | } |
1973 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmListNode<R> {} | 1431 | unsafe impl TransparentNewType for MatchArmList { |
1974 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmListNode<R> { | 1432 | type Repr = rowan::SyntaxNode<RaTypes>; |
1975 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1976 | } | 1433 | } |
1977 | 1434 | ||
1978 | impl<'a> AstNode<'a> for MatchArmList<'a> { | 1435 | impl AstNode for MatchArmList { |
1979 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1436 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1980 | match syntax.kind() { | 1437 | match syntax.kind() { |
1981 | MATCH_ARM_LIST => Some(MatchArmList { syntax }), | 1438 | MATCH_ARM_LIST => Some(MatchArmList::from_repr(syntax.into_repr())), |
1982 | _ => None, | 1439 | _ => None, |
1983 | } | 1440 | } |
1984 | } | 1441 | } |
1985 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1442 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1443 | fn to_owned(&self) -> TreePtr<MatchArmList> { TreePtr::cast(self.syntax.to_owned()) } | ||
1986 | } | 1444 | } |
1987 | 1445 | ||
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 | 1446 | ||
1997 | 1447 | impl MatchArmList { | |
1998 | impl<'a> MatchArmList<'a> { | 1448 | pub fn arms(&self) -> impl Iterator<Item = &MatchArm> { |
1999 | pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a { | ||
2000 | super::children(self) | 1449 | super::children(self) |
2001 | } | 1450 | } |
2002 | } | 1451 | } |
2003 | 1452 | ||
2004 | // MatchExpr | 1453 | // MatchExpr |
2005 | #[derive(Debug, Clone, Copy,)] | 1454 | #[derive(Debug, PartialEq, Eq, Hash)] |
2006 | pub struct MatchExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1455 | #[repr(transparent)] |
2007 | pub(crate) syntax: SyntaxNode<R>, | 1456 | pub struct MatchExpr { |
2008 | } | 1457 | 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 | } | 1458 | } |
2014 | impl<R: TreeRoot<RaTypes>> Eq for MatchExprNode<R> {} | 1459 | unsafe impl TransparentNewType for MatchExpr { |
2015 | impl<R: TreeRoot<RaTypes>> Hash for MatchExprNode<R> { | 1460 | type Repr = rowan::SyntaxNode<RaTypes>; |
2016 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2017 | } | 1461 | } |
2018 | 1462 | ||
2019 | impl<'a> AstNode<'a> for MatchExpr<'a> { | 1463 | impl AstNode for MatchExpr { |
2020 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1464 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2021 | match syntax.kind() { | 1465 | match syntax.kind() { |
2022 | MATCH_EXPR => Some(MatchExpr { syntax }), | 1466 | MATCH_EXPR => Some(MatchExpr::from_repr(syntax.into_repr())), |
2023 | _ => None, | 1467 | _ => None, |
2024 | } | 1468 | } |
2025 | } | 1469 | } |
2026 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1470 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2027 | } | 1471 | 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 | } | 1472 | } |
2037 | 1473 | ||
2038 | 1474 | ||
2039 | impl<'a> MatchExpr<'a> { | 1475 | impl MatchExpr { |
2040 | pub fn expr(self) -> Option<Expr<'a>> { | 1476 | pub fn expr(&self) -> Option<&Expr> { |
2041 | super::child_opt(self) | 1477 | super::child_opt(self) |
2042 | } | 1478 | } |
2043 | 1479 | ||
2044 | pub fn match_arm_list(self) -> Option<MatchArmList<'a>> { | 1480 | pub fn match_arm_list(&self) -> Option<&MatchArmList> { |
2045 | super::child_opt(self) | 1481 | super::child_opt(self) |
2046 | } | 1482 | } |
2047 | } | 1483 | } |
2048 | 1484 | ||
2049 | // MatchGuard | 1485 | // MatchGuard |
2050 | #[derive(Debug, Clone, Copy,)] | 1486 | #[derive(Debug, PartialEq, Eq, Hash)] |
2051 | pub struct MatchGuardNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1487 | #[repr(transparent)] |
2052 | pub(crate) syntax: SyntaxNode<R>, | 1488 | pub struct MatchGuard { |
1489 | pub(crate) syntax: SyntaxNode, | ||
2053 | } | 1490 | } |
2054 | pub type MatchGuard<'a> = MatchGuardNode<RefRoot<'a>>; | 1491 | unsafe impl TransparentNewType for MatchGuard { |
2055 | 1492 | 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 | } | 1493 | } |
2063 | 1494 | ||
2064 | impl<'a> AstNode<'a> for MatchGuard<'a> { | 1495 | impl AstNode for MatchGuard { |
2065 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1496 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2066 | match syntax.kind() { | 1497 | match syntax.kind() { |
2067 | MATCH_GUARD => Some(MatchGuard { syntax }), | 1498 | MATCH_GUARD => Some(MatchGuard::from_repr(syntax.into_repr())), |
2068 | _ => None, | 1499 | _ => None, |
2069 | } | 1500 | } |
2070 | } | 1501 | } |
2071 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1502 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2072 | } | 1503 | 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 | } | 1504 | } |
2082 | 1505 | ||
2083 | 1506 | ||
2084 | impl<'a> MatchGuard<'a> {} | 1507 | impl MatchGuard {} |
2085 | 1508 | ||
2086 | // MethodCallExpr | 1509 | // MethodCallExpr |
2087 | #[derive(Debug, Clone, Copy,)] | 1510 | #[derive(Debug, PartialEq, Eq, Hash)] |
2088 | pub struct MethodCallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1511 | #[repr(transparent)] |
2089 | pub(crate) syntax: SyntaxNode<R>, | 1512 | pub struct MethodCallExpr { |
2090 | } | 1513 | 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 | } | 1514 | } |
2096 | impl<R: TreeRoot<RaTypes>> Eq for MethodCallExprNode<R> {} | 1515 | unsafe impl TransparentNewType for MethodCallExpr { |
2097 | impl<R: TreeRoot<RaTypes>> Hash for MethodCallExprNode<R> { | 1516 | type Repr = rowan::SyntaxNode<RaTypes>; |
2098 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2099 | } | 1517 | } |
2100 | 1518 | ||
2101 | impl<'a> AstNode<'a> for MethodCallExpr<'a> { | 1519 | impl AstNode for MethodCallExpr { |
2102 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1520 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2103 | match syntax.kind() { | 1521 | match syntax.kind() { |
2104 | METHOD_CALL_EXPR => Some(MethodCallExpr { syntax }), | 1522 | METHOD_CALL_EXPR => Some(MethodCallExpr::from_repr(syntax.into_repr())), |
2105 | _ => None, | 1523 | _ => None, |
2106 | } | 1524 | } |
2107 | } | 1525 | } |
2108 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1526 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1527 | fn to_owned(&self) -> TreePtr<MethodCallExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
2109 | } | 1528 | } |
2110 | 1529 | ||
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 | 1530 | ||
2120 | 1531 | impl ast::ArgListOwner for MethodCallExpr {} | |
2121 | impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} | 1532 | impl MethodCallExpr { |
2122 | impl<'a> MethodCallExpr<'a> { | 1533 | pub fn expr(&self) -> Option<&Expr> { |
2123 | pub fn expr(self) -> Option<Expr<'a>> { | ||
2124 | super::child_opt(self) | 1534 | super::child_opt(self) |
2125 | } | 1535 | } |
2126 | 1536 | ||
2127 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 1537 | pub fn name_ref(&self) -> Option<&NameRef> { |
2128 | super::child_opt(self) | 1538 | super::child_opt(self) |
2129 | } | 1539 | } |
2130 | } | 1540 | } |
2131 | 1541 | ||
2132 | // Module | 1542 | // Module |
2133 | #[derive(Debug, Clone, Copy,)] | 1543 | #[derive(Debug, PartialEq, Eq, Hash)] |
2134 | pub struct ModuleNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1544 | #[repr(transparent)] |
2135 | pub(crate) syntax: SyntaxNode<R>, | 1545 | pub struct Module { |
2136 | } | 1546 | 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 | } | 1547 | } |
2142 | impl<R: TreeRoot<RaTypes>> Eq for ModuleNode<R> {} | 1548 | unsafe impl TransparentNewType for Module { |
2143 | impl<R: TreeRoot<RaTypes>> Hash for ModuleNode<R> { | 1549 | type Repr = rowan::SyntaxNode<RaTypes>; |
2144 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2145 | } | 1550 | } |
2146 | 1551 | ||
2147 | impl<'a> AstNode<'a> for Module<'a> { | 1552 | impl AstNode for Module { |
2148 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1553 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2149 | match syntax.kind() { | 1554 | match syntax.kind() { |
2150 | MODULE => Some(Module { syntax }), | 1555 | MODULE => Some(Module::from_repr(syntax.into_repr())), |
2151 | _ => None, | 1556 | _ => None, |
2152 | } | 1557 | } |
2153 | } | 1558 | } |
2154 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1559 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1560 | fn to_owned(&self) -> TreePtr<Module> { TreePtr::cast(self.syntax.to_owned()) } | ||
2155 | } | 1561 | } |
2156 | 1562 | ||
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 | 1563 | ||
2166 | 1564 | impl ast::VisibilityOwner for Module {} | |
2167 | impl<'a> ast::VisibilityOwner<'a> for Module<'a> {} | 1565 | impl ast::NameOwner for Module {} |
2168 | impl<'a> ast::NameOwner<'a> for Module<'a> {} | 1566 | impl ast::AttrsOwner for Module {} |
2169 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} | 1567 | impl ast::DocCommentsOwner for Module {} |
2170 | impl<'a> ast::DocCommentsOwner<'a> for Module<'a> {} | 1568 | impl Module { |
2171 | impl<'a> Module<'a> { | 1569 | pub fn item_list(&self) -> Option<&ItemList> { |
2172 | pub fn item_list(self) -> Option<ItemList<'a>> { | ||
2173 | super::child_opt(self) | 1570 | super::child_opt(self) |
2174 | } | 1571 | } |
2175 | } | 1572 | } |
2176 | 1573 | ||
2177 | // ModuleItem | 1574 | // ModuleItem |
2178 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1575 | #[derive(Debug, PartialEq, Eq, Hash)] |
2179 | pub enum ModuleItem<'a> { | 1576 | #[repr(transparent)] |
2180 | StructDef(StructDef<'a>), | 1577 | pub struct ModuleItem { |
2181 | EnumDef(EnumDef<'a>), | 1578 | pub(crate) syntax: SyntaxNode, |
2182 | FnDef(FnDef<'a>), | 1579 | } |
2183 | TraitDef(TraitDef<'a>), | 1580 | unsafe impl TransparentNewType for ModuleItem { |
2184 | TypeDef(TypeDef<'a>), | 1581 | 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 | } | 1582 | } |
2226 | 1583 | ||
2227 | impl<'a> ModuleItem<'a> {} | 1584 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1585 | pub enum ModuleItemKind<'a> { | ||
1586 | StructDef(&'a StructDef), | ||
1587 | EnumDef(&'a EnumDef), | ||
1588 | FnDef(&'a FnDef), | ||
1589 | TraitDef(&'a TraitDef), | ||
1590 | TypeDef(&'a TypeDef), | ||
1591 | ImplBlock(&'a ImplBlock), | ||
1592 | UseItem(&'a UseItem), | ||
1593 | ExternCrateItem(&'a ExternCrateItem), | ||
1594 | ConstDef(&'a ConstDef), | ||
1595 | StaticDef(&'a StaticDef), | ||
1596 | Module(&'a Module), | ||
1597 | } | ||
1598 | |||
1599 | impl AstNode for ModuleItem { | ||
1600 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
1601 | match syntax.kind() { | ||
1602 | | STRUCT_DEF | ||
1603 | | ENUM_DEF | ||
1604 | | FN_DEF | ||
1605 | | TRAIT_DEF | ||
1606 | | TYPE_DEF | ||
1607 | | IMPL_BLOCK | ||
1608 | | USE_ITEM | ||
1609 | | EXTERN_CRATE_ITEM | ||
1610 | | CONST_DEF | ||
1611 | | STATIC_DEF | ||
1612 | | MODULE => Some(ModuleItem::from_repr(syntax.into_repr())), | ||
1613 | _ => None, | ||
1614 | } | ||
1615 | } | ||
1616 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1617 | fn to_owned(&self) -> TreePtr<ModuleItem> { TreePtr::cast(self.syntax.to_owned()) } | ||
1618 | } | ||
1619 | |||
1620 | impl ModuleItem { | ||
1621 | pub fn kind(&self) -> ModuleItemKind { | ||
1622 | match self.syntax.kind() { | ||
1623 | STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(&self.syntax).unwrap()), | ||
1624 | ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()), | ||
1625 | FN_DEF => ModuleItemKind::FnDef(FnDef::cast(&self.syntax).unwrap()), | ||
1626 | TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(&self.syntax).unwrap()), | ||
1627 | TYPE_DEF => ModuleItemKind::TypeDef(TypeDef::cast(&self.syntax).unwrap()), | ||
1628 | IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(&self.syntax).unwrap()), | ||
1629 | USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(&self.syntax).unwrap()), | ||
1630 | EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(&self.syntax).unwrap()), | ||
1631 | CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(&self.syntax).unwrap()), | ||
1632 | STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(&self.syntax).unwrap()), | ||
1633 | MODULE => ModuleItemKind::Module(Module::cast(&self.syntax).unwrap()), | ||
1634 | _ => unreachable!(), | ||
1635 | } | ||
1636 | } | ||
1637 | } | ||
1638 | |||
1639 | impl ModuleItem {} | ||
2228 | 1640 | ||
2229 | // Name | 1641 | // Name |
2230 | #[derive(Debug, Clone, Copy,)] | 1642 | #[derive(Debug, PartialEq, Eq, Hash)] |
2231 | pub struct NameNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1643 | #[repr(transparent)] |
2232 | pub(crate) syntax: SyntaxNode<R>, | 1644 | pub struct Name { |
2233 | } | 1645 | 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 | } | 1646 | } |
2239 | impl<R: TreeRoot<RaTypes>> Eq for NameNode<R> {} | 1647 | unsafe impl TransparentNewType for Name { |
2240 | impl<R: TreeRoot<RaTypes>> Hash for NameNode<R> { | 1648 | type Repr = rowan::SyntaxNode<RaTypes>; |
2241 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2242 | } | 1649 | } |
2243 | 1650 | ||
2244 | impl<'a> AstNode<'a> for Name<'a> { | 1651 | impl AstNode for Name { |
2245 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1652 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2246 | match syntax.kind() { | 1653 | match syntax.kind() { |
2247 | NAME => Some(Name { syntax }), | 1654 | NAME => Some(Name::from_repr(syntax.into_repr())), |
2248 | _ => None, | 1655 | _ => None, |
2249 | } | 1656 | } |
2250 | } | 1657 | } |
2251 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1658 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1659 | fn to_owned(&self) -> TreePtr<Name> { TreePtr::cast(self.syntax.to_owned()) } | ||
2252 | } | 1660 | } |
2253 | 1661 | ||
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 | 1662 | ||
2263 | 1663 | impl Name {} | |
2264 | impl<'a> Name<'a> {} | ||
2265 | 1664 | ||
2266 | // NameRef | 1665 | // NameRef |
2267 | #[derive(Debug, Clone, Copy,)] | 1666 | #[derive(Debug, PartialEq, Eq, Hash)] |
2268 | pub struct NameRefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1667 | #[repr(transparent)] |
2269 | pub(crate) syntax: SyntaxNode<R>, | 1668 | pub struct NameRef { |
2270 | } | 1669 | 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 | } | 1670 | } |
2276 | impl<R: TreeRoot<RaTypes>> Eq for NameRefNode<R> {} | 1671 | unsafe impl TransparentNewType for NameRef { |
2277 | impl<R: TreeRoot<RaTypes>> Hash for NameRefNode<R> { | 1672 | type Repr = rowan::SyntaxNode<RaTypes>; |
2278 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2279 | } | 1673 | } |
2280 | 1674 | ||
2281 | impl<'a> AstNode<'a> for NameRef<'a> { | 1675 | impl AstNode for NameRef { |
2282 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1676 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2283 | match syntax.kind() { | 1677 | match syntax.kind() { |
2284 | NAME_REF => Some(NameRef { syntax }), | 1678 | NAME_REF => Some(NameRef::from_repr(syntax.into_repr())), |
2285 | _ => None, | 1679 | _ => None, |
2286 | } | 1680 | } |
2287 | } | 1681 | } |
2288 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1682 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1683 | fn to_owned(&self) -> TreePtr<NameRef> { TreePtr::cast(self.syntax.to_owned()) } | ||
2289 | } | 1684 | } |
2290 | 1685 | ||
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 | 1686 | ||
2300 | 1687 | impl NameRef {} | |
2301 | impl<'a> NameRef<'a> {} | ||
2302 | 1688 | ||
2303 | // NamedField | 1689 | // NamedField |
2304 | #[derive(Debug, Clone, Copy,)] | 1690 | #[derive(Debug, PartialEq, Eq, Hash)] |
2305 | pub struct NamedFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1691 | #[repr(transparent)] |
2306 | pub(crate) syntax: SyntaxNode<R>, | 1692 | pub struct NamedField { |
1693 | pub(crate) syntax: SyntaxNode, | ||
2307 | } | 1694 | } |
2308 | pub type NamedField<'a> = NamedFieldNode<RefRoot<'a>>; | 1695 | unsafe impl TransparentNewType for NamedField { |
2309 | 1696 | 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 | } | 1697 | } |
2317 | 1698 | ||
2318 | impl<'a> AstNode<'a> for NamedField<'a> { | 1699 | impl AstNode for NamedField { |
2319 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1700 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2320 | match syntax.kind() { | 1701 | match syntax.kind() { |
2321 | NAMED_FIELD => Some(NamedField { syntax }), | 1702 | NAMED_FIELD => Some(NamedField::from_repr(syntax.into_repr())), |
2322 | _ => None, | 1703 | _ => None, |
2323 | } | 1704 | } |
2324 | } | 1705 | } |
2325 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1706 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2326 | } | 1707 | 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 | } | 1708 | } |
2336 | 1709 | ||
2337 | 1710 | ||
2338 | impl<'a> NamedField<'a> { | 1711 | impl NamedField { |
2339 | pub fn name_ref(self) -> Option<NameRef<'a>> { | 1712 | pub fn name_ref(&self) -> Option<&NameRef> { |
2340 | super::child_opt(self) | 1713 | super::child_opt(self) |
2341 | } | 1714 | } |
2342 | 1715 | ||
2343 | pub fn expr(self) -> Option<Expr<'a>> { | 1716 | pub fn expr(&self) -> Option<&Expr> { |
2344 | super::child_opt(self) | 1717 | super::child_opt(self) |
2345 | } | 1718 | } |
2346 | } | 1719 | } |
2347 | 1720 | ||
2348 | // NamedFieldDef | 1721 | // NamedFieldDef |
2349 | #[derive(Debug, Clone, Copy,)] | 1722 | #[derive(Debug, PartialEq, Eq, Hash)] |
2350 | pub struct NamedFieldDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1723 | #[repr(transparent)] |
2351 | pub(crate) syntax: SyntaxNode<R>, | 1724 | pub struct NamedFieldDef { |
1725 | pub(crate) syntax: SyntaxNode, | ||
2352 | } | 1726 | } |
2353 | pub type NamedFieldDef<'a> = NamedFieldDefNode<RefRoot<'a>>; | 1727 | unsafe impl TransparentNewType for NamedFieldDef { |
2354 | 1728 | 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 | } | 1729 | } |
2362 | 1730 | ||
2363 | impl<'a> AstNode<'a> for NamedFieldDef<'a> { | 1731 | impl AstNode for NamedFieldDef { |
2364 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1732 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2365 | match syntax.kind() { | 1733 | match syntax.kind() { |
2366 | NAMED_FIELD_DEF => Some(NamedFieldDef { syntax }), | 1734 | NAMED_FIELD_DEF => Some(NamedFieldDef::from_repr(syntax.into_repr())), |
2367 | _ => None, | 1735 | _ => None, |
2368 | } | 1736 | } |
2369 | } | 1737 | } |
2370 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1738 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1739 | fn to_owned(&self) -> TreePtr<NamedFieldDef> { TreePtr::cast(self.syntax.to_owned()) } | ||
2371 | } | 1740 | } |
2372 | 1741 | ||
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 | 1742 | ||
2382 | 1743 | impl ast::VisibilityOwner for NamedFieldDef {} | |
2383 | impl<'a> ast::VisibilityOwner<'a> for NamedFieldDef<'a> {} | 1744 | impl ast::NameOwner for NamedFieldDef {} |
2384 | impl<'a> ast::NameOwner<'a> for NamedFieldDef<'a> {} | 1745 | impl ast::AttrsOwner for NamedFieldDef {} |
2385 | impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {} | 1746 | impl NamedFieldDef { |
2386 | impl<'a> NamedFieldDef<'a> { | 1747 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2387 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
2388 | super::child_opt(self) | 1748 | super::child_opt(self) |
2389 | } | 1749 | } |
2390 | } | 1750 | } |
2391 | 1751 | ||
2392 | // NamedFieldDefList | 1752 | // NamedFieldDefList |
2393 | #[derive(Debug, Clone, Copy,)] | 1753 | #[derive(Debug, PartialEq, Eq, Hash)] |
2394 | pub struct NamedFieldDefListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1754 | #[repr(transparent)] |
2395 | pub(crate) syntax: SyntaxNode<R>, | 1755 | pub struct NamedFieldDefList { |
2396 | } | 1756 | 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 | } | 1757 | } |
2402 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefListNode<R> {} | 1758 | unsafe impl TransparentNewType for NamedFieldDefList { |
2403 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefListNode<R> { | 1759 | type Repr = rowan::SyntaxNode<RaTypes>; |
2404 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2405 | } | 1760 | } |
2406 | 1761 | ||
2407 | impl<'a> AstNode<'a> for NamedFieldDefList<'a> { | 1762 | impl AstNode for NamedFieldDefList { |
2408 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1763 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2409 | match syntax.kind() { | 1764 | match syntax.kind() { |
2410 | NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList { syntax }), | 1765 | NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList::from_repr(syntax.into_repr())), |
2411 | _ => None, | 1766 | _ => None, |
2412 | } | 1767 | } |
2413 | } | 1768 | } |
2414 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1769 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1770 | fn to_owned(&self) -> TreePtr<NamedFieldDefList> { TreePtr::cast(self.syntax.to_owned()) } | ||
2415 | } | 1771 | } |
2416 | 1772 | ||
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 | 1773 | ||
2426 | 1774 | impl NamedFieldDefList { | |
2427 | impl<'a> NamedFieldDefList<'a> { | 1775 | pub fn fields(&self) -> impl Iterator<Item = &NamedFieldDef> { |
2428 | pub fn fields(self) -> impl Iterator<Item = NamedFieldDef<'a>> + 'a { | ||
2429 | super::children(self) | 1776 | super::children(self) |
2430 | } | 1777 | } |
2431 | } | 1778 | } |
2432 | 1779 | ||
2433 | // NamedFieldList | 1780 | // NamedFieldList |
2434 | #[derive(Debug, Clone, Copy,)] | 1781 | #[derive(Debug, PartialEq, Eq, Hash)] |
2435 | pub struct NamedFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1782 | #[repr(transparent)] |
2436 | pub(crate) syntax: SyntaxNode<R>, | 1783 | pub struct NamedFieldList { |
2437 | } | 1784 | 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 | } | 1785 | } |
2443 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldListNode<R> {} | 1786 | unsafe impl TransparentNewType for NamedFieldList { |
2444 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldListNode<R> { | 1787 | type Repr = rowan::SyntaxNode<RaTypes>; |
2445 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2446 | } | 1788 | } |
2447 | 1789 | ||
2448 | impl<'a> AstNode<'a> for NamedFieldList<'a> { | 1790 | impl AstNode for NamedFieldList { |
2449 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1791 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2450 | match syntax.kind() { | 1792 | match syntax.kind() { |
2451 | NAMED_FIELD_LIST => Some(NamedFieldList { syntax }), | 1793 | NAMED_FIELD_LIST => Some(NamedFieldList::from_repr(syntax.into_repr())), |
2452 | _ => None, | 1794 | _ => None, |
2453 | } | 1795 | } |
2454 | } | 1796 | } |
2455 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1797 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2456 | } | 1798 | 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 | } | 1799 | } |
2466 | 1800 | ||
2467 | 1801 | ||
2468 | impl<'a> NamedFieldList<'a> { | 1802 | impl NamedFieldList { |
2469 | pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a { | 1803 | pub fn fields(&self) -> impl Iterator<Item = &NamedField> { |
2470 | super::children(self) | 1804 | super::children(self) |
2471 | } | 1805 | } |
2472 | } | 1806 | } |
2473 | 1807 | ||
2474 | // NeverType | 1808 | // NeverType |
2475 | #[derive(Debug, Clone, Copy,)] | 1809 | #[derive(Debug, PartialEq, Eq, Hash)] |
2476 | pub struct NeverTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1810 | #[repr(transparent)] |
2477 | pub(crate) syntax: SyntaxNode<R>, | 1811 | pub struct NeverType { |
2478 | } | 1812 | 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 | } | 1813 | } |
2484 | impl<R: TreeRoot<RaTypes>> Eq for NeverTypeNode<R> {} | 1814 | unsafe impl TransparentNewType for NeverType { |
2485 | impl<R: TreeRoot<RaTypes>> Hash for NeverTypeNode<R> { | 1815 | type Repr = rowan::SyntaxNode<RaTypes>; |
2486 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2487 | } | 1816 | } |
2488 | 1817 | ||
2489 | impl<'a> AstNode<'a> for NeverType<'a> { | 1818 | impl AstNode for NeverType { |
2490 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1819 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2491 | match syntax.kind() { | 1820 | match syntax.kind() { |
2492 | NEVER_TYPE => Some(NeverType { syntax }), | 1821 | NEVER_TYPE => Some(NeverType::from_repr(syntax.into_repr())), |
2493 | _ => None, | 1822 | _ => None, |
2494 | } | 1823 | } |
2495 | } | 1824 | } |
2496 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1825 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2497 | } | 1826 | 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 | } | 1827 | } |
2507 | 1828 | ||
2508 | 1829 | ||
2509 | impl<'a> NeverType<'a> {} | 1830 | impl NeverType {} |
2510 | 1831 | ||
2511 | // NominalDef | 1832 | // NominalDef |
1833 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1834 | #[repr(transparent)] | ||
1835 | pub struct NominalDef { | ||
1836 | pub(crate) syntax: SyntaxNode, | ||
1837 | } | ||
1838 | unsafe impl TransparentNewType for NominalDef { | ||
1839 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1840 | } | ||
1841 | |||
2512 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 1842 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2513 | pub enum NominalDef<'a> { | 1843 | pub enum NominalDefKind<'a> { |
2514 | StructDef(StructDef<'a>), | 1844 | StructDef(&'a StructDef), |
2515 | EnumDef(EnumDef<'a>), | 1845 | EnumDef(&'a EnumDef), |
2516 | } | 1846 | } |
2517 | 1847 | ||
2518 | impl<'a> AstNode<'a> for NominalDef<'a> { | 1848 | impl AstNode for NominalDef { |
2519 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1849 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2520 | match syntax.kind() { | 1850 | match syntax.kind() { |
2521 | STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })), | 1851 | | STRUCT_DEF |
2522 | ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })), | 1852 | | ENUM_DEF => Some(NominalDef::from_repr(syntax.into_repr())), |
2523 | _ => None, | 1853 | _ => None, |
2524 | } | 1854 | } |
2525 | } | 1855 | } |
2526 | fn syntax(self) -> SyntaxNodeRef<'a> { | 1856 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2527 | match self { | 1857 | fn to_owned(&self) -> TreePtr<NominalDef> { TreePtr::cast(self.syntax.to_owned()) } |
2528 | NominalDef::StructDef(inner) => inner.syntax(), | 1858 | } |
2529 | NominalDef::EnumDef(inner) => inner.syntax(), | 1859 | |
1860 | impl NominalDef { | ||
1861 | pub fn kind(&self) -> NominalDefKind { | ||
1862 | match self.syntax.kind() { | ||
1863 | STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(&self.syntax).unwrap()), | ||
1864 | ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(&self.syntax).unwrap()), | ||
1865 | _ => unreachable!(), | ||
2530 | } | 1866 | } |
2531 | } | 1867 | } |
2532 | } | 1868 | } |
2533 | 1869 | ||
2534 | impl<'a> ast::NameOwner<'a> for NominalDef<'a> {} | 1870 | impl ast::NameOwner for NominalDef {} |
2535 | impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {} | 1871 | impl ast::TypeParamsOwner for NominalDef {} |
2536 | impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} | 1872 | impl ast::AttrsOwner for NominalDef {} |
2537 | impl<'a> NominalDef<'a> {} | 1873 | impl NominalDef {} |
2538 | 1874 | ||
2539 | // Param | 1875 | // Param |
2540 | #[derive(Debug, Clone, Copy,)] | 1876 | #[derive(Debug, PartialEq, Eq, Hash)] |
2541 | pub struct ParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1877 | #[repr(transparent)] |
2542 | pub(crate) syntax: SyntaxNode<R>, | 1878 | pub struct Param { |
2543 | } | 1879 | 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 | } | 1880 | } |
2549 | impl<R: TreeRoot<RaTypes>> Eq for ParamNode<R> {} | 1881 | unsafe impl TransparentNewType for Param { |
2550 | impl<R: TreeRoot<RaTypes>> Hash for ParamNode<R> { | 1882 | type Repr = rowan::SyntaxNode<RaTypes>; |
2551 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2552 | } | 1883 | } |
2553 | 1884 | ||
2554 | impl<'a> AstNode<'a> for Param<'a> { | 1885 | impl AstNode for Param { |
2555 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1886 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2556 | match syntax.kind() { | 1887 | match syntax.kind() { |
2557 | PARAM => Some(Param { syntax }), | 1888 | PARAM => Some(Param::from_repr(syntax.into_repr())), |
2558 | _ => None, | 1889 | _ => None, |
2559 | } | 1890 | } |
2560 | } | 1891 | } |
2561 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1892 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2562 | } | 1893 | 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 | } | 1894 | } |
2572 | 1895 | ||
2573 | 1896 | ||
2574 | impl<'a> Param<'a> { | 1897 | impl Param { |
2575 | pub fn pat(self) -> Option<Pat<'a>> { | 1898 | pub fn pat(&self) -> Option<&Pat> { |
2576 | super::child_opt(self) | 1899 | super::child_opt(self) |
2577 | } | 1900 | } |
2578 | 1901 | ||
2579 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1902 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2580 | super::child_opt(self) | 1903 | super::child_opt(self) |
2581 | } | 1904 | } |
2582 | } | 1905 | } |
2583 | 1906 | ||
2584 | // ParamList | 1907 | // ParamList |
2585 | #[derive(Debug, Clone, Copy,)] | 1908 | #[derive(Debug, PartialEq, Eq, Hash)] |
2586 | pub struct ParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1909 | #[repr(transparent)] |
2587 | pub(crate) syntax: SyntaxNode<R>, | 1910 | pub struct ParamList { |
1911 | pub(crate) syntax: SyntaxNode, | ||
2588 | } | 1912 | } |
2589 | pub type ParamList<'a> = ParamListNode<RefRoot<'a>>; | 1913 | unsafe impl TransparentNewType for ParamList { |
2590 | 1914 | 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 | } | 1915 | } |
2598 | 1916 | ||
2599 | impl<'a> AstNode<'a> for ParamList<'a> { | 1917 | impl AstNode for ParamList { |
2600 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1918 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2601 | match syntax.kind() { | 1919 | match syntax.kind() { |
2602 | PARAM_LIST => Some(ParamList { syntax }), | 1920 | PARAM_LIST => Some(ParamList::from_repr(syntax.into_repr())), |
2603 | _ => None, | 1921 | _ => None, |
2604 | } | 1922 | } |
2605 | } | 1923 | } |
2606 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1924 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2607 | } | 1925 | 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 | } | 1926 | } |
2617 | 1927 | ||
2618 | 1928 | ||
2619 | impl<'a> ParamList<'a> { | 1929 | impl ParamList { |
2620 | pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { | 1930 | pub fn params(&self) -> impl Iterator<Item = &Param> { |
2621 | super::children(self) | 1931 | super::children(self) |
2622 | } | 1932 | } |
2623 | 1933 | ||
2624 | pub fn self_param(self) -> Option<SelfParam<'a>> { | 1934 | pub fn self_param(&self) -> Option<&SelfParam> { |
2625 | super::child_opt(self) | 1935 | super::child_opt(self) |
2626 | } | 1936 | } |
2627 | } | 1937 | } |
2628 | 1938 | ||
2629 | // ParenExpr | 1939 | // ParenExpr |
2630 | #[derive(Debug, Clone, Copy,)] | 1940 | #[derive(Debug, PartialEq, Eq, Hash)] |
2631 | pub struct ParenExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1941 | #[repr(transparent)] |
2632 | pub(crate) syntax: SyntaxNode<R>, | 1942 | pub struct ParenExpr { |
2633 | } | 1943 | 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 | } | 1944 | } |
2639 | impl<R: TreeRoot<RaTypes>> Eq for ParenExprNode<R> {} | 1945 | unsafe impl TransparentNewType for ParenExpr { |
2640 | impl<R: TreeRoot<RaTypes>> Hash for ParenExprNode<R> { | 1946 | type Repr = rowan::SyntaxNode<RaTypes>; |
2641 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2642 | } | 1947 | } |
2643 | 1948 | ||
2644 | impl<'a> AstNode<'a> for ParenExpr<'a> { | 1949 | impl AstNode for ParenExpr { |
2645 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1950 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2646 | match syntax.kind() { | 1951 | match syntax.kind() { |
2647 | PAREN_EXPR => Some(ParenExpr { syntax }), | 1952 | PAREN_EXPR => Some(ParenExpr::from_repr(syntax.into_repr())), |
2648 | _ => None, | 1953 | _ => None, |
2649 | } | 1954 | } |
2650 | } | 1955 | } |
2651 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1956 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1957 | fn to_owned(&self) -> TreePtr<ParenExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
2652 | } | 1958 | } |
2653 | 1959 | ||
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 | 1960 | ||
2663 | 1961 | impl ParenExpr { | |
2664 | impl<'a> ParenExpr<'a> { | 1962 | pub fn expr(&self) -> Option<&Expr> { |
2665 | pub fn expr(self) -> Option<Expr<'a>> { | ||
2666 | super::child_opt(self) | 1963 | super::child_opt(self) |
2667 | } | 1964 | } |
2668 | } | 1965 | } |
2669 | 1966 | ||
2670 | // ParenType | 1967 | // ParenType |
2671 | #[derive(Debug, Clone, Copy,)] | 1968 | #[derive(Debug, PartialEq, Eq, Hash)] |
2672 | pub struct ParenTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1969 | #[repr(transparent)] |
2673 | pub(crate) syntax: SyntaxNode<R>, | 1970 | pub struct ParenType { |
1971 | pub(crate) syntax: SyntaxNode, | ||
2674 | } | 1972 | } |
2675 | pub type ParenType<'a> = ParenTypeNode<RefRoot<'a>>; | 1973 | unsafe impl TransparentNewType for ParenType { |
2676 | 1974 | 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 | } | 1975 | } |
2684 | 1976 | ||
2685 | impl<'a> AstNode<'a> for ParenType<'a> { | 1977 | impl AstNode for ParenType { |
2686 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1978 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2687 | match syntax.kind() { | 1979 | match syntax.kind() { |
2688 | PAREN_TYPE => Some(ParenType { syntax }), | 1980 | PAREN_TYPE => Some(ParenType::from_repr(syntax.into_repr())), |
2689 | _ => None, | 1981 | _ => None, |
2690 | } | 1982 | } |
2691 | } | 1983 | } |
2692 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1984 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2693 | } | 1985 | 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 | } | 1986 | } |
2703 | 1987 | ||
2704 | 1988 | ||
2705 | impl<'a> ParenType<'a> { | 1989 | impl ParenType { |
2706 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 1990 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2707 | super::child_opt(self) | 1991 | super::child_opt(self) |
2708 | } | 1992 | } |
2709 | } | 1993 | } |
2710 | 1994 | ||
2711 | // Pat | 1995 | // Pat |
1996 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1997 | #[repr(transparent)] | ||
1998 | pub struct Pat { | ||
1999 | pub(crate) syntax: SyntaxNode, | ||
2000 | } | ||
2001 | unsafe impl TransparentNewType for Pat { | ||
2002 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
2003 | } | ||
2004 | |||
2712 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 2005 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2713 | pub enum Pat<'a> { | 2006 | pub enum PatKind<'a> { |
2714 | RefPat(RefPat<'a>), | 2007 | RefPat(&'a RefPat), |
2715 | BindPat(BindPat<'a>), | 2008 | BindPat(&'a BindPat), |
2716 | PlaceholderPat(PlaceholderPat<'a>), | 2009 | PlaceholderPat(&'a PlaceholderPat), |
2717 | PathPat(PathPat<'a>), | 2010 | PathPat(&'a PathPat), |
2718 | StructPat(StructPat<'a>), | 2011 | StructPat(&'a StructPat), |
2719 | FieldPatList(FieldPatList<'a>), | 2012 | FieldPatList(&'a FieldPatList), |
2720 | TupleStructPat(TupleStructPat<'a>), | 2013 | TupleStructPat(&'a TupleStructPat), |
2721 | TuplePat(TuplePat<'a>), | 2014 | TuplePat(&'a TuplePat), |
2722 | SlicePat(SlicePat<'a>), | 2015 | SlicePat(&'a SlicePat), |
2723 | RangePat(RangePat<'a>), | 2016 | RangePat(&'a RangePat), |
2724 | } | 2017 | } |
2725 | 2018 | ||
2726 | impl<'a> AstNode<'a> for Pat<'a> { | 2019 | impl AstNode for Pat { |
2727 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2020 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2728 | match syntax.kind() { | 2021 | match syntax.kind() { |
2729 | REF_PAT => Some(Pat::RefPat(RefPat { syntax })), | 2022 | | REF_PAT |
2730 | BIND_PAT => Some(Pat::BindPat(BindPat { syntax })), | 2023 | | BIND_PAT |
2731 | PLACEHOLDER_PAT => Some(Pat::PlaceholderPat(PlaceholderPat { syntax })), | 2024 | | PLACEHOLDER_PAT |
2732 | PATH_PAT => Some(Pat::PathPat(PathPat { syntax })), | 2025 | | PATH_PAT |
2733 | STRUCT_PAT => Some(Pat::StructPat(StructPat { syntax })), | 2026 | | STRUCT_PAT |
2734 | FIELD_PAT_LIST => Some(Pat::FieldPatList(FieldPatList { syntax })), | 2027 | | FIELD_PAT_LIST |
2735 | TUPLE_STRUCT_PAT => Some(Pat::TupleStructPat(TupleStructPat { syntax })), | 2028 | | TUPLE_STRUCT_PAT |
2736 | TUPLE_PAT => Some(Pat::TuplePat(TuplePat { syntax })), | 2029 | | TUPLE_PAT |
2737 | SLICE_PAT => Some(Pat::SlicePat(SlicePat { syntax })), | 2030 | | SLICE_PAT |
2738 | RANGE_PAT => Some(Pat::RangePat(RangePat { syntax })), | 2031 | | RANGE_PAT => Some(Pat::from_repr(syntax.into_repr())), |
2739 | _ => None, | 2032 | _ => None, |
2740 | } | 2033 | } |
2741 | } | 2034 | } |
2742 | fn syntax(self) -> SyntaxNodeRef<'a> { | 2035 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2743 | match self { | 2036 | fn to_owned(&self) -> TreePtr<Pat> { TreePtr::cast(self.syntax.to_owned()) } |
2744 | Pat::RefPat(inner) => inner.syntax(), | 2037 | } |
2745 | Pat::BindPat(inner) => inner.syntax(), | 2038 | |
2746 | Pat::PlaceholderPat(inner) => inner.syntax(), | 2039 | impl Pat { |
2747 | Pat::PathPat(inner) => inner.syntax(), | 2040 | pub fn kind(&self) -> PatKind { |
2748 | Pat::StructPat(inner) => inner.syntax(), | 2041 | match self.syntax.kind() { |
2749 | Pat::FieldPatList(inner) => inner.syntax(), | 2042 | REF_PAT => PatKind::RefPat(RefPat::cast(&self.syntax).unwrap()), |
2750 | Pat::TupleStructPat(inner) => inner.syntax(), | 2043 | BIND_PAT => PatKind::BindPat(BindPat::cast(&self.syntax).unwrap()), |
2751 | Pat::TuplePat(inner) => inner.syntax(), | 2044 | PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(&self.syntax).unwrap()), |
2752 | Pat::SlicePat(inner) => inner.syntax(), | 2045 | PATH_PAT => PatKind::PathPat(PathPat::cast(&self.syntax).unwrap()), |
2753 | Pat::RangePat(inner) => inner.syntax(), | 2046 | STRUCT_PAT => PatKind::StructPat(StructPat::cast(&self.syntax).unwrap()), |
2047 | FIELD_PAT_LIST => PatKind::FieldPatList(FieldPatList::cast(&self.syntax).unwrap()), | ||
2048 | TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(&self.syntax).unwrap()), | ||
2049 | TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(&self.syntax).unwrap()), | ||
2050 | SLICE_PAT => PatKind::SlicePat(SlicePat::cast(&self.syntax).unwrap()), | ||
2051 | RANGE_PAT => PatKind::RangePat(RangePat::cast(&self.syntax).unwrap()), | ||
2052 | _ => unreachable!(), | ||
2754 | } | 2053 | } |
2755 | } | 2054 | } |
2756 | } | 2055 | } |
2757 | 2056 | ||
2758 | impl<'a> Pat<'a> {} | 2057 | impl Pat {} |
2759 | 2058 | ||
2760 | // Path | 2059 | // Path |
2761 | #[derive(Debug, Clone, Copy,)] | 2060 | #[derive(Debug, PartialEq, Eq, Hash)] |
2762 | pub struct PathNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2061 | #[repr(transparent)] |
2763 | pub(crate) syntax: SyntaxNode<R>, | 2062 | pub struct Path { |
2764 | } | 2063 | 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 | } | 2064 | } |
2770 | impl<R: TreeRoot<RaTypes>> Eq for PathNode<R> {} | 2065 | unsafe impl TransparentNewType for Path { |
2771 | impl<R: TreeRoot<RaTypes>> Hash for PathNode<R> { | 2066 | type Repr = rowan::SyntaxNode<RaTypes>; |
2772 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2773 | } | 2067 | } |
2774 | 2068 | ||
2775 | impl<'a> AstNode<'a> for Path<'a> { | 2069 | impl AstNode for Path { |
2776 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2070 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2777 | match syntax.kind() { | 2071 | match syntax.kind() { |
2778 | PATH => Some(Path { syntax }), | 2072 | PATH => Some(Path::from_repr(syntax.into_repr())), |
2779 | _ => None, | 2073 | _ => None, |
2780 | } | 2074 | } |
2781 | } | 2075 | } |
2782 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2076 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2783 | } | 2077 | 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 | } | 2078 | } |
2793 | 2079 | ||
2794 | 2080 | ||
2795 | impl<'a> Path<'a> { | 2081 | impl Path { |
2796 | pub fn segment(self) -> Option<PathSegment<'a>> { | 2082 | pub fn segment(&self) -> Option<&PathSegment> { |
2797 | super::child_opt(self) | 2083 | super::child_opt(self) |
2798 | } | 2084 | } |
2799 | 2085 | ||
2800 | pub fn qualifier(self) -> Option<Path<'a>> { | 2086 | pub fn qualifier(&self) -> Option<&Path> { |
2801 | super::child_opt(self) | 2087 | super::child_opt(self) |
2802 | } | 2088 | } |
2803 | } | 2089 | } |
2804 | 2090 | ||
2805 | // PathExpr | 2091 | // PathExpr |
2806 | #[derive(Debug, Clone, Copy,)] | 2092 | #[derive(Debug, PartialEq, Eq, Hash)] |
2807 | pub struct PathExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2093 | #[repr(transparent)] |
2808 | pub(crate) syntax: SyntaxNode<R>, | 2094 | pub struct PathExpr { |
2095 | pub(crate) syntax: SyntaxNode, | ||
2809 | } | 2096 | } |
2810 | pub type PathExpr<'a> = PathExprNode<RefRoot<'a>>; | 2097 | unsafe impl TransparentNewType for PathExpr { |
2811 | 2098 | 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 | } | 2099 | } |
2819 | 2100 | ||
2820 | impl<'a> AstNode<'a> for PathExpr<'a> { | 2101 | impl AstNode for PathExpr { |
2821 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2102 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2822 | match syntax.kind() { | 2103 | match syntax.kind() { |
2823 | PATH_EXPR => Some(PathExpr { syntax }), | 2104 | PATH_EXPR => Some(PathExpr::from_repr(syntax.into_repr())), |
2824 | _ => None, | 2105 | _ => None, |
2825 | } | 2106 | } |
2826 | } | 2107 | } |
2827 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2108 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2828 | } | 2109 | 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 | } | 2110 | } |
2838 | 2111 | ||
2839 | 2112 | ||
2840 | impl<'a> PathExpr<'a> { | 2113 | impl PathExpr { |
2841 | pub fn path(self) -> Option<Path<'a>> { | 2114 | pub fn path(&self) -> Option<&Path> { |
2842 | super::child_opt(self) | 2115 | super::child_opt(self) |
2843 | } | 2116 | } |
2844 | } | 2117 | } |
2845 | 2118 | ||
2846 | // PathPat | 2119 | // PathPat |
2847 | #[derive(Debug, Clone, Copy,)] | 2120 | #[derive(Debug, PartialEq, Eq, Hash)] |
2848 | pub struct PathPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2121 | #[repr(transparent)] |
2849 | pub(crate) syntax: SyntaxNode<R>, | 2122 | pub struct PathPat { |
2123 | pub(crate) syntax: SyntaxNode, | ||
2850 | } | 2124 | } |
2851 | pub type PathPat<'a> = PathPatNode<RefRoot<'a>>; | 2125 | unsafe impl TransparentNewType for PathPat { |
2852 | 2126 | 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 | } | 2127 | } |
2860 | 2128 | ||
2861 | impl<'a> AstNode<'a> for PathPat<'a> { | 2129 | impl AstNode for PathPat { |
2862 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2130 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2863 | match syntax.kind() { | 2131 | match syntax.kind() { |
2864 | PATH_PAT => Some(PathPat { syntax }), | 2132 | PATH_PAT => Some(PathPat::from_repr(syntax.into_repr())), |
2865 | _ => None, | 2133 | _ => None, |
2866 | } | 2134 | } |
2867 | } | 2135 | } |
2868 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2136 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2869 | } | 2137 | 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 | } | 2138 | } |
2879 | 2139 | ||
2880 | 2140 | ||
2881 | impl<'a> PathPat<'a> {} | 2141 | impl PathPat {} |
2882 | 2142 | ||
2883 | // PathSegment | 2143 | // PathSegment |
2884 | #[derive(Debug, Clone, Copy,)] | 2144 | #[derive(Debug, PartialEq, Eq, Hash)] |
2885 | pub struct PathSegmentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2145 | #[repr(transparent)] |
2886 | pub(crate) syntax: SyntaxNode<R>, | 2146 | pub struct PathSegment { |
2887 | } | 2147 | 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 | } | 2148 | } |
2893 | impl<R: TreeRoot<RaTypes>> Eq for PathSegmentNode<R> {} | 2149 | unsafe impl TransparentNewType for PathSegment { |
2894 | impl<R: TreeRoot<RaTypes>> Hash for PathSegmentNode<R> { | 2150 | type Repr = rowan::SyntaxNode<RaTypes>; |
2895 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2896 | } | 2151 | } |
2897 | 2152 | ||
2898 | impl<'a> AstNode<'a> for PathSegment<'a> { | 2153 | impl AstNode for PathSegment { |
2899 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2154 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2900 | match syntax.kind() { | 2155 | match syntax.kind() { |
2901 | PATH_SEGMENT => Some(PathSegment { syntax }), | 2156 | PATH_SEGMENT => Some(PathSegment::from_repr(syntax.into_repr())), |
2902 | _ => None, | 2157 | _ => None, |
2903 | } | 2158 | } |
2904 | } | 2159 | } |
2905 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2160 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2161 | fn to_owned(&self) -> TreePtr<PathSegment> { TreePtr::cast(self.syntax.to_owned()) } | ||
2906 | } | 2162 | } |
2907 | 2163 | ||
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 | 2164 | ||
2917 | 2165 | impl PathSegment { | |
2918 | impl<'a> PathSegment<'a> { | 2166 | pub fn name_ref(&self) -> Option<&NameRef> { |
2919 | pub fn name_ref(self) -> Option<NameRef<'a>> { | ||
2920 | super::child_opt(self) | 2167 | super::child_opt(self) |
2921 | } | 2168 | } |
2922 | } | 2169 | } |
2923 | 2170 | ||
2924 | // PathType | 2171 | // PathType |
2925 | #[derive(Debug, Clone, Copy,)] | 2172 | #[derive(Debug, PartialEq, Eq, Hash)] |
2926 | pub struct PathTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2173 | #[repr(transparent)] |
2927 | pub(crate) syntax: SyntaxNode<R>, | 2174 | pub struct PathType { |
2928 | } | 2175 | 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 | } | 2176 | } |
2934 | impl<R: TreeRoot<RaTypes>> Eq for PathTypeNode<R> {} | 2177 | unsafe impl TransparentNewType for PathType { |
2935 | impl<R: TreeRoot<RaTypes>> Hash for PathTypeNode<R> { | 2178 | type Repr = rowan::SyntaxNode<RaTypes>; |
2936 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2937 | } | 2179 | } |
2938 | 2180 | ||
2939 | impl<'a> AstNode<'a> for PathType<'a> { | 2181 | impl AstNode for PathType { |
2940 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2182 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2941 | match syntax.kind() { | 2183 | match syntax.kind() { |
2942 | PATH_TYPE => Some(PathType { syntax }), | 2184 | PATH_TYPE => Some(PathType::from_repr(syntax.into_repr())), |
2943 | _ => None, | 2185 | _ => None, |
2944 | } | 2186 | } |
2945 | } | 2187 | } |
2946 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2188 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2947 | } | 2189 | 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 | } | 2190 | } |
2957 | 2191 | ||
2958 | 2192 | ||
2959 | impl<'a> PathType<'a> { | 2193 | impl PathType { |
2960 | pub fn path(self) -> Option<Path<'a>> { | 2194 | pub fn path(&self) -> Option<&Path> { |
2961 | super::child_opt(self) | 2195 | super::child_opt(self) |
2962 | } | 2196 | } |
2963 | } | 2197 | } |
2964 | 2198 | ||
2965 | // PlaceholderPat | 2199 | // PlaceholderPat |
2966 | #[derive(Debug, Clone, Copy,)] | 2200 | #[derive(Debug, PartialEq, Eq, Hash)] |
2967 | pub struct PlaceholderPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2201 | #[repr(transparent)] |
2968 | pub(crate) syntax: SyntaxNode<R>, | 2202 | pub struct PlaceholderPat { |
2203 | pub(crate) syntax: SyntaxNode, | ||
2969 | } | 2204 | } |
2970 | pub type PlaceholderPat<'a> = PlaceholderPatNode<RefRoot<'a>>; | 2205 | unsafe impl TransparentNewType for PlaceholderPat { |
2971 | 2206 | 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 | } | 2207 | } |
2979 | 2208 | ||
2980 | impl<'a> AstNode<'a> for PlaceholderPat<'a> { | 2209 | impl AstNode for PlaceholderPat { |
2981 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2210 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
2982 | match syntax.kind() { | 2211 | match syntax.kind() { |
2983 | PLACEHOLDER_PAT => Some(PlaceholderPat { syntax }), | 2212 | PLACEHOLDER_PAT => Some(PlaceholderPat::from_repr(syntax.into_repr())), |
2984 | _ => None, | 2213 | _ => None, |
2985 | } | 2214 | } |
2986 | } | 2215 | } |
2987 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2216 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2988 | } | 2217 | 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 | } | 2218 | } |
2998 | 2219 | ||
2999 | 2220 | ||
3000 | impl<'a> PlaceholderPat<'a> {} | 2221 | impl PlaceholderPat {} |
3001 | 2222 | ||
3002 | // PlaceholderType | 2223 | // PlaceholderType |
3003 | #[derive(Debug, Clone, Copy,)] | 2224 | #[derive(Debug, PartialEq, Eq, Hash)] |
3004 | pub struct PlaceholderTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2225 | #[repr(transparent)] |
3005 | pub(crate) syntax: SyntaxNode<R>, | 2226 | pub struct PlaceholderType { |
2227 | pub(crate) syntax: SyntaxNode, | ||
3006 | } | 2228 | } |
3007 | pub type PlaceholderType<'a> = PlaceholderTypeNode<RefRoot<'a>>; | 2229 | unsafe impl TransparentNewType for PlaceholderType { |
3008 | 2230 | 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 | } | 2231 | } |
3016 | 2232 | ||
3017 | impl<'a> AstNode<'a> for PlaceholderType<'a> { | 2233 | impl AstNode for PlaceholderType { |
3018 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2234 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3019 | match syntax.kind() { | 2235 | match syntax.kind() { |
3020 | PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }), | 2236 | PLACEHOLDER_TYPE => Some(PlaceholderType::from_repr(syntax.into_repr())), |
3021 | _ => None, | 2237 | _ => None, |
3022 | } | 2238 | } |
3023 | } | 2239 | } |
3024 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2240 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3025 | } | 2241 | 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 | } | 2242 | } |
3035 | 2243 | ||
3036 | 2244 | ||
3037 | impl<'a> PlaceholderType<'a> {} | 2245 | impl PlaceholderType {} |
3038 | 2246 | ||
3039 | // PointerType | 2247 | // PointerType |
3040 | #[derive(Debug, Clone, Copy,)] | 2248 | #[derive(Debug, PartialEq, Eq, Hash)] |
3041 | pub struct PointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2249 | #[repr(transparent)] |
3042 | pub(crate) syntax: SyntaxNode<R>, | 2250 | pub struct PointerType { |
3043 | } | 2251 | 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 | } | 2252 | } |
3049 | impl<R: TreeRoot<RaTypes>> Eq for PointerTypeNode<R> {} | 2253 | unsafe impl TransparentNewType for PointerType { |
3050 | impl<R: TreeRoot<RaTypes>> Hash for PointerTypeNode<R> { | 2254 | type Repr = rowan::SyntaxNode<RaTypes>; |
3051 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3052 | } | 2255 | } |
3053 | 2256 | ||
3054 | impl<'a> AstNode<'a> for PointerType<'a> { | 2257 | impl AstNode for PointerType { |
3055 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2258 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3056 | match syntax.kind() { | 2259 | match syntax.kind() { |
3057 | POINTER_TYPE => Some(PointerType { syntax }), | 2260 | POINTER_TYPE => Some(PointerType::from_repr(syntax.into_repr())), |
3058 | _ => None, | 2261 | _ => None, |
3059 | } | 2262 | } |
3060 | } | 2263 | } |
3061 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2264 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2265 | fn to_owned(&self) -> TreePtr<PointerType> { TreePtr::cast(self.syntax.to_owned()) } | ||
3062 | } | 2266 | } |
3063 | 2267 | ||
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 | 2268 | ||
3073 | 2269 | impl PointerType { | |
3074 | impl<'a> PointerType<'a> { | 2270 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3075 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | ||
3076 | super::child_opt(self) | 2271 | super::child_opt(self) |
3077 | } | 2272 | } |
3078 | } | 2273 | } |
3079 | 2274 | ||
3080 | // PosField | 2275 | // PosField |
3081 | #[derive(Debug, Clone, Copy,)] | 2276 | #[derive(Debug, PartialEq, Eq, Hash)] |
3082 | pub struct PosFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2277 | #[repr(transparent)] |
3083 | pub(crate) syntax: SyntaxNode<R>, | 2278 | pub struct PosField { |
3084 | } | 2279 | 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 | } | 2280 | } |
3090 | impl<R: TreeRoot<RaTypes>> Eq for PosFieldNode<R> {} | 2281 | unsafe impl TransparentNewType for PosField { |
3091 | impl<R: TreeRoot<RaTypes>> Hash for PosFieldNode<R> { | 2282 | type Repr = rowan::SyntaxNode<RaTypes>; |
3092 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3093 | } | 2283 | } |
3094 | 2284 | ||
3095 | impl<'a> AstNode<'a> for PosField<'a> { | 2285 | impl AstNode for PosField { |
3096 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2286 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3097 | match syntax.kind() { | 2287 | match syntax.kind() { |
3098 | POS_FIELD => Some(PosField { syntax }), | 2288 | POS_FIELD => Some(PosField::from_repr(syntax.into_repr())), |
3099 | _ => None, | 2289 | _ => None, |
3100 | } | 2290 | } |
3101 | } | 2291 | } |
3102 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2292 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3103 | } | 2293 | 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 | } | 2294 | } |
3113 | 2295 | ||
3114 | 2296 | ||
3115 | impl<'a> ast::VisibilityOwner<'a> for PosField<'a> {} | 2297 | impl ast::VisibilityOwner for PosField {} |
3116 | impl<'a> ast::AttrsOwner<'a> for PosField<'a> {} | 2298 | impl ast::AttrsOwner for PosField {} |
3117 | impl<'a> PosField<'a> { | 2299 | impl PosField { |
3118 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2300 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3119 | super::child_opt(self) | 2301 | super::child_opt(self) |
3120 | } | 2302 | } |
3121 | } | 2303 | } |
3122 | 2304 | ||
3123 | // PosFieldList | 2305 | // PosFieldList |
3124 | #[derive(Debug, Clone, Copy,)] | 2306 | #[derive(Debug, PartialEq, Eq, Hash)] |
3125 | pub struct PosFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2307 | #[repr(transparent)] |
3126 | pub(crate) syntax: SyntaxNode<R>, | 2308 | pub struct PosFieldList { |
3127 | } | 2309 | 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 | } | 2310 | } |
3133 | impl<R: TreeRoot<RaTypes>> Eq for PosFieldListNode<R> {} | 2311 | unsafe impl TransparentNewType for PosFieldList { |
3134 | impl<R: TreeRoot<RaTypes>> Hash for PosFieldListNode<R> { | 2312 | type Repr = rowan::SyntaxNode<RaTypes>; |
3135 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3136 | } | 2313 | } |
3137 | 2314 | ||
3138 | impl<'a> AstNode<'a> for PosFieldList<'a> { | 2315 | impl AstNode for PosFieldList { |
3139 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2316 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3140 | match syntax.kind() { | 2317 | match syntax.kind() { |
3141 | POS_FIELD_LIST => Some(PosFieldList { syntax }), | 2318 | POS_FIELD_LIST => Some(PosFieldList::from_repr(syntax.into_repr())), |
3142 | _ => None, | 2319 | _ => None, |
3143 | } | 2320 | } |
3144 | } | 2321 | } |
3145 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2322 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3146 | } | 2323 | 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 | } | 2324 | } |
3156 | 2325 | ||
3157 | 2326 | ||
3158 | impl<'a> PosFieldList<'a> { | 2327 | impl PosFieldList { |
3159 | pub fn fields(self) -> impl Iterator<Item = PosField<'a>> + 'a { | 2328 | pub fn fields(&self) -> impl Iterator<Item = &PosField> { |
3160 | super::children(self) | 2329 | super::children(self) |
3161 | } | 2330 | } |
3162 | } | 2331 | } |
3163 | 2332 | ||
3164 | // PrefixExpr | 2333 | // PrefixExpr |
3165 | #[derive(Debug, Clone, Copy,)] | 2334 | #[derive(Debug, PartialEq, Eq, Hash)] |
3166 | pub struct PrefixExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2335 | #[repr(transparent)] |
3167 | pub(crate) syntax: SyntaxNode<R>, | 2336 | pub struct PrefixExpr { |
2337 | pub(crate) syntax: SyntaxNode, | ||
3168 | } | 2338 | } |
3169 | pub type PrefixExpr<'a> = PrefixExprNode<RefRoot<'a>>; | 2339 | unsafe impl TransparentNewType for PrefixExpr { |
3170 | 2340 | 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 | } | 2341 | } |
3178 | 2342 | ||
3179 | impl<'a> AstNode<'a> for PrefixExpr<'a> { | 2343 | impl AstNode for PrefixExpr { |
3180 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2344 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3181 | match syntax.kind() { | 2345 | match syntax.kind() { |
3182 | PREFIX_EXPR => Some(PrefixExpr { syntax }), | 2346 | PREFIX_EXPR => Some(PrefixExpr::from_repr(syntax.into_repr())), |
3183 | _ => None, | 2347 | _ => None, |
3184 | } | 2348 | } |
3185 | } | 2349 | } |
3186 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2350 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3187 | } | 2351 | 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 | } | 2352 | } |
3197 | 2353 | ||
3198 | 2354 | ||
3199 | impl<'a> PrefixExpr<'a> { | 2355 | impl PrefixExpr { |
3200 | pub fn expr(self) -> Option<Expr<'a>> { | 2356 | pub fn expr(&self) -> Option<&Expr> { |
3201 | super::child_opt(self) | 2357 | super::child_opt(self) |
3202 | } | 2358 | } |
3203 | } | 2359 | } |
3204 | 2360 | ||
3205 | // RangeExpr | 2361 | // RangeExpr |
3206 | #[derive(Debug, Clone, Copy,)] | 2362 | #[derive(Debug, PartialEq, Eq, Hash)] |
3207 | pub struct RangeExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2363 | #[repr(transparent)] |
3208 | pub(crate) syntax: SyntaxNode<R>, | 2364 | pub struct RangeExpr { |
3209 | } | 2365 | 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 | } | 2366 | } |
3215 | impl<R: TreeRoot<RaTypes>> Eq for RangeExprNode<R> {} | 2367 | unsafe impl TransparentNewType for RangeExpr { |
3216 | impl<R: TreeRoot<RaTypes>> Hash for RangeExprNode<R> { | 2368 | type Repr = rowan::SyntaxNode<RaTypes>; |
3217 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3218 | } | 2369 | } |
3219 | 2370 | ||
3220 | impl<'a> AstNode<'a> for RangeExpr<'a> { | 2371 | impl AstNode for RangeExpr { |
3221 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2372 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3222 | match syntax.kind() { | 2373 | match syntax.kind() { |
3223 | RANGE_EXPR => Some(RangeExpr { syntax }), | 2374 | RANGE_EXPR => Some(RangeExpr::from_repr(syntax.into_repr())), |
3224 | _ => None, | 2375 | _ => None, |
3225 | } | 2376 | } |
3226 | } | 2377 | } |
3227 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2378 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2379 | fn to_owned(&self) -> TreePtr<RangeExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
3228 | } | 2380 | } |
3229 | 2381 | ||
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 | 2382 | ||
3239 | 2383 | impl RangeExpr {} | |
3240 | impl<'a> RangeExpr<'a> {} | ||
3241 | 2384 | ||
3242 | // RangePat | 2385 | // RangePat |
3243 | #[derive(Debug, Clone, Copy,)] | 2386 | #[derive(Debug, PartialEq, Eq, Hash)] |
3244 | pub struct RangePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2387 | #[repr(transparent)] |
3245 | pub(crate) syntax: SyntaxNode<R>, | 2388 | pub struct RangePat { |
2389 | pub(crate) syntax: SyntaxNode, | ||
3246 | } | 2390 | } |
3247 | pub type RangePat<'a> = RangePatNode<RefRoot<'a>>; | 2391 | unsafe impl TransparentNewType for RangePat { |
3248 | 2392 | 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 | } | 2393 | } |
3256 | 2394 | ||
3257 | impl<'a> AstNode<'a> for RangePat<'a> { | 2395 | impl AstNode for RangePat { |
3258 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2396 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3259 | match syntax.kind() { | 2397 | match syntax.kind() { |
3260 | RANGE_PAT => Some(RangePat { syntax }), | 2398 | RANGE_PAT => Some(RangePat::from_repr(syntax.into_repr())), |
3261 | _ => None, | 2399 | _ => None, |
3262 | } | 2400 | } |
3263 | } | 2401 | } |
3264 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2402 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3265 | } | 2403 | 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 | } | 2404 | } |
3275 | 2405 | ||
3276 | 2406 | ||
3277 | impl<'a> RangePat<'a> {} | 2407 | impl RangePat {} |
3278 | 2408 | ||
3279 | // RefExpr | 2409 | // RefExpr |
3280 | #[derive(Debug, Clone, Copy,)] | 2410 | #[derive(Debug, PartialEq, Eq, Hash)] |
3281 | pub struct RefExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2411 | #[repr(transparent)] |
3282 | pub(crate) syntax: SyntaxNode<R>, | 2412 | pub struct RefExpr { |
2413 | pub(crate) syntax: SyntaxNode, | ||
3283 | } | 2414 | } |
3284 | pub type RefExpr<'a> = RefExprNode<RefRoot<'a>>; | 2415 | unsafe impl TransparentNewType for RefExpr { |
3285 | 2416 | 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 | } | 2417 | } |
3293 | 2418 | ||
3294 | impl<'a> AstNode<'a> for RefExpr<'a> { | 2419 | impl AstNode for RefExpr { |
3295 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2420 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3296 | match syntax.kind() { | 2421 | match syntax.kind() { |
3297 | REF_EXPR => Some(RefExpr { syntax }), | 2422 | REF_EXPR => Some(RefExpr::from_repr(syntax.into_repr())), |
3298 | _ => None, | 2423 | _ => None, |
3299 | } | 2424 | } |
3300 | } | 2425 | } |
3301 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2426 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3302 | } | 2427 | 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 | } | 2428 | } |
3312 | 2429 | ||
3313 | 2430 | ||
3314 | impl<'a> RefExpr<'a> { | 2431 | impl RefExpr { |
3315 | pub fn expr(self) -> Option<Expr<'a>> { | 2432 | pub fn expr(&self) -> Option<&Expr> { |
3316 | super::child_opt(self) | 2433 | super::child_opt(self) |
3317 | } | 2434 | } |
3318 | } | 2435 | } |
3319 | 2436 | ||
3320 | // RefPat | 2437 | // RefPat |
3321 | #[derive(Debug, Clone, Copy,)] | 2438 | #[derive(Debug, PartialEq, Eq, Hash)] |
3322 | pub struct RefPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2439 | #[repr(transparent)] |
3323 | pub(crate) syntax: SyntaxNode<R>, | 2440 | pub struct RefPat { |
2441 | pub(crate) syntax: SyntaxNode, | ||
3324 | } | 2442 | } |
3325 | pub type RefPat<'a> = RefPatNode<RefRoot<'a>>; | 2443 | unsafe impl TransparentNewType for RefPat { |
3326 | 2444 | 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 | } | 2445 | } |
3334 | 2446 | ||
3335 | impl<'a> AstNode<'a> for RefPat<'a> { | 2447 | impl AstNode for RefPat { |
3336 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2448 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3337 | match syntax.kind() { | 2449 | match syntax.kind() { |
3338 | REF_PAT => Some(RefPat { syntax }), | 2450 | REF_PAT => Some(RefPat::from_repr(syntax.into_repr())), |
3339 | _ => None, | 2451 | _ => None, |
3340 | } | 2452 | } |
3341 | } | 2453 | } |
3342 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2454 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3343 | } | 2455 | 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 | } | 2456 | } |
3353 | 2457 | ||
3354 | 2458 | ||
3355 | impl<'a> RefPat<'a> {} | 2459 | impl RefPat {} |
3356 | 2460 | ||
3357 | // ReferenceType | 2461 | // ReferenceType |
3358 | #[derive(Debug, Clone, Copy,)] | 2462 | #[derive(Debug, PartialEq, Eq, Hash)] |
3359 | pub struct ReferenceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2463 | #[repr(transparent)] |
3360 | pub(crate) syntax: SyntaxNode<R>, | 2464 | pub struct ReferenceType { |
3361 | } | 2465 | 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 | } | 2466 | } |
3367 | impl<R: TreeRoot<RaTypes>> Eq for ReferenceTypeNode<R> {} | 2467 | unsafe impl TransparentNewType for ReferenceType { |
3368 | impl<R: TreeRoot<RaTypes>> Hash for ReferenceTypeNode<R> { | 2468 | type Repr = rowan::SyntaxNode<RaTypes>; |
3369 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3370 | } | 2469 | } |
3371 | 2470 | ||
3372 | impl<'a> AstNode<'a> for ReferenceType<'a> { | 2471 | impl AstNode for ReferenceType { |
3373 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2472 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3374 | match syntax.kind() { | 2473 | match syntax.kind() { |
3375 | REFERENCE_TYPE => Some(ReferenceType { syntax }), | 2474 | REFERENCE_TYPE => Some(ReferenceType::from_repr(syntax.into_repr())), |
3376 | _ => None, | 2475 | _ => None, |
3377 | } | 2476 | } |
3378 | } | 2477 | } |
3379 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2478 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3380 | } | 2479 | 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 | } | 2480 | } |
3390 | 2481 | ||
3391 | 2482 | ||
3392 | impl<'a> ReferenceType<'a> { | 2483 | impl ReferenceType { |
3393 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2484 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3394 | super::child_opt(self) | 2485 | super::child_opt(self) |
3395 | } | 2486 | } |
3396 | } | 2487 | } |
3397 | 2488 | ||
3398 | // RetType | 2489 | // RetType |
3399 | #[derive(Debug, Clone, Copy,)] | 2490 | #[derive(Debug, PartialEq, Eq, Hash)] |
3400 | pub struct RetTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2491 | #[repr(transparent)] |
3401 | pub(crate) syntax: SyntaxNode<R>, | 2492 | pub struct RetType { |
3402 | } | 2493 | 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 | } | 2494 | } |
3408 | impl<R: TreeRoot<RaTypes>> Eq for RetTypeNode<R> {} | 2495 | unsafe impl TransparentNewType for RetType { |
3409 | impl<R: TreeRoot<RaTypes>> Hash for RetTypeNode<R> { | 2496 | type Repr = rowan::SyntaxNode<RaTypes>; |
3410 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3411 | } | 2497 | } |
3412 | 2498 | ||
3413 | impl<'a> AstNode<'a> for RetType<'a> { | 2499 | impl AstNode for RetType { |
3414 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2500 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3415 | match syntax.kind() { | 2501 | match syntax.kind() { |
3416 | RET_TYPE => Some(RetType { syntax }), | 2502 | RET_TYPE => Some(RetType::from_repr(syntax.into_repr())), |
3417 | _ => None, | 2503 | _ => None, |
3418 | } | 2504 | } |
3419 | } | 2505 | } |
3420 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2506 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3421 | } | 2507 | 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 | } | 2508 | } |
3431 | 2509 | ||
3432 | 2510 | ||
3433 | impl<'a> RetType<'a> { | 2511 | impl RetType { |
3434 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2512 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3435 | super::child_opt(self) | 2513 | super::child_opt(self) |
3436 | } | 2514 | } |
3437 | } | 2515 | } |
3438 | 2516 | ||
3439 | // ReturnExpr | 2517 | // ReturnExpr |
3440 | #[derive(Debug, Clone, Copy,)] | 2518 | #[derive(Debug, PartialEq, Eq, Hash)] |
3441 | pub struct ReturnExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2519 | #[repr(transparent)] |
3442 | pub(crate) syntax: SyntaxNode<R>, | 2520 | pub struct ReturnExpr { |
2521 | pub(crate) syntax: SyntaxNode, | ||
3443 | } | 2522 | } |
3444 | pub type ReturnExpr<'a> = ReturnExprNode<RefRoot<'a>>; | 2523 | unsafe impl TransparentNewType for ReturnExpr { |
3445 | 2524 | 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 | } | 2525 | } |
3453 | 2526 | ||
3454 | impl<'a> AstNode<'a> for ReturnExpr<'a> { | 2527 | impl AstNode for ReturnExpr { |
3455 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2528 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3456 | match syntax.kind() { | 2529 | match syntax.kind() { |
3457 | RETURN_EXPR => Some(ReturnExpr { syntax }), | 2530 | RETURN_EXPR => Some(ReturnExpr::from_repr(syntax.into_repr())), |
3458 | _ => None, | 2531 | _ => None, |
3459 | } | 2532 | } |
3460 | } | 2533 | } |
3461 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2534 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3462 | } | 2535 | 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 | } | 2536 | } |
3472 | 2537 | ||
3473 | 2538 | ||
3474 | impl<'a> ReturnExpr<'a> { | 2539 | impl ReturnExpr { |
3475 | pub fn expr(self) -> Option<Expr<'a>> { | 2540 | pub fn expr(&self) -> Option<&Expr> { |
3476 | super::child_opt(self) | 2541 | super::child_opt(self) |
3477 | } | 2542 | } |
3478 | } | 2543 | } |
3479 | 2544 | ||
3480 | // SelfKw | 2545 | // SelfKw |
3481 | #[derive(Debug, Clone, Copy,)] | 2546 | #[derive(Debug, PartialEq, Eq, Hash)] |
3482 | pub struct SelfKwNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2547 | #[repr(transparent)] |
3483 | pub(crate) syntax: SyntaxNode<R>, | 2548 | pub struct SelfKw { |
3484 | } | 2549 | 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 | } | 2550 | } |
3490 | impl<R: TreeRoot<RaTypes>> Eq for SelfKwNode<R> {} | 2551 | unsafe impl TransparentNewType for SelfKw { |
3491 | impl<R: TreeRoot<RaTypes>> Hash for SelfKwNode<R> { | 2552 | type Repr = rowan::SyntaxNode<RaTypes>; |
3492 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3493 | } | 2553 | } |
3494 | 2554 | ||
3495 | impl<'a> AstNode<'a> for SelfKw<'a> { | 2555 | impl AstNode for SelfKw { |
3496 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2556 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3497 | match syntax.kind() { | 2557 | match syntax.kind() { |
3498 | SELF_KW => Some(SelfKw { syntax }), | 2558 | SELF_KW => Some(SelfKw::from_repr(syntax.into_repr())), |
3499 | _ => None, | 2559 | _ => None, |
3500 | } | 2560 | } |
3501 | } | 2561 | } |
3502 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2562 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2563 | fn to_owned(&self) -> TreePtr<SelfKw> { TreePtr::cast(self.syntax.to_owned()) } | ||
3503 | } | 2564 | } |
3504 | 2565 | ||
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 | 2566 | ||
3514 | 2567 | impl SelfKw {} | |
3515 | impl<'a> SelfKw<'a> {} | ||
3516 | 2568 | ||
3517 | // SelfParam | 2569 | // SelfParam |
3518 | #[derive(Debug, Clone, Copy,)] | 2570 | #[derive(Debug, PartialEq, Eq, Hash)] |
3519 | pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2571 | #[repr(transparent)] |
3520 | pub(crate) syntax: SyntaxNode<R>, | 2572 | pub struct SelfParam { |
2573 | pub(crate) syntax: SyntaxNode, | ||
3521 | } | 2574 | } |
3522 | pub type SelfParam<'a> = SelfParamNode<RefRoot<'a>>; | 2575 | unsafe impl TransparentNewType for SelfParam { |
3523 | 2576 | 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 | } | 2577 | } |
3531 | 2578 | ||
3532 | impl<'a> AstNode<'a> for SelfParam<'a> { | 2579 | impl AstNode for SelfParam { |
3533 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2580 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3534 | match syntax.kind() { | 2581 | match syntax.kind() { |
3535 | SELF_PARAM => Some(SelfParam { syntax }), | 2582 | SELF_PARAM => Some(SelfParam::from_repr(syntax.into_repr())), |
3536 | _ => None, | 2583 | _ => None, |
3537 | } | 2584 | } |
3538 | } | 2585 | } |
3539 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2586 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3540 | } | 2587 | 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 | } | 2588 | } |
3550 | 2589 | ||
3551 | 2590 | ||
3552 | impl<'a> SelfParam<'a> { | 2591 | impl SelfParam { |
3553 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2592 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3554 | super::child_opt(self) | 2593 | super::child_opt(self) |
3555 | } | 2594 | } |
3556 | 2595 | ||
3557 | pub fn self_kw(self) -> Option<SelfKw<'a>> { | 2596 | pub fn self_kw(&self) -> Option<&SelfKw> { |
3558 | super::child_opt(self) | 2597 | super::child_opt(self) |
3559 | } | 2598 | } |
3560 | } | 2599 | } |
3561 | 2600 | ||
3562 | // SlicePat | 2601 | // SlicePat |
3563 | #[derive(Debug, Clone, Copy,)] | 2602 | #[derive(Debug, PartialEq, Eq, Hash)] |
3564 | pub struct SlicePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2603 | #[repr(transparent)] |
3565 | pub(crate) syntax: SyntaxNode<R>, | 2604 | pub struct SlicePat { |
2605 | pub(crate) syntax: SyntaxNode, | ||
3566 | } | 2606 | } |
3567 | pub type SlicePat<'a> = SlicePatNode<RefRoot<'a>>; | 2607 | unsafe impl TransparentNewType for SlicePat { |
3568 | 2608 | 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 | } | 2609 | } |
3576 | 2610 | ||
3577 | impl<'a> AstNode<'a> for SlicePat<'a> { | 2611 | impl AstNode for SlicePat { |
3578 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2612 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3579 | match syntax.kind() { | 2613 | match syntax.kind() { |
3580 | SLICE_PAT => Some(SlicePat { syntax }), | 2614 | SLICE_PAT => Some(SlicePat::from_repr(syntax.into_repr())), |
3581 | _ => None, | 2615 | _ => None, |
3582 | } | 2616 | } |
3583 | } | 2617 | } |
3584 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2618 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3585 | } | 2619 | 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 | } | 2620 | } |
3595 | 2621 | ||
3596 | 2622 | ||
3597 | impl<'a> SlicePat<'a> {} | 2623 | impl SlicePat {} |
3598 | 2624 | ||
3599 | // SliceType | 2625 | // SliceType |
3600 | #[derive(Debug, Clone, Copy,)] | 2626 | #[derive(Debug, PartialEq, Eq, Hash)] |
3601 | pub struct SliceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2627 | #[repr(transparent)] |
3602 | pub(crate) syntax: SyntaxNode<R>, | 2628 | pub struct SliceType { |
2629 | pub(crate) syntax: SyntaxNode, | ||
3603 | } | 2630 | } |
3604 | pub type SliceType<'a> = SliceTypeNode<RefRoot<'a>>; | 2631 | unsafe impl TransparentNewType for SliceType { |
3605 | 2632 | 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 | } | 2633 | } |
3613 | 2634 | ||
3614 | impl<'a> AstNode<'a> for SliceType<'a> { | 2635 | impl AstNode for SliceType { |
3615 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2636 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3616 | match syntax.kind() { | 2637 | match syntax.kind() { |
3617 | SLICE_TYPE => Some(SliceType { syntax }), | 2638 | SLICE_TYPE => Some(SliceType::from_repr(syntax.into_repr())), |
3618 | _ => None, | 2639 | _ => None, |
3619 | } | 2640 | } |
3620 | } | 2641 | } |
3621 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2642 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3622 | } | 2643 | 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 | } | 2644 | } |
3632 | 2645 | ||
3633 | 2646 | ||
3634 | impl<'a> SliceType<'a> { | 2647 | impl SliceType { |
3635 | pub fn type_ref(self) -> Option<TypeRef<'a>> { | 2648 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3636 | super::child_opt(self) | 2649 | super::child_opt(self) |
3637 | } | 2650 | } |
3638 | } | 2651 | } |
3639 | 2652 | ||
3640 | // SourceFile | 2653 | // SourceFile |
3641 | #[derive(Debug, Clone, Copy,)] | 2654 | #[derive(Debug, PartialEq, Eq, Hash)] |
3642 | pub struct SourceFileNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2655 | #[repr(transparent)] |
3643 | pub(crate) syntax: SyntaxNode<R>, | 2656 | pub struct SourceFile { |
2657 | pub(crate) syntax: SyntaxNode, | ||
3644 | } | 2658 | } |
3645 | pub type SourceFile<'a> = SourceFileNode<RefRoot<'a>>; | 2659 | unsafe impl TransparentNewType for SourceFile { |
3646 | 2660 | 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 | } | 2661 | } |
3654 | 2662 | ||
3655 | impl<'a> AstNode<'a> for SourceFile<'a> { | 2663 | impl AstNode for SourceFile { |
3656 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2664 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3657 | match syntax.kind() { | 2665 | match syntax.kind() { |
3658 | SOURCE_FILE => Some(SourceFile { syntax }), | 2666 | SOURCE_FILE => Some(SourceFile::from_repr(syntax.into_repr())), |
3659 | _ => None, | 2667 | _ => None, |
3660 | } | 2668 | } |
3661 | } | 2669 | } |
3662 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2670 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2671 | fn to_owned(&self) -> TreePtr<SourceFile> { TreePtr::cast(self.syntax.to_owned()) } | ||
3663 | } | 2672 | } |
3664 | 2673 | ||
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 | 2674 | ||
3674 | 2675 | impl ast::ModuleItemOwner for SourceFile {} | |
3675 | impl<'a> ast::ModuleItemOwner<'a> for SourceFile<'a> {} | 2676 | impl ast::FnDefOwner for SourceFile {} |
3676 | impl<'a> ast::FnDefOwner<'a> for SourceFile<'a> {} | 2677 | impl SourceFile { |
3677 | impl<'a> SourceFile<'a> { | 2678 | pub fn modules(&self) -> impl Iterator<Item = &Module> { |
3678 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { | ||
3679 | super::children(self) | 2679 | super::children(self) |
3680 | } | 2680 | } |
3681 | } | 2681 | } |
3682 | 2682 | ||
3683 | // StaticDef | 2683 | // StaticDef |
3684 | #[derive(Debug, Clone, Copy,)] | 2684 | #[derive(Debug, PartialEq, Eq, Hash)] |
3685 | pub struct StaticDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2685 | #[repr(transparent)] |
3686 | pub(crate) syntax: SyntaxNode<R>, | 2686 | pub struct StaticDef { |
3687 | } | 2687 | 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 | } | 2688 | } |
3693 | impl<R: TreeRoot<RaTypes>> Eq for StaticDefNode<R> {} | 2689 | unsafe impl TransparentNewType for StaticDef { |
3694 | impl<R: TreeRoot<RaTypes>> Hash for StaticDefNode<R> { | 2690 | type Repr = rowan::SyntaxNode<RaTypes>; |
3695 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3696 | } | 2691 | } |
3697 | 2692 | ||
3698 | impl<'a> AstNode<'a> for StaticDef<'a> { | 2693 | impl AstNode for StaticDef { |
3699 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2694 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3700 | match syntax.kind() { | 2695 | match syntax.kind() { |
3701 | STATIC_DEF => Some(StaticDef { syntax }), | 2696 | STATIC_DEF => Some(StaticDef::from_repr(syntax.into_repr())), |
3702 | _ => None, | 2697 | _ => None, |
3703 | } | 2698 | } |
3704 | } | 2699 | } |
3705 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2700 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2701 | fn to_owned(&self) -> TreePtr<StaticDef> { TreePtr::cast(self.syntax.to_owned()) } | ||
3706 | } | 2702 | } |
3707 | 2703 | ||
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 | 2704 | ||
3717 | 2705 | impl ast::VisibilityOwner for StaticDef {} | |
3718 | impl<'a> ast::VisibilityOwner<'a> for StaticDef<'a> {} | 2706 | impl ast::NameOwner for StaticDef {} |
3719 | impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} | 2707 | impl ast::TypeParamsOwner for StaticDef {} |
3720 | impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {} | 2708 | impl ast::AttrsOwner for StaticDef {} |
3721 | impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} | 2709 | impl ast::DocCommentsOwner for StaticDef {} |
3722 | impl<'a> ast::DocCommentsOwner<'a> for StaticDef<'a> {} | 2710 | impl StaticDef {} |
3723 | impl<'a> StaticDef<'a> {} | ||
3724 | 2711 | ||
3725 | // Stmt | 2712 | // Stmt |
2713 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
2714 | #[repr(transparent)] | ||
2715 | pub struct Stmt { | ||
2716 | pub(crate) syntax: SyntaxNode, | ||
2717 | } | ||
2718 | unsafe impl TransparentNewType for Stmt { | ||
2719 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
2720 | } | ||
2721 | |||
3726 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 2722 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
3727 | pub enum Stmt<'a> { | 2723 | pub enum StmtKind<'a> { |
3728 | ExprStmt(ExprStmt<'a>), | 2724 | ExprStmt(&'a ExprStmt), |
3729 | LetStmt(LetStmt<'a>), | 2725 | LetStmt(&'a LetStmt), |
3730 | } | 2726 | } |
3731 | 2727 | ||
3732 | impl<'a> AstNode<'a> for Stmt<'a> { | 2728 | impl AstNode for Stmt { |
3733 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2729 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3734 | match syntax.kind() { | 2730 | match syntax.kind() { |
3735 | EXPR_STMT => Some(Stmt::ExprStmt(ExprStmt { syntax })), | 2731 | | EXPR_STMT |
3736 | LET_STMT => Some(Stmt::LetStmt(LetStmt { syntax })), | 2732 | | LET_STMT => Some(Stmt::from_repr(syntax.into_repr())), |
3737 | _ => None, | 2733 | _ => None, |
3738 | } | 2734 | } |
3739 | } | 2735 | } |
3740 | fn syntax(self) -> SyntaxNodeRef<'a> { | 2736 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3741 | match self { | 2737 | fn to_owned(&self) -> TreePtr<Stmt> { TreePtr::cast(self.syntax.to_owned()) } |
3742 | Stmt::ExprStmt(inner) => inner.syntax(), | 2738 | } |
3743 | Stmt::LetStmt(inner) => inner.syntax(), | 2739 | |
2740 | impl Stmt { | ||
2741 | pub fn kind(&self) -> StmtKind { | ||
2742 | match self.syntax.kind() { | ||
2743 | EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(&self.syntax).unwrap()), | ||
2744 | LET_STMT => StmtKind::LetStmt(LetStmt::cast(&self.syntax).unwrap()), | ||
2745 | _ => unreachable!(), | ||
3744 | } | 2746 | } |
3745 | } | 2747 | } |
3746 | } | 2748 | } |
3747 | 2749 | ||
3748 | impl<'a> Stmt<'a> {} | 2750 | impl Stmt {} |
3749 | 2751 | ||
3750 | // String | 2752 | // String |
3751 | #[derive(Debug, Clone, Copy,)] | 2753 | #[derive(Debug, PartialEq, Eq, Hash)] |
3752 | pub struct StringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2754 | #[repr(transparent)] |
3753 | pub(crate) syntax: SyntaxNode<R>, | 2755 | pub struct String { |
3754 | } | 2756 | 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 | } | 2757 | } |
3760 | impl<R: TreeRoot<RaTypes>> Eq for StringNode<R> {} | 2758 | unsafe impl TransparentNewType for String { |
3761 | impl<R: TreeRoot<RaTypes>> Hash for StringNode<R> { | 2759 | type Repr = rowan::SyntaxNode<RaTypes>; |
3762 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3763 | } | 2760 | } |
3764 | 2761 | ||
3765 | impl<'a> AstNode<'a> for String<'a> { | 2762 | impl AstNode for String { |
3766 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2763 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3767 | match syntax.kind() { | 2764 | match syntax.kind() { |
3768 | STRING => Some(String { syntax }), | 2765 | STRING => Some(String::from_repr(syntax.into_repr())), |
3769 | _ => None, | 2766 | _ => None, |
3770 | } | 2767 | } |
3771 | } | 2768 | } |
3772 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2769 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3773 | } | 2770 | 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 | } | 2771 | } |
3783 | 2772 | ||
3784 | 2773 | ||
3785 | impl<'a> String<'a> {} | 2774 | impl ast::AstToken for String {} |
2775 | impl String {} | ||
3786 | 2776 | ||
3787 | // StructDef | 2777 | // StructDef |
3788 | #[derive(Debug, Clone, Copy,)] | 2778 | #[derive(Debug, PartialEq, Eq, Hash)] |
3789 | pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2779 | #[repr(transparent)] |
3790 | pub(crate) syntax: SyntaxNode<R>, | 2780 | pub struct StructDef { |
2781 | pub(crate) syntax: SyntaxNode, | ||
3791 | } | 2782 | } |
3792 | pub type StructDef<'a> = StructDefNode<RefRoot<'a>>; | 2783 | unsafe impl TransparentNewType for StructDef { |
3793 | 2784 | 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 | } | 2785 | } |
3801 | 2786 | ||
3802 | impl<'a> AstNode<'a> for StructDef<'a> { | 2787 | impl AstNode for StructDef { |
3803 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2788 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3804 | match syntax.kind() { | 2789 | match syntax.kind() { |
3805 | STRUCT_DEF => Some(StructDef { syntax }), | 2790 | STRUCT_DEF => Some(StructDef::from_repr(syntax.into_repr())), |
3806 | _ => None, | 2791 | _ => None, |
3807 | } | 2792 | } |
3808 | } | 2793 | } |
3809 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2794 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3810 | } | 2795 | 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 | } | 2796 | } |
3820 | 2797 | ||
3821 | 2798 | ||
3822 | impl<'a> ast::VisibilityOwner<'a> for StructDef<'a> {} | 2799 | impl ast::VisibilityOwner for StructDef {} |
3823 | impl<'a> ast::NameOwner<'a> for StructDef<'a> {} | 2800 | impl ast::NameOwner for StructDef {} |
3824 | impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {} | 2801 | impl ast::TypeParamsOwner for StructDef {} |
3825 | impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} | 2802 | impl ast::AttrsOwner for StructDef {} |
3826 | impl<'a> ast::DocCommentsOwner<'a> for StructDef<'a> {} | 2803 | impl ast::DocCommentsOwner for StructDef {} |
3827 | impl<'a> StructDef<'a> {} | 2804 | impl StructDef {} |
3828 | 2805 | ||
3829 | // StructLit | 2806 | // StructLit |
3830 | #[derive(Debug, Clone, Copy,)] | 2807 | #[derive(Debug, PartialEq, Eq, Hash)] |
3831 | pub struct StructLitNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2808 | #[repr(transparent)] |
3832 | pub(crate) syntax: SyntaxNode<R>, | 2809 | pub struct StructLit { |
2810 | pub(crate) syntax: SyntaxNode, | ||
3833 | } | 2811 | } |
3834 | pub type StructLit<'a> = StructLitNode<RefRoot<'a>>; | 2812 | unsafe impl TransparentNewType for StructLit { |
3835 | 2813 | 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 | } | 2814 | } |
3843 | 2815 | ||
3844 | impl<'a> AstNode<'a> for StructLit<'a> { | 2816 | impl AstNode for StructLit { |
3845 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2817 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3846 | match syntax.kind() { | 2818 | match syntax.kind() { |
3847 | STRUCT_LIT => Some(StructLit { syntax }), | 2819 | STRUCT_LIT => Some(StructLit::from_repr(syntax.into_repr())), |
3848 | _ => None, | 2820 | _ => None, |
3849 | } | 2821 | } |
3850 | } | 2822 | } |
3851 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2823 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3852 | } | 2824 | 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 | } | 2825 | } |
3862 | 2826 | ||
3863 | 2827 | ||
3864 | impl<'a> StructLit<'a> { | 2828 | impl StructLit { |
3865 | pub fn path(self) -> Option<Path<'a>> { | 2829 | pub fn path(&self) -> Option<&Path> { |
3866 | super::child_opt(self) | 2830 | super::child_opt(self) |
3867 | } | 2831 | } |
3868 | 2832 | ||
3869 | pub fn named_field_list(self) -> Option<NamedFieldList<'a>> { | 2833 | pub fn named_field_list(&self) -> Option<&NamedFieldList> { |
3870 | super::child_opt(self) | 2834 | super::child_opt(self) |
3871 | } | 2835 | } |
3872 | 2836 | ||
3873 | pub fn spread(self) -> Option<Expr<'a>> { | 2837 | pub fn spread(&self) -> Option<&Expr> { |
3874 | super::child_opt(self) | 2838 | super::child_opt(self) |
3875 | } | 2839 | } |
3876 | } | 2840 | } |
3877 | 2841 | ||
3878 | // StructPat | 2842 | // StructPat |
3879 | #[derive(Debug, Clone, Copy,)] | 2843 | #[derive(Debug, PartialEq, Eq, Hash)] |
3880 | pub struct StructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2844 | #[repr(transparent)] |
3881 | pub(crate) syntax: SyntaxNode<R>, | 2845 | pub struct StructPat { |
3882 | } | 2846 | 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 | } | 2847 | } |
3888 | impl<R: TreeRoot<RaTypes>> Eq for StructPatNode<R> {} | 2848 | unsafe impl TransparentNewType for StructPat { |
3889 | impl<R: TreeRoot<RaTypes>> Hash for StructPatNode<R> { | 2849 | type Repr = rowan::SyntaxNode<RaTypes>; |
3890 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3891 | } | 2850 | } |
3892 | 2851 | ||
3893 | impl<'a> AstNode<'a> for StructPat<'a> { | 2852 | impl AstNode for StructPat { |
3894 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2853 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3895 | match syntax.kind() { | 2854 | match syntax.kind() { |
3896 | STRUCT_PAT => Some(StructPat { syntax }), | 2855 | STRUCT_PAT => Some(StructPat::from_repr(syntax.into_repr())), |
3897 | _ => None, | 2856 | _ => None, |
3898 | } | 2857 | } |
3899 | } | 2858 | } |
3900 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2859 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2860 | fn to_owned(&self) -> TreePtr<StructPat> { TreePtr::cast(self.syntax.to_owned()) } | ||
3901 | } | 2861 | } |
3902 | 2862 | ||
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 | 2863 | ||
3912 | 2864 | impl StructPat {} | |
3913 | impl<'a> StructPat<'a> {} | ||
3914 | 2865 | ||
3915 | // TokenTree | 2866 | // TokenTree |
3916 | #[derive(Debug, Clone, Copy,)] | 2867 | #[derive(Debug, PartialEq, Eq, Hash)] |
3917 | pub struct TokenTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2868 | #[repr(transparent)] |
3918 | pub(crate) syntax: SyntaxNode<R>, | 2869 | pub struct TokenTree { |
3919 | } | 2870 | 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 | } | 2871 | } |
3925 | impl<R: TreeRoot<RaTypes>> Eq for TokenTreeNode<R> {} | 2872 | unsafe impl TransparentNewType for TokenTree { |
3926 | impl<R: TreeRoot<RaTypes>> Hash for TokenTreeNode<R> { | 2873 | type Repr = rowan::SyntaxNode<RaTypes>; |
3927 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3928 | } | 2874 | } |
3929 | 2875 | ||
3930 | impl<'a> AstNode<'a> for TokenTree<'a> { | 2876 | impl AstNode for TokenTree { |
3931 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2877 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3932 | match syntax.kind() { | 2878 | match syntax.kind() { |
3933 | TOKEN_TREE => Some(TokenTree { syntax }), | 2879 | TOKEN_TREE => Some(TokenTree::from_repr(syntax.into_repr())), |
3934 | _ => None, | 2880 | _ => None, |
3935 | } | 2881 | } |
3936 | } | 2882 | } |
3937 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2883 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3938 | } | 2884 | 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 | } | 2885 | } |
3948 | 2886 | ||
3949 | 2887 | ||
3950 | impl<'a> TokenTree<'a> {} | 2888 | impl TokenTree {} |
3951 | 2889 | ||
3952 | // TraitDef | 2890 | // TraitDef |
3953 | #[derive(Debug, Clone, Copy,)] | 2891 | #[derive(Debug, PartialEq, Eq, Hash)] |
3954 | pub struct TraitDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2892 | #[repr(transparent)] |
3955 | pub(crate) syntax: SyntaxNode<R>, | 2893 | pub struct TraitDef { |
2894 | pub(crate) syntax: SyntaxNode, | ||
3956 | } | 2895 | } |
3957 | pub type TraitDef<'a> = TraitDefNode<RefRoot<'a>>; | 2896 | unsafe impl TransparentNewType for TraitDef { |
3958 | 2897 | 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 | } | 2898 | } |
3966 | 2899 | ||
3967 | impl<'a> AstNode<'a> for TraitDef<'a> { | 2900 | impl AstNode for TraitDef { |
3968 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2901 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
3969 | match syntax.kind() { | 2902 | match syntax.kind() { |
3970 | TRAIT_DEF => Some(TraitDef { syntax }), | 2903 | TRAIT_DEF => Some(TraitDef::from_repr(syntax.into_repr())), |
3971 | _ => None, | 2904 | _ => None, |
3972 | } | 2905 | } |
3973 | } | 2906 | } |
3974 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2907 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3975 | } | 2908 | 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 | } | 2909 | } |
3985 | 2910 | ||
3986 | 2911 | ||
3987 | impl<'a> ast::VisibilityOwner<'a> for TraitDef<'a> {} | 2912 | impl ast::VisibilityOwner for TraitDef {} |
3988 | impl<'a> ast::NameOwner<'a> for TraitDef<'a> {} | 2913 | impl ast::NameOwner for TraitDef {} |
3989 | impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {} | 2914 | impl ast::AttrsOwner for TraitDef {} |
3990 | impl<'a> ast::DocCommentsOwner<'a> for TraitDef<'a> {} | 2915 | impl ast::DocCommentsOwner for TraitDef {} |
3991 | impl<'a> TraitDef<'a> {} | 2916 | impl TraitDef {} |
3992 | 2917 | ||
3993 | // TryExpr | 2918 | // TryExpr |
3994 | #[derive(Debug, Clone, Copy,)] | 2919 | #[derive(Debug, PartialEq, Eq, Hash)] |
3995 | pub struct TryExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2920 | #[repr(transparent)] |
3996 | pub(crate) syntax: SyntaxNode<R>, | 2921 | pub struct TryExpr { |
2922 | pub(crate) syntax: SyntaxNode, | ||
3997 | } | 2923 | } |
3998 | pub type TryExpr<'a> = TryExprNode<RefRoot<'a>>; | 2924 | unsafe impl TransparentNewType for TryExpr { |
3999 | 2925 | 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 | } | 2926 | } |
4007 | 2927 | ||
4008 | impl<'a> AstNode<'a> for TryExpr<'a> { | 2928 | impl AstNode for TryExpr { |
4009 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2929 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4010 | match syntax.kind() { | 2930 | match syntax.kind() { |
4011 | TRY_EXPR => Some(TryExpr { syntax }), | 2931 | TRY_EXPR => Some(TryExpr::from_repr(syntax.into_repr())), |
4012 | _ => None, | 2932 | _ => None, |
4013 | } | 2933 | } |
4014 | } | 2934 | } |
4015 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2935 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2936 | fn to_owned(&self) -> TreePtr<TryExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
4016 | } | 2937 | } |
4017 | 2938 | ||
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 | 2939 | ||
4027 | 2940 | impl TryExpr { | |
4028 | impl<'a> TryExpr<'a> { | 2941 | pub fn expr(&self) -> Option<&Expr> { |
4029 | pub fn expr(self) -> Option<Expr<'a>> { | ||
4030 | super::child_opt(self) | 2942 | super::child_opt(self) |
4031 | } | 2943 | } |
4032 | } | 2944 | } |
4033 | 2945 | ||
4034 | // TupleExpr | 2946 | // TupleExpr |
4035 | #[derive(Debug, Clone, Copy,)] | 2947 | #[derive(Debug, PartialEq, Eq, Hash)] |
4036 | pub struct TupleExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2948 | #[repr(transparent)] |
4037 | pub(crate) syntax: SyntaxNode<R>, | 2949 | pub struct TupleExpr { |
4038 | } | 2950 | 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 | } | 2951 | } |
4044 | impl<R: TreeRoot<RaTypes>> Eq for TupleExprNode<R> {} | 2952 | unsafe impl TransparentNewType for TupleExpr { |
4045 | impl<R: TreeRoot<RaTypes>> Hash for TupleExprNode<R> { | 2953 | type Repr = rowan::SyntaxNode<RaTypes>; |
4046 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4047 | } | 2954 | } |
4048 | 2955 | ||
4049 | impl<'a> AstNode<'a> for TupleExpr<'a> { | 2956 | impl AstNode for TupleExpr { |
4050 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2957 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4051 | match syntax.kind() { | 2958 | match syntax.kind() { |
4052 | TUPLE_EXPR => Some(TupleExpr { syntax }), | 2959 | TUPLE_EXPR => Some(TupleExpr::from_repr(syntax.into_repr())), |
4053 | _ => None, | 2960 | _ => None, |
4054 | } | 2961 | } |
4055 | } | 2962 | } |
4056 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2963 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4057 | } | 2964 | 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 | } | 2965 | } |
4067 | 2966 | ||
4068 | 2967 | ||
4069 | impl<'a> TupleExpr<'a> {} | 2968 | impl TupleExpr {} |
4070 | 2969 | ||
4071 | // TuplePat | 2970 | // TuplePat |
4072 | #[derive(Debug, Clone, Copy,)] | 2971 | #[derive(Debug, PartialEq, Eq, Hash)] |
4073 | pub struct TuplePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2972 | #[repr(transparent)] |
4074 | pub(crate) syntax: SyntaxNode<R>, | 2973 | pub struct TuplePat { |
2974 | pub(crate) syntax: SyntaxNode, | ||
4075 | } | 2975 | } |
4076 | pub type TuplePat<'a> = TuplePatNode<RefRoot<'a>>; | 2976 | unsafe impl TransparentNewType for TuplePat { |
4077 | 2977 | 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 | } | 2978 | } |
4085 | 2979 | ||
4086 | impl<'a> AstNode<'a> for TuplePat<'a> { | 2980 | impl AstNode for TuplePat { |
4087 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2981 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4088 | match syntax.kind() { | 2982 | match syntax.kind() { |
4089 | TUPLE_PAT => Some(TuplePat { syntax }), | 2983 | TUPLE_PAT => Some(TuplePat::from_repr(syntax.into_repr())), |
4090 | _ => None, | 2984 | _ => None, |
4091 | } | 2985 | } |
4092 | } | 2986 | } |
4093 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2987 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4094 | } | 2988 | 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 | } | 2989 | } |
4104 | 2990 | ||
4105 | 2991 | ||
4106 | impl<'a> TuplePat<'a> {} | 2992 | impl TuplePat {} |
4107 | 2993 | ||
4108 | // TupleStructPat | 2994 | // TupleStructPat |
4109 | #[derive(Debug, Clone, Copy,)] | 2995 | #[derive(Debug, PartialEq, Eq, Hash)] |
4110 | pub struct TupleStructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2996 | #[repr(transparent)] |
4111 | pub(crate) syntax: SyntaxNode<R>, | 2997 | pub struct TupleStructPat { |
2998 | pub(crate) syntax: SyntaxNode, | ||
4112 | } | 2999 | } |
4113 | pub type TupleStructPat<'a> = TupleStructPatNode<RefRoot<'a>>; | 3000 | unsafe impl TransparentNewType for TupleStructPat { |
4114 | 3001 | 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 | } | 3002 | } |
4122 | 3003 | ||
4123 | impl<'a> AstNode<'a> for TupleStructPat<'a> { | 3004 | impl AstNode for TupleStructPat { |
4124 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3005 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4125 | match syntax.kind() { | 3006 | match syntax.kind() { |
4126 | TUPLE_STRUCT_PAT => Some(TupleStructPat { syntax }), | 3007 | TUPLE_STRUCT_PAT => Some(TupleStructPat::from_repr(syntax.into_repr())), |
4127 | _ => None, | 3008 | _ => None, |
4128 | } | 3009 | } |
4129 | } | 3010 | } |
4130 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3011 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4131 | } | 3012 | 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 | } | 3013 | } |
4141 | 3014 | ||
4142 | 3015 | ||
4143 | impl<'a> TupleStructPat<'a> { | 3016 | impl TupleStructPat { |
4144 | pub fn args(self) -> impl Iterator<Item = Pat<'a>> + 'a { | 3017 | pub fn args(&self) -> impl Iterator<Item = &Pat> { |
4145 | super::children(self) | 3018 | super::children(self) |
4146 | } | 3019 | } |
4147 | 3020 | ||
4148 | pub fn path(self) -> Option<Path<'a>> { | 3021 | pub fn path(&self) -> Option<&Path> { |
4149 | super::child_opt(self) | 3022 | super::child_opt(self) |
4150 | } | 3023 | } |
4151 | } | 3024 | } |
4152 | 3025 | ||
4153 | // TupleType | 3026 | // TupleType |
4154 | #[derive(Debug, Clone, Copy,)] | 3027 | #[derive(Debug, PartialEq, Eq, Hash)] |
4155 | pub struct TupleTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3028 | #[repr(transparent)] |
4156 | pub(crate) syntax: SyntaxNode<R>, | 3029 | pub struct TupleType { |
4157 | } | 3030 | 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 | } | 3031 | } |
4163 | impl<R: TreeRoot<RaTypes>> Eq for TupleTypeNode<R> {} | 3032 | unsafe impl TransparentNewType for TupleType { |
4164 | impl<R: TreeRoot<RaTypes>> Hash for TupleTypeNode<R> { | 3033 | type Repr = rowan::SyntaxNode<RaTypes>; |
4165 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4166 | } | 3034 | } |
4167 | 3035 | ||
4168 | impl<'a> AstNode<'a> for TupleType<'a> { | 3036 | impl AstNode for TupleType { |
4169 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3037 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4170 | match syntax.kind() { | 3038 | match syntax.kind() { |
4171 | TUPLE_TYPE => Some(TupleType { syntax }), | 3039 | TUPLE_TYPE => Some(TupleType::from_repr(syntax.into_repr())), |
4172 | _ => None, | 3040 | _ => None, |
4173 | } | 3041 | } |
4174 | } | 3042 | } |
4175 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3043 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3044 | fn to_owned(&self) -> TreePtr<TupleType> { TreePtr::cast(self.syntax.to_owned()) } | ||
4176 | } | 3045 | } |
4177 | 3046 | ||
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 | 3047 | ||
4187 | 3048 | impl TupleType { | |
4188 | impl<'a> TupleType<'a> { | 3049 | pub fn fields(&self) -> impl Iterator<Item = &TypeRef> { |
4189 | pub fn fields(self) -> impl Iterator<Item = TypeRef<'a>> + 'a { | ||
4190 | super::children(self) | 3050 | super::children(self) |
4191 | } | 3051 | } |
4192 | } | 3052 | } |
4193 | 3053 | ||
4194 | // TypeDef | 3054 | // TypeDef |
4195 | #[derive(Debug, Clone, Copy,)] | 3055 | #[derive(Debug, PartialEq, Eq, Hash)] |
4196 | pub struct TypeDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3056 | #[repr(transparent)] |
4197 | pub(crate) syntax: SyntaxNode<R>, | 3057 | pub struct TypeDef { |
4198 | } | 3058 | 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 | } | 3059 | } |
4204 | impl<R: TreeRoot<RaTypes>> Eq for TypeDefNode<R> {} | 3060 | unsafe impl TransparentNewType for TypeDef { |
4205 | impl<R: TreeRoot<RaTypes>> Hash for TypeDefNode<R> { | 3061 | type Repr = rowan::SyntaxNode<RaTypes>; |
4206 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4207 | } | 3062 | } |
4208 | 3063 | ||
4209 | impl<'a> AstNode<'a> for TypeDef<'a> { | 3064 | impl AstNode for TypeDef { |
4210 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3065 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4211 | match syntax.kind() { | 3066 | match syntax.kind() { |
4212 | TYPE_DEF => Some(TypeDef { syntax }), | 3067 | TYPE_DEF => Some(TypeDef::from_repr(syntax.into_repr())), |
4213 | _ => None, | 3068 | _ => None, |
4214 | } | 3069 | } |
4215 | } | 3070 | } |
4216 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3071 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4217 | } | 3072 | 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 | } | 3073 | } |
4227 | 3074 | ||
4228 | 3075 | ||
4229 | impl<'a> ast::VisibilityOwner<'a> for TypeDef<'a> {} | 3076 | impl ast::VisibilityOwner for TypeDef {} |
4230 | impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} | 3077 | impl ast::NameOwner for TypeDef {} |
4231 | impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {} | 3078 | impl ast::TypeParamsOwner for TypeDef {} |
4232 | impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} | 3079 | impl ast::AttrsOwner for TypeDef {} |
4233 | impl<'a> ast::DocCommentsOwner<'a> for TypeDef<'a> {} | 3080 | impl ast::DocCommentsOwner for TypeDef {} |
4234 | impl<'a> TypeDef<'a> {} | 3081 | impl TypeDef {} |
4235 | 3082 | ||
4236 | // TypeParam | 3083 | // TypeParam |
4237 | #[derive(Debug, Clone, Copy,)] | 3084 | #[derive(Debug, PartialEq, Eq, Hash)] |
4238 | pub struct TypeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3085 | #[repr(transparent)] |
4239 | pub(crate) syntax: SyntaxNode<R>, | 3086 | pub struct TypeParam { |
3087 | pub(crate) syntax: SyntaxNode, | ||
4240 | } | 3088 | } |
4241 | pub type TypeParam<'a> = TypeParamNode<RefRoot<'a>>; | 3089 | unsafe impl TransparentNewType for TypeParam { |
4242 | 3090 | 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 | } | 3091 | } |
4250 | 3092 | ||
4251 | impl<'a> AstNode<'a> for TypeParam<'a> { | 3093 | impl AstNode for TypeParam { |
4252 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3094 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4253 | match syntax.kind() { | 3095 | match syntax.kind() { |
4254 | TYPE_PARAM => Some(TypeParam { syntax }), | 3096 | TYPE_PARAM => Some(TypeParam::from_repr(syntax.into_repr())), |
4255 | _ => None, | 3097 | _ => None, |
4256 | } | 3098 | } |
4257 | } | 3099 | } |
4258 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3100 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4259 | } | 3101 | 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 | } | 3102 | } |
4269 | 3103 | ||
4270 | 3104 | ||
4271 | impl<'a> ast::NameOwner<'a> for TypeParam<'a> {} | 3105 | impl ast::NameOwner for TypeParam {} |
4272 | impl<'a> TypeParam<'a> {} | 3106 | impl TypeParam {} |
4273 | 3107 | ||
4274 | // TypeParamList | 3108 | // TypeParamList |
4275 | #[derive(Debug, Clone, Copy,)] | 3109 | #[derive(Debug, PartialEq, Eq, Hash)] |
4276 | pub struct TypeParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3110 | #[repr(transparent)] |
4277 | pub(crate) syntax: SyntaxNode<R>, | 3111 | pub struct TypeParamList { |
3112 | pub(crate) syntax: SyntaxNode, | ||
4278 | } | 3113 | } |
4279 | pub type TypeParamList<'a> = TypeParamListNode<RefRoot<'a>>; | 3114 | unsafe impl TransparentNewType for TypeParamList { |
4280 | 3115 | 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 | } | 3116 | } |
4288 | 3117 | ||
4289 | impl<'a> AstNode<'a> for TypeParamList<'a> { | 3118 | impl AstNode for TypeParamList { |
4290 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3119 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4291 | match syntax.kind() { | 3120 | match syntax.kind() { |
4292 | TYPE_PARAM_LIST => Some(TypeParamList { syntax }), | 3121 | TYPE_PARAM_LIST => Some(TypeParamList::from_repr(syntax.into_repr())), |
4293 | _ => None, | 3122 | _ => None, |
4294 | } | 3123 | } |
4295 | } | 3124 | } |
4296 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3125 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3126 | fn to_owned(&self) -> TreePtr<TypeParamList> { TreePtr::cast(self.syntax.to_owned()) } | ||
4297 | } | 3127 | } |
4298 | 3128 | ||
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 | 3129 | ||
4308 | 3130 | impl TypeParamList { | |
4309 | impl<'a> TypeParamList<'a> { | 3131 | 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) | 3132 | super::children(self) |
4312 | } | 3133 | } |
4313 | 3134 | ||
4314 | pub fn lifetime_params(self) -> impl Iterator<Item = LifetimeParam<'a>> + 'a { | 3135 | pub fn lifetime_params(&self) -> impl Iterator<Item = &LifetimeParam> { |
4315 | super::children(self) | 3136 | super::children(self) |
4316 | } | 3137 | } |
4317 | } | 3138 | } |
4318 | 3139 | ||
4319 | // TypeRef | 3140 | // TypeRef |
4320 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 3141 | #[derive(Debug, PartialEq, Eq, Hash)] |
4321 | pub enum TypeRef<'a> { | 3142 | #[repr(transparent)] |
4322 | ParenType(ParenType<'a>), | 3143 | pub struct TypeRef { |
4323 | TupleType(TupleType<'a>), | 3144 | pub(crate) syntax: SyntaxNode, |
4324 | NeverType(NeverType<'a>), | 3145 | } |
4325 | PathType(PathType<'a>), | 3146 | unsafe impl TransparentNewType for TypeRef { |
4326 | PointerType(PointerType<'a>), | 3147 | 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 | } | 3148 | } |
4374 | 3149 | ||
4375 | impl<'a> TypeRef<'a> {} | 3150 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
3151 | pub enum TypeRefKind<'a> { | ||
3152 | ParenType(&'a ParenType), | ||
3153 | TupleType(&'a TupleType), | ||
3154 | NeverType(&'a NeverType), | ||
3155 | PathType(&'a PathType), | ||
3156 | PointerType(&'a PointerType), | ||
3157 | ArrayType(&'a ArrayType), | ||
3158 | SliceType(&'a SliceType), | ||
3159 | ReferenceType(&'a ReferenceType), | ||
3160 | PlaceholderType(&'a PlaceholderType), | ||
3161 | FnPointerType(&'a FnPointerType), | ||
3162 | ForType(&'a ForType), | ||
3163 | ImplTraitType(&'a ImplTraitType), | ||
3164 | DynTraitType(&'a DynTraitType), | ||
3165 | } | ||
3166 | |||
3167 | impl AstNode for TypeRef { | ||
3168 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
3169 | match syntax.kind() { | ||
3170 | | PAREN_TYPE | ||
3171 | | TUPLE_TYPE | ||
3172 | | NEVER_TYPE | ||
3173 | | PATH_TYPE | ||
3174 | | POINTER_TYPE | ||
3175 | | ARRAY_TYPE | ||
3176 | | SLICE_TYPE | ||
3177 | | REFERENCE_TYPE | ||
3178 | | PLACEHOLDER_TYPE | ||
3179 | | FN_POINTER_TYPE | ||
3180 | | FOR_TYPE | ||
3181 | | IMPL_TRAIT_TYPE | ||
3182 | | DYN_TRAIT_TYPE => Some(TypeRef::from_repr(syntax.into_repr())), | ||
3183 | _ => None, | ||
3184 | } | ||
3185 | } | ||
3186 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3187 | fn to_owned(&self) -> TreePtr<TypeRef> { TreePtr::cast(self.syntax.to_owned()) } | ||
3188 | } | ||
3189 | |||
3190 | impl TypeRef { | ||
3191 | pub fn kind(&self) -> TypeRefKind { | ||
3192 | match self.syntax.kind() { | ||
3193 | PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(&self.syntax).unwrap()), | ||
3194 | TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(&self.syntax).unwrap()), | ||
3195 | NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(&self.syntax).unwrap()), | ||
3196 | PATH_TYPE => TypeRefKind::PathType(PathType::cast(&self.syntax).unwrap()), | ||
3197 | POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(&self.syntax).unwrap()), | ||
3198 | ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(&self.syntax).unwrap()), | ||
3199 | SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(&self.syntax).unwrap()), | ||
3200 | REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(&self.syntax).unwrap()), | ||
3201 | PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(&self.syntax).unwrap()), | ||
3202 | FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(&self.syntax).unwrap()), | ||
3203 | FOR_TYPE => TypeRefKind::ForType(ForType::cast(&self.syntax).unwrap()), | ||
3204 | IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(&self.syntax).unwrap()), | ||
3205 | DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(&self.syntax).unwrap()), | ||
3206 | _ => unreachable!(), | ||
3207 | } | ||
3208 | } | ||
3209 | } | ||
3210 | |||
3211 | impl TypeRef {} | ||
4376 | 3212 | ||
4377 | // UseItem | 3213 | // UseItem |
4378 | #[derive(Debug, Clone, Copy,)] | 3214 | #[derive(Debug, PartialEq, Eq, Hash)] |
4379 | pub struct UseItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3215 | #[repr(transparent)] |
4380 | pub(crate) syntax: SyntaxNode<R>, | 3216 | pub struct UseItem { |
3217 | pub(crate) syntax: SyntaxNode, | ||
4381 | } | 3218 | } |
4382 | pub type UseItem<'a> = UseItemNode<RefRoot<'a>>; | 3219 | unsafe impl TransparentNewType for UseItem { |
4383 | 3220 | 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 | } | 3221 | } |
4391 | 3222 | ||
4392 | impl<'a> AstNode<'a> for UseItem<'a> { | 3223 | impl AstNode for UseItem { |
4393 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3224 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4394 | match syntax.kind() { | 3225 | match syntax.kind() { |
4395 | USE_ITEM => Some(UseItem { syntax }), | 3226 | USE_ITEM => Some(UseItem::from_repr(syntax.into_repr())), |
4396 | _ => None, | 3227 | _ => None, |
4397 | } | 3228 | } |
4398 | } | 3229 | } |
4399 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3230 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4400 | } | 3231 | 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 | } | 3232 | } |
4410 | 3233 | ||
4411 | 3234 | ||
4412 | impl<'a> UseItem<'a> { | 3235 | impl UseItem { |
4413 | pub fn use_tree(self) -> Option<UseTree<'a>> { | 3236 | pub fn use_tree(&self) -> Option<&UseTree> { |
4414 | super::child_opt(self) | 3237 | super::child_opt(self) |
4415 | } | 3238 | } |
4416 | } | 3239 | } |
4417 | 3240 | ||
4418 | // UseTree | 3241 | // UseTree |
4419 | #[derive(Debug, Clone, Copy,)] | 3242 | #[derive(Debug, PartialEq, Eq, Hash)] |
4420 | pub struct UseTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3243 | #[repr(transparent)] |
4421 | pub(crate) syntax: SyntaxNode<R>, | 3244 | pub struct UseTree { |
3245 | pub(crate) syntax: SyntaxNode, | ||
4422 | } | 3246 | } |
4423 | pub type UseTree<'a> = UseTreeNode<RefRoot<'a>>; | 3247 | unsafe impl TransparentNewType for UseTree { |
4424 | 3248 | 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 | } | 3249 | } |
4432 | 3250 | ||
4433 | impl<'a> AstNode<'a> for UseTree<'a> { | 3251 | impl AstNode for UseTree { |
4434 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3252 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4435 | match syntax.kind() { | 3253 | match syntax.kind() { |
4436 | USE_TREE => Some(UseTree { syntax }), | 3254 | USE_TREE => Some(UseTree::from_repr(syntax.into_repr())), |
4437 | _ => None, | 3255 | _ => None, |
4438 | } | 3256 | } |
4439 | } | 3257 | } |
4440 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3258 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3259 | fn to_owned(&self) -> TreePtr<UseTree> { TreePtr::cast(self.syntax.to_owned()) } | ||
4441 | } | 3260 | } |
4442 | 3261 | ||
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 | 3262 | ||
4452 | 3263 | impl UseTree { | |
4453 | impl<'a> UseTree<'a> { | 3264 | pub fn path(&self) -> Option<&Path> { |
4454 | pub fn path(self) -> Option<Path<'a>> { | ||
4455 | super::child_opt(self) | 3265 | super::child_opt(self) |
4456 | } | 3266 | } |
4457 | 3267 | ||
4458 | pub fn use_tree_list(self) -> Option<UseTreeList<'a>> { | 3268 | pub fn use_tree_list(&self) -> Option<&UseTreeList> { |
4459 | super::child_opt(self) | 3269 | super::child_opt(self) |
4460 | } | 3270 | } |
4461 | } | 3271 | } |
4462 | 3272 | ||
4463 | // UseTreeList | 3273 | // UseTreeList |
4464 | #[derive(Debug, Clone, Copy,)] | 3274 | #[derive(Debug, PartialEq, Eq, Hash)] |
4465 | pub struct UseTreeListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3275 | #[repr(transparent)] |
4466 | pub(crate) syntax: SyntaxNode<R>, | 3276 | pub struct UseTreeList { |
4467 | } | 3277 | 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 | } | 3278 | } |
4473 | impl<R: TreeRoot<RaTypes>> Eq for UseTreeListNode<R> {} | 3279 | unsafe impl TransparentNewType for UseTreeList { |
4474 | impl<R: TreeRoot<RaTypes>> Hash for UseTreeListNode<R> { | 3280 | type Repr = rowan::SyntaxNode<RaTypes>; |
4475 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4476 | } | 3281 | } |
4477 | 3282 | ||
4478 | impl<'a> AstNode<'a> for UseTreeList<'a> { | 3283 | impl AstNode for UseTreeList { |
4479 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3284 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4480 | match syntax.kind() { | 3285 | match syntax.kind() { |
4481 | USE_TREE_LIST => Some(UseTreeList { syntax }), | 3286 | USE_TREE_LIST => Some(UseTreeList::from_repr(syntax.into_repr())), |
4482 | _ => None, | 3287 | _ => None, |
4483 | } | 3288 | } |
4484 | } | 3289 | } |
4485 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3290 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4486 | } | 3291 | 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 | } | 3292 | } |
4496 | 3293 | ||
4497 | 3294 | ||
4498 | impl<'a> UseTreeList<'a> { | 3295 | impl UseTreeList { |
4499 | pub fn use_trees(self) -> impl Iterator<Item = UseTree<'a>> + 'a { | 3296 | pub fn use_trees(&self) -> impl Iterator<Item = &UseTree> { |
4500 | super::children(self) | 3297 | super::children(self) |
4501 | } | 3298 | } |
4502 | } | 3299 | } |
4503 | 3300 | ||
4504 | // Visibility | 3301 | // Visibility |
4505 | #[derive(Debug, Clone, Copy,)] | 3302 | #[derive(Debug, PartialEq, Eq, Hash)] |
4506 | pub struct VisibilityNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3303 | #[repr(transparent)] |
4507 | pub(crate) syntax: SyntaxNode<R>, | 3304 | pub struct Visibility { |
3305 | pub(crate) syntax: SyntaxNode, | ||
4508 | } | 3306 | } |
4509 | pub type Visibility<'a> = VisibilityNode<RefRoot<'a>>; | 3307 | unsafe impl TransparentNewType for Visibility { |
4510 | 3308 | 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 | } | 3309 | } |
4518 | 3310 | ||
4519 | impl<'a> AstNode<'a> for Visibility<'a> { | 3311 | impl AstNode for Visibility { |
4520 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3312 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4521 | match syntax.kind() { | 3313 | match syntax.kind() { |
4522 | VISIBILITY => Some(Visibility { syntax }), | 3314 | VISIBILITY => Some(Visibility::from_repr(syntax.into_repr())), |
4523 | _ => None, | 3315 | _ => None, |
4524 | } | 3316 | } |
4525 | } | 3317 | } |
4526 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3318 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4527 | } | 3319 | 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 | } | 3320 | } |
4537 | 3321 | ||
4538 | 3322 | ||
4539 | impl<'a> Visibility<'a> {} | 3323 | impl Visibility {} |
4540 | 3324 | ||
4541 | // WhereClause | 3325 | // WhereClause |
4542 | #[derive(Debug, Clone, Copy,)] | 3326 | #[derive(Debug, PartialEq, Eq, Hash)] |
4543 | pub struct WhereClauseNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3327 | #[repr(transparent)] |
4544 | pub(crate) syntax: SyntaxNode<R>, | 3328 | pub struct WhereClause { |
3329 | pub(crate) syntax: SyntaxNode, | ||
4545 | } | 3330 | } |
4546 | pub type WhereClause<'a> = WhereClauseNode<RefRoot<'a>>; | 3331 | unsafe impl TransparentNewType for WhereClause { |
4547 | 3332 | 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 | } | 3333 | } |
4555 | 3334 | ||
4556 | impl<'a> AstNode<'a> for WhereClause<'a> { | 3335 | impl AstNode for WhereClause { |
4557 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3336 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4558 | match syntax.kind() { | 3337 | match syntax.kind() { |
4559 | WHERE_CLAUSE => Some(WhereClause { syntax }), | 3338 | WHERE_CLAUSE => Some(WhereClause::from_repr(syntax.into_repr())), |
4560 | _ => None, | 3339 | _ => None, |
4561 | } | 3340 | } |
4562 | } | 3341 | } |
4563 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3342 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4564 | } | 3343 | 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 | } | 3344 | } |
4574 | 3345 | ||
4575 | 3346 | ||
4576 | impl<'a> WhereClause<'a> {} | 3347 | impl WhereClause {} |
4577 | 3348 | ||
4578 | // WhileExpr | 3349 | // WhileExpr |
4579 | #[derive(Debug, Clone, Copy,)] | 3350 | #[derive(Debug, PartialEq, Eq, Hash)] |
4580 | pub struct WhileExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3351 | #[repr(transparent)] |
4581 | pub(crate) syntax: SyntaxNode<R>, | 3352 | pub struct WhileExpr { |
4582 | } | 3353 | 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 | } | 3354 | } |
4588 | impl<R: TreeRoot<RaTypes>> Eq for WhileExprNode<R> {} | 3355 | unsafe impl TransparentNewType for WhileExpr { |
4589 | impl<R: TreeRoot<RaTypes>> Hash for WhileExprNode<R> { | 3356 | type Repr = rowan::SyntaxNode<RaTypes>; |
4590 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4591 | } | 3357 | } |
4592 | 3358 | ||
4593 | impl<'a> AstNode<'a> for WhileExpr<'a> { | 3359 | impl AstNode for WhileExpr { |
4594 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3360 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4595 | match syntax.kind() { | 3361 | match syntax.kind() { |
4596 | WHILE_EXPR => Some(WhileExpr { syntax }), | 3362 | WHILE_EXPR => Some(WhileExpr::from_repr(syntax.into_repr())), |
4597 | _ => None, | 3363 | _ => None, |
4598 | } | 3364 | } |
4599 | } | 3365 | } |
4600 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3366 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
3367 | fn to_owned(&self) -> TreePtr<WhileExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
4601 | } | 3368 | } |
4602 | 3369 | ||
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 | 3370 | ||
4612 | 3371 | impl ast::LoopBodyOwner for WhileExpr {} | |
4613 | impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} | 3372 | impl WhileExpr { |
4614 | impl<'a> WhileExpr<'a> { | 3373 | pub fn condition(&self) -> Option<&Condition> { |
4615 | pub fn condition(self) -> Option<Condition<'a>> { | ||
4616 | super::child_opt(self) | 3374 | super::child_opt(self) |
4617 | } | 3375 | } |
4618 | } | 3376 | } |
4619 | 3377 | ||
4620 | // Whitespace | 3378 | // Whitespace |
4621 | #[derive(Debug, Clone, Copy,)] | 3379 | #[derive(Debug, PartialEq, Eq, Hash)] |
4622 | pub struct WhitespaceNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3380 | #[repr(transparent)] |
4623 | pub(crate) syntax: SyntaxNode<R>, | 3381 | pub struct Whitespace { |
4624 | } | 3382 | 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 | } | 3383 | } |
4630 | impl<R: TreeRoot<RaTypes>> Eq for WhitespaceNode<R> {} | 3384 | unsafe impl TransparentNewType for Whitespace { |
4631 | impl<R: TreeRoot<RaTypes>> Hash for WhitespaceNode<R> { | 3385 | type Repr = rowan::SyntaxNode<RaTypes>; |
4632 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4633 | } | 3386 | } |
4634 | 3387 | ||
4635 | impl<'a> AstNode<'a> for Whitespace<'a> { | 3388 | impl AstNode for Whitespace { |
4636 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3389 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
4637 | match syntax.kind() { | 3390 | match syntax.kind() { |
4638 | WHITESPACE => Some(Whitespace { syntax }), | 3391 | WHITESPACE => Some(Whitespace::from_repr(syntax.into_repr())), |
4639 | _ => None, | 3392 | _ => None, |
4640 | } | 3393 | } |
4641 | } | 3394 | } |
4642 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 3395 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
4643 | } | 3396 | 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 | } | 3397 | } |
4653 | 3398 | ||
4654 | 3399 | ||
4655 | impl<'a> Whitespace<'a> {} | 3400 | impl ast::AstToken for Whitespace {} |
3401 | impl Whitespace {} | ||
4656 | 3402 | ||
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/grammar.ron b/crates/ra_syntax/src/grammar.ron index 3c640ed47..bddd96a5c 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -49,6 +49,7 @@ Grammar( | |||
49 | ["^=", "CARETEQ"], | 49 | ["^=", "CARETEQ"], |
50 | ["/=", "SLASHEQ"], | 50 | ["/=", "SLASHEQ"], |
51 | ["*=", "STAREQ"], | 51 | ["*=", "STAREQ"], |
52 | ["%=", "PERCENTEQ"], | ||
52 | ["&&", "AMPAMP"], | 53 | ["&&", "AMPAMP"], |
53 | ["||", "PIPEPIPE"], | 54 | ["||", "PIPEPIPE"], |
54 | ["<<", "SHL"], | 55 | ["<<", "SHL"], |
@@ -423,10 +424,10 @@ Grammar( | |||
423 | "PrefixExpr": (options: ["Expr"]), | 424 | "PrefixExpr": (options: ["Expr"]), |
424 | "RangeExpr": (), | 425 | "RangeExpr": (), |
425 | "BinExpr": (), | 426 | "BinExpr": (), |
426 | "String": (), | 427 | "String": ( traits: ["AstToken"] ), |
427 | "Byte": (), | 428 | "Byte": ( traits: ["AstToken"] ), |
428 | "ByteString": (), | 429 | "ByteString": ( traits: ["AstToken"] ), |
429 | "Char": (), | 430 | "Char": ( traits: ["AstToken"] ), |
430 | "Literal": (), | 431 | "Literal": (), |
431 | 432 | ||
432 | "Expr": ( | 433 | "Expr": ( |
@@ -504,7 +505,7 @@ Grammar( | |||
504 | ), | 505 | ), |
505 | "TypeParam": ( traits: ["NameOwner"] ), | 506 | "TypeParam": ( traits: ["NameOwner"] ), |
506 | "LifetimeParam": ( options: [ "Lifetime" ] ), | 507 | "LifetimeParam": ( options: [ "Lifetime" ] ), |
507 | "Lifetime": (), | 508 | "Lifetime": ( traits: ["AstToken"] ), |
508 | "WhereClause": (), | 509 | "WhereClause": (), |
509 | "ExprStmt": ( | 510 | "ExprStmt": ( |
510 | options: [ ["expr", "Expr"] ] | 511 | options: [ ["expr", "Expr"] ] |
@@ -561,7 +562,7 @@ Grammar( | |||
561 | "PathSegment": ( | 562 | "PathSegment": ( |
562 | options: [ "NameRef" ] | 563 | options: [ "NameRef" ] |
563 | ), | 564 | ), |
564 | "Comment": (), | 565 | "Comment": ( traits: ["AstToken"] ), |
565 | "Whitespace": (), | 566 | "Whitespace": ( traits: ["AstToken"] ), |
566 | }, | 567 | }, |
567 | ) | 568 | ) |
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/syntax_kinds/generated.rs b/crates/ra_syntax/src/syntax_kinds/generated.rs index ef4588d93..830fac9f4 100644 --- a/crates/ra_syntax/src/syntax_kinds/generated.rs +++ b/crates/ra_syntax/src/syntax_kinds/generated.rs | |||
@@ -58,6 +58,7 @@ pub enum SyntaxKind { | |||
58 | CARETEQ, | 58 | CARETEQ, |
59 | SLASHEQ, | 59 | SLASHEQ, |
60 | STAREQ, | 60 | STAREQ, |
61 | PERCENTEQ, | ||
61 | AMPAMP, | 62 | AMPAMP, |
62 | PIPEPIPE, | 63 | PIPEPIPE, |
63 | SHL, | 64 | SHL, |
@@ -319,6 +320,7 @@ impl SyntaxKind { | |||
319 | CARETEQ => &SyntaxInfo { name: "CARETEQ" }, | 320 | CARETEQ => &SyntaxInfo { name: "CARETEQ" }, |
320 | SLASHEQ => &SyntaxInfo { name: "SLASHEQ" }, | 321 | SLASHEQ => &SyntaxInfo { name: "SLASHEQ" }, |
321 | STAREQ => &SyntaxInfo { name: "STAREQ" }, | 322 | STAREQ => &SyntaxInfo { name: "STAREQ" }, |
323 | PERCENTEQ => &SyntaxInfo { name: "PERCENTEQ" }, | ||
322 | AMPAMP => &SyntaxInfo { name: "AMPAMP" }, | 324 | AMPAMP => &SyntaxInfo { name: "AMPAMP" }, |
323 | PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" }, | 325 | PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" }, |
324 | SHL => &SyntaxInfo { name: "SHL" }, | 326 | SHL => &SyntaxInfo { name: "SHL" }, |
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..9ab4b18a3 100644 --- a/crates/ra_syntax/src/validation/byte.rs +++ b/crates/ra_syntax/src/validation/byte.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Validation of byte literals | 1 | //! Validation of byte literals |
2 | 2 | ||
3 | use crate::{ | 3 | use crate::{ |
4 | ast::{self, AstNode}, | 4 | ast::{self, AstNode, AstToken}, |
5 | string_lexing::{self, StringComponentKind}, | 5 | string_lexing::{self, StringComponentKind}, |
6 | TextRange, | 6 | TextRange, |
7 | validation::char, | 7 | validation::char, |
@@ -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..cd41a0a68 100644 --- a/crates/ra_syntax/src/validation/byte_string.rs +++ b/crates/ra_syntax/src/validation/byte_string.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | ast::{self, AstNode}, | 2 | ast::{self, AstNode, AstToken}, |
3 | string_lexing::{self, StringComponentKind}, | 3 | string_lexing::{self, StringComponentKind}, |
4 | yellow::{ | 4 | yellow::{ |
5 | SyntaxError, | 5 | SyntaxError, |
@@ -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..169c88f56 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs | |||
@@ -5,7 +5,7 @@ use std::u32; | |||
5 | use arrayvec::ArrayString; | 5 | use arrayvec::ArrayString; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | ast::{self, AstNode}, | 8 | ast::{self, AstNode, AstToken}, |
9 | string_lexing::{self, StringComponentKind}, | 9 | string_lexing::{self, StringComponentKind}, |
10 | TextRange, | 10 | TextRange, |
11 | yellow::{ | 11 | yellow::{ |
@@ -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..cb86b765f 100644 --- a/crates/ra_syntax/src/validation/string.rs +++ b/crates/ra_syntax/src/validation/string.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | ast::{self, AstNode}, | 2 | ast::{self, AstNode, AstToken}, |
3 | string_lexing, | 3 | string_lexing, |
4 | yellow::{ | 4 | yellow::{ |
5 | SyntaxError, | 5 | SyntaxError, |
@@ -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, |