aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 09:05:55 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 09:05:55 +0000
commit3f4be819125ce4a22edd86721fa56b5caba99c2e (patch)
treebe93895ddc08c911585d9f7bc64623a3741f32c6
parent4e444d2bc24d16284401444fd2154f63e0f96070 (diff)
parent122410d7aa34a32d468a3173858cbc8a2bbc68f5 (diff)
Merge #449
449: switch to new rowan API r=matklad a=matklad closes https://github.com/rust-analyzer/rust-analyzer/issues/448 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--Cargo.lock30
-rw-r--r--crates/ra_analysis/src/completion/complete_fn_param.rs6
-rw-r--r--crates/ra_analysis/src/completion/complete_keyword.rs6
-rw-r--r--crates/ra_analysis/src/completion/completion_context.rs29
-rw-r--r--crates/ra_analysis/src/extend_selection.rs8
-rw-r--r--crates/ra_analysis/src/goto_defenition.rs4
-rw-r--r--crates/ra_analysis/src/hover.rs30
-rw-r--r--crates/ra_analysis/src/imp.rs28
-rw-r--r--crates/ra_analysis/src/lib.rs8
-rw-r--r--crates/ra_analysis/src/runnables.rs12
-rw-r--r--crates/ra_analysis/src/symbol_index.rs8
-rw-r--r--crates/ra_analysis/src/syntax_highlighting.rs2
-rw-r--r--crates/ra_cli/src/main.rs10
-rw-r--r--crates/ra_db/src/lib.rs8
-rw-r--r--crates/ra_db/src/syntax_ptr.rs12
-rw-r--r--crates/ra_editor/src/assists.rs16
-rw-r--r--crates/ra_editor/src/assists/add_derive.rs2
-rw-r--r--crates/ra_editor/src/assists/change_visibility.rs2
-rw-r--r--crates/ra_editor/src/assists/introduce_variable.rs4
-rw-r--r--crates/ra_editor/src/diagnostics.rs32
-rw-r--r--crates/ra_editor/src/extend_selection.rs24
-rw-r--r--crates/ra_editor/src/folding_ranges.rs17
-rw-r--r--crates/ra_editor/src/lib.rs24
-rw-r--r--crates/ra_editor/src/structure.rs12
-rw-r--r--crates/ra_editor/src/test_utils.rs10
-rw-r--r--crates/ra_editor/src/typing.rs36
-rw-r--r--crates/ra_hir/src/adt.rs4
-rw-r--r--crates/ra_hir/src/code_model_api.rs13
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs18
-rw-r--r--crates/ra_hir/src/db.rs6
-rw-r--r--crates/ra_hir/src/expr.rs92
-rw-r--r--crates/ra_hir/src/function.rs17
-rw-r--r--crates/ra_hir/src/function/scope.rs24
-rw-r--r--crates/ra_hir/src/ids.rs27
-rw-r--r--crates/ra_hir/src/impl_block.rs22
-rw-r--r--crates/ra_hir/src/macros.rs21
-rw-r--r--crates/ra_hir/src/module_tree.rs40
-rw-r--r--crates/ra_hir/src/name.rs4
-rw-r--r--crates/ra_hir/src/nameres.rs34
-rw-r--r--crates/ra_hir/src/path.rs12
-rw-r--r--crates/ra_hir/src/query_definitions.rs32
-rw-r--r--crates/ra_hir/src/source_binder.rs17
-rw-r--r--crates/ra_hir/src/type_ref.rs8
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs2
-rw-r--r--crates/ra_syntax/Cargo.toml2
-rw-r--r--crates/ra_syntax/src/algo.rs16
-rw-r--r--crates/ra_syntax/src/algo/visit.rs30
-rw-r--r--crates/ra_syntax/src/ast.rs210
-rw-r--r--crates/ra_syntax/src/ast/generated.rs4843
-rw-r--r--crates/ra_syntax/src/ast/generated.rs.tera93
-rw-r--r--crates/ra_syntax/src/lib.rs38
-rw-r--r--crates/ra_syntax/src/reparsing.rs35
-rw-r--r--crates/ra_syntax/src/utils.rs17
-rw-r--r--crates/ra_syntax/src/validation.rs15
-rw-r--r--crates/ra_syntax/src/validation/byte.rs8
-rw-r--r--crates/ra_syntax/src/validation/byte_string.rs8
-rw-r--r--crates/ra_syntax/src/validation/char.rs8
-rw-r--r--crates/ra_syntax/src/validation/string.rs8
-rw-r--r--crates/ra_syntax/src/yellow.rs148
-rw-r--r--crates/ra_syntax/src/yellow/syntax_text.rs6
-rw-r--r--crates/ra_syntax/tests/test.rs8
61 files changed, 2504 insertions, 3762 deletions
diff --git a/Cargo.lock b/Cargo.lock
index dbadfc64e..6ef51fed0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -221,7 +221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
221dependencies = [ 221dependencies = [
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"
284dependencies = [ 284dependencies = [
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]]
297name = "flexi_logger" 297name = "flexi_logger"
298version = "0.10.3" 298version = "0.10.4"
299source = "registry+https://github.com/rust-lang/crates.io-index" 299source = "registry+https://github.com/rust-lang/crates.io-index"
300dependencies = [ 300dependencies = [
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"
706dependencies = [ 706dependencies = [
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]]
971name = "rowan" 971name = "rowan"
972version = "0.1.4" 972version = "0.2.0"
973source = "registry+https://github.com/rust-lang/crates.io-index" 973source = "registry+https://github.com/rust-lang/crates.io-index"
974dependencies = [ 974dependencies = [
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"
1075dependencies = [ 1075dependencies = [
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]]
1142name = "syn" 1142name = "syn"
1143version = "0.15.23" 1143version = "0.15.24"
1144source = "registry+https://github.com/rust-lang/crates.io-index" 1144source = "registry+https://github.com/rust-lang/crates.io-index"
1145dependencies = [ 1145dependencies = [
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"
1155dependencies = [ 1155dependencies = [
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
8use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; 8use 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
79fn is_in_loop_body(leaf: SyntaxNodeRef) -> bool { 79fn 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
98fn complete_return(fn_def: ast::FnDef, can_be_stmt: bool) -> Option<CompletionItem> { 98fn 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 @@
1use ra_editor::find_node_at_offset; 1use ra_editor::find_node_at_offset;
2use ra_text_edit::AtomTextEdit; 2use ra_text_edit::AtomTextEdit;
3use ra_syntax::{ 3use 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};
13use hir::source_binder; 9use hir::source_binder;
@@ -20,11 +16,11 @@ use crate::{db, FilePosition, Cancelable};
20pub(super) struct CompletionContext<'a> { 16pub(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> {
44impl<'a> CompletionContext<'a> { 40impl<'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
200fn find_node_with_range<'a, N: AstNode<'a>>( 196fn 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
208fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool { 201fn 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 @@
1use ra_db::SyntaxDatabase; 1use ra_db::SyntaxDatabase;
2use ra_syntax::{ 2use 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
20fn extend_selection_in_macro( 20fn 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
33fn find_macro_call(node: SyntaxNodeRef, range: TextRange) -> Option<ast::MacroCall> { 33fn 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(
23pub(crate) fn reference_defenition( 23pub(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(
53fn name_defenition( 53fn 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 @@
1use ra_db::{Cancelable, SyntaxDatabase}; 1use ra_db::{Cancelable, SyntaxDatabase};
2use ra_editor::find_node_at_offset; 2use ra_editor::find_node_at_offset;
3use ra_syntax::{ 3use 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
90impl NavigationTarget { 90impl NavigationTarget {
91 fn node(&self, db: &RootDatabase) -> Option<SyntaxNode> { 91 fn node(&self, db: &RootDatabase) -> Option<TreePtr<SyntaxNode>> {
92 let source_file = db.source_file(self.file_id); 92 let source_file = db.source_file(self.file_id);
93 let source_file = source_file.syntax(); 93 let source_file = source_file.syntax();
94 let node = source_file 94 let node = source_file
95 .descendants() 95 .descendants()
96 .find(|node| node.kind() == self.kind && node.range() == self.range)? 96 .find(|node| node.kind() == self.kind && node.range() == self.range)?
97 .owned(); 97 .to_owned();
98 Some(node) 98 Some(node)
99 } 99 }
100 100
101 fn docs(&self, db: &RootDatabase) -> Option<String> { 101 fn docs(&self, db: &RootDatabase) -> Option<String> {
102 let node = self.node(db)?; 102 let node = self.node(db)?;
103 let node = node.borrowed(); 103 fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> {
104 fn doc_comments<'a, N: ast::DocCommentsOwner<'a>>(node: N) -> Option<String> {
105 let comments = node.doc_comment_text(); 104 let comments = node.doc_comment_text();
106 if comments.is_empty() { 105 if comments.is_empty() {
107 None 106 None
@@ -119,7 +118,7 @@ impl NavigationTarget {
119 .visit(doc_comments::<ast::TypeDef>) 118 .visit(doc_comments::<ast::TypeDef>)
120 .visit(doc_comments::<ast::ConstDef>) 119 .visit(doc_comments::<ast::ConstDef>)
121 .visit(doc_comments::<ast::StaticDef>) 120 .visit(doc_comments::<ast::StaticDef>)
122 .accept(node)? 121 .accept(&node)?
123 } 122 }
124 123
125 /// Get a description of this node. 124 /// Get a description of this node.
@@ -128,50 +127,49 @@ impl NavigationTarget {
128 fn description(&self, db: &RootDatabase) -> Option<String> { 127 fn description(&self, db: &RootDatabase) -> Option<String> {
129 // TODO: After type inference is done, add type information to improve the output 128 // TODO: After type inference is done, add type information to improve the output
130 let node = self.node(db)?; 129 let node = self.node(db)?;
131 let node = node.borrowed();
132 // TODO: Refactor to be have less repetition 130 // TODO: Refactor to be have less repetition
133 visitor() 131 visitor()
134 .visit(|node: ast::FnDef| { 132 .visit(|node: &ast::FnDef| {
135 let mut string = "fn ".to_string(); 133 let mut string = "fn ".to_string();
136 node.name()?.syntax().text().push_to(&mut string); 134 node.name()?.syntax().text().push_to(&mut string);
137 Some(string) 135 Some(string)
138 }) 136 })
139 .visit(|node: ast::StructDef| { 137 .visit(|node: &ast::StructDef| {
140 let mut string = "struct ".to_string(); 138 let mut string = "struct ".to_string();
141 node.name()?.syntax().text().push_to(&mut string); 139 node.name()?.syntax().text().push_to(&mut string);
142 Some(string) 140 Some(string)
143 }) 141 })
144 .visit(|node: ast::EnumDef| { 142 .visit(|node: &ast::EnumDef| {
145 let mut string = "enum ".to_string(); 143 let mut string = "enum ".to_string();
146 node.name()?.syntax().text().push_to(&mut string); 144 node.name()?.syntax().text().push_to(&mut string);
147 Some(string) 145 Some(string)
148 }) 146 })
149 .visit(|node: ast::TraitDef| { 147 .visit(|node: &ast::TraitDef| {
150 let mut string = "trait ".to_string(); 148 let mut string = "trait ".to_string();
151 node.name()?.syntax().text().push_to(&mut string); 149 node.name()?.syntax().text().push_to(&mut string);
152 Some(string) 150 Some(string)
153 }) 151 })
154 .visit(|node: ast::Module| { 152 .visit(|node: &ast::Module| {
155 let mut string = "mod ".to_string(); 153 let mut string = "mod ".to_string();
156 node.name()?.syntax().text().push_to(&mut string); 154 node.name()?.syntax().text().push_to(&mut string);
157 Some(string) 155 Some(string)
158 }) 156 })
159 .visit(|node: ast::TypeDef| { 157 .visit(|node: &ast::TypeDef| {
160 let mut string = "type ".to_string(); 158 let mut string = "type ".to_string();
161 node.name()?.syntax().text().push_to(&mut string); 159 node.name()?.syntax().text().push_to(&mut string);
162 Some(string) 160 Some(string)
163 }) 161 })
164 .visit(|node: ast::ConstDef| { 162 .visit(|node: &ast::ConstDef| {
165 let mut string = "const ".to_string(); 163 let mut string = "const ".to_string();
166 node.name()?.syntax().text().push_to(&mut string); 164 node.name()?.syntax().text().push_to(&mut string);
167 Some(string) 165 Some(string)
168 }) 166 })
169 .visit(|node: ast::StaticDef| { 167 .visit(|node: &ast::StaticDef| {
170 let mut string = "static ".to_string(); 168 let mut string = "static ".to_string();
171 node.name()?.syntax().text().push_to(&mut string); 169 node.name()?.syntax().text().push_to(&mut string);
172 Some(string) 170 Some(string)
173 }) 171 })
174 .accept(node)? 172 .accept(&node)?
175 } 173 }
176} 174}
177 175
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 07a966290..8ac430e41 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -8,10 +8,9 @@ use hir::{
8use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; 8use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
9use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity}; 9use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity};
10use ra_syntax::{ 10use 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
17use crate::{ 16use crate::{
@@ -113,7 +112,6 @@ impl db::RootDatabase {
113 None => return Ok(Vec::new()), 112 None => return Ok(Vec::new()),
114 Some(it) => it, 113 Some(it) => it,
115 }; 114 };
116 let ast_module = ast_module.borrowed();
117 let name = ast_module.name().unwrap(); 115 let name = ast_module.name().unwrap();
118 Ok(vec![NavigationTarget { 116 Ok(vec![NavigationTarget {
119 file_id, 117 file_id,
@@ -163,9 +161,9 @@ impl db::RootDatabase {
163 161
164 fn find_binding<'a>( 162 fn find_binding<'a>(
165 db: &db::RootDatabase, 163 db: &db::RootDatabase,
166 source_file: &'a SourceFileNode, 164 source_file: &'a SourceFile,
167 position: FilePosition, 165 position: FilePosition,
168 ) -> Cancelable<Option<(ast::BindPat<'a>, hir::Function)>> { 166 ) -> Cancelable<Option<(&'a ast::BindPat, hir::Function)>> {
169 let syntax = source_file.syntax(); 167 let syntax = source_file.syntax();
170 if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { 168 if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) {
171 let descr = ctry!(source_binder::function_from_child_node( 169 let descr = ctry!(source_binder::function_from_child_node(
@@ -281,7 +279,7 @@ impl db::RootDatabase {
281 if symbol.ptr.kind() == FN_DEF { 279 if symbol.ptr.kind() == FN_DEF {
282 let fn_file = self.source_file(symbol.file_id); 280 let fn_file = self.source_file(symbol.file_id);
283 let fn_def = symbol.ptr.resolve(&fn_file); 281 let fn_def = symbol.ptr.resolve(&fn_file);
284 let fn_def = ast::FnDef::cast(fn_def.borrowed()).unwrap(); 282 let fn_def = ast::FnDef::cast(&fn_def).unwrap();
285 let descr = ctry!(source_binder::function_from_source( 283 let descr = ctry!(source_binder::function_from_source(
286 self, 284 self,
287 symbol.file_id, 285 symbol.file_id,
@@ -352,7 +350,7 @@ impl db::RootDatabase {
352 .collect::<Vec<_>>(); 350 .collect::<Vec<_>>();
353 Ok(res) 351 Ok(res)
354 } 352 }
355 pub(crate) fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<FileSymbol>> { 353 pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Cancelable<Vec<FileSymbol>> {
356 let name = name_ref.text(); 354 let name = name_ref.text();
357 let mut query = Query::new(name.to_string()); 355 let mut query = Query::new(name.to_string());
358 query.exact(); 356 query.exact();
@@ -379,12 +377,12 @@ impl SourceChange {
379} 377}
380 378
381enum FnCallNode<'a> { 379enum 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
386impl<'a> FnCallNode<'a> { 384impl<'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
27use std::{fmt, sync::Arc}; 27use std::{fmt, sync::Arc};
28 28
29use ra_syntax::{SmolStr, SourceFileNode, SyntaxKind, TextRange, TextUnit}; 29use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit};
30use ra_text_edit::TextEdit; 30use ra_text_edit::TextEdit;
31use rayon::prelude::*; 31use rayon::prelude::*;
32use relative_path::RelativePathBuf; 32use 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 @@
1use itertools::Itertools; 1use itertools::Itertools;
2use ra_syntax::{ 2use ra_syntax::{
3 TextRange, SyntaxNode,
3 ast::{self, AstNode, NameOwner, ModuleItemOwner}, 4 ast::{self, AstNode, NameOwner, ModuleItemOwner},
4 TextRange, SyntaxNodeRef,
5}; 5};
6use ra_db::{Cancelable, SyntaxDatabase}; 6use 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
33fn runnable(db: &RootDatabase, file_id: FileId, item: SyntaxNodeRef) -> Option<Runnable> { 33fn 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
43fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> { 43fn 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
60fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Option<Runnable> { 60fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Option<Runnable> {
61 let has_test_function = module 61 let has_test_function = module
62 .item_list()? 62 .item_list()?
63 .items() 63 .items()
64 .filter_map(|it| match it { 64 .filter_map(|it| match it.kind() {
65 ast::ModuleItem::FnDef(it) => Some(it), 65 ast::ModuleItemKind::FnDef(it) => Some(it),
66 _ => None, 66 _ => None,
67 }) 67 })
68 .any(|f| f.has_atom_attr("test")); 68 .any(|f| f.has_atom_attr("test"));
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs
index e2b1c88fe..ed1796756 100644
--- a/crates/ra_analysis/src/symbol_index.rs
+++ b/crates/ra_analysis/src/symbol_index.rs
@@ -27,7 +27,7 @@ use std::{
27 27
28use fst::{self, Streamer}; 28use fst::{self, Streamer};
29use ra_syntax::{ 29use ra_syntax::{
30 SyntaxNodeRef, SourceFileNode, SmolStr, 30 SyntaxNode, SourceFile, SmolStr, TreePtr, AstNode,
31 algo::{visit::{visitor, Visitor}, find_covering_node}, 31 algo::{visit::{visitor, Visitor}, find_covering_node},
32 SyntaxKind::{self, *}, 32 SyntaxKind::{self, *},
33 ast::{self, NameOwner}, 33 ast::{self, NameOwner},
@@ -141,7 +141,7 @@ impl SymbolIndex {
141 } 141 }
142 142
143 pub(crate) fn for_files( 143 pub(crate) fn for_files(
144 files: impl ParallelIterator<Item = (FileId, SourceFileNode)>, 144 files: impl ParallelIterator<Item = (FileId, TreePtr<SourceFile>)>,
145 ) -> SymbolIndex { 145 ) -> SymbolIndex {
146 let symbols = files 146 let symbols = files
147 .flat_map(|(file_id, file)| { 147 .flat_map(|(file_id, file)| {
@@ -203,8 +203,8 @@ pub(crate) struct FileSymbol {
203 pub(crate) ptr: LocalSyntaxPtr, 203 pub(crate) ptr: LocalSyntaxPtr,
204} 204}
205 205
206fn to_symbol(node: SyntaxNodeRef) -> Option<(SmolStr, LocalSyntaxPtr)> { 206fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, LocalSyntaxPtr)> {
207 fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<(SmolStr, LocalSyntaxPtr)> { 207 fn decl<N: NameOwner>(node: &N) -> Option<(SmolStr, LocalSyntaxPtr)> {
208 let name = node.name()?.text(); 208 let name = node.name()?.text();
209 let ptr = LocalSyntaxPtr::new(node.syntax()); 209 let ptr = LocalSyntaxPtr::new(node.syntax());
210 Some((name, ptr)) 210 Some((name, ptr))
diff --git a/crates/ra_analysis/src/syntax_highlighting.rs b/crates/ra_analysis/src/syntax_highlighting.rs
index 35e153ca0..d2dc6cfbb 100644
--- a/crates/ra_analysis/src/syntax_highlighting.rs
+++ b/crates/ra_analysis/src/syntax_highlighting.rs
@@ -16,7 +16,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Hi
16 .filter_map(ast::MacroCall::cast) 16 .filter_map(ast::MacroCall::cast)
17 { 17 {
18 if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) { 18 if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) {
19 let mapped_ranges = ra_editor::highlight(exp.syntax().borrowed()) 19 let mapped_ranges = ra_editor::highlight(&exp.syntax())
20 .into_iter() 20 .into_iter()
21 .filter_map(|r| { 21 .filter_map(|r| {
22 let mapped_range = exp.map_range_back(r.range)?; 22 let mapped_range = exp.map_range_back(r.range)?;
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index a3b856aa9..0d12f3a88 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -3,7 +3,7 @@ use std::{fs, io::Read, path::Path, time::Instant};
3use clap::{App, Arg, SubCommand}; 3use clap::{App, Arg, SubCommand};
4use join_to_string::join; 4use join_to_string::join;
5use ra_editor::{extend_selection, file_structure, syntax_tree}; 5use ra_editor::{extend_selection, file_structure, syntax_tree};
6use ra_syntax::{SourceFileNode, TextRange}; 6use ra_syntax::{SourceFile, TextRange, TreePtr, AstNode};
7use tools::collect_tests; 7use tools::collect_tests;
8 8
9type Result<T> = ::std::result::Result<T, failure::Error>; 9type Result<T> = ::std::result::Result<T, failure::Error>;
@@ -71,9 +71,9 @@ fn main() -> Result<()> {
71 Ok(()) 71 Ok(())
72} 72}
73 73
74fn file() -> Result<SourceFileNode> { 74fn 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
79fn read_stdin() -> Result<String> { 79fn 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
100fn selections(file: &SourceFileNode, start: u32, end: u32) -> String { 100fn 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;
8use std::sync::Arc; 8use std::sync::Arc;
9 9
10use ra_editor::LineIndex; 10use ra_editor::LineIndex;
11use ra_syntax::{TextUnit, TextRange, SourceFileNode}; 11use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr};
12 12
13pub use crate::{ 13pub use crate::{
14 cancelation::{Canceled, Cancelable}, 14 cancelation::{Canceled, Cancelable},
@@ -47,7 +47,7 @@ pub trait BaseDatabase: salsa::Database {
47 47
48salsa::query_group! { 48salsa::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
59fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode { 59fn 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}
63fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { 63fn 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 @@
1use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; 1use 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
10impl LocalSyntaxPtr { 10impl 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]
41fn test_local_syntax_ptr() { 41fn test_local_syntax_ptr() {
42 use ra_syntax::{ast, AstNode}; 42 use ra_syntax::{ast, AstNode};
43 let file = SourceFileNode::parse("struct Foo { f: u32, }"); 43 let file = SourceFile::parse("struct Foo { f: u32, }");
44 let field = file 44 let field = file
45 .syntax() 45 .syntax()
46 .descendants() 46 .descendants()
@@ -48,5 +48,5 @@ fn test_local_syntax_ptr() {
48 .unwrap(); 48 .unwrap();
49 let ptr = LocalSyntaxPtr::new(field.syntax()); 49 let ptr = LocalSyntaxPtr::new(field.syntax());
50 let field_syntax = ptr.resolve(&file); 50 let field_syntax = ptr.resolve(&file);
51 assert_eq!(field.syntax(), field_syntax); 51 assert_eq!(field.syntax(), &*field_syntax);
52} 52}
diff --git a/crates/ra_editor/src/assists.rs b/crates/ra_editor/src/assists.rs
index 57b78342a..a320caabf 100644
--- a/crates/ra_editor/src/assists.rs
+++ b/crates/ra_editor/src/assists.rs
@@ -12,7 +12,7 @@ mod split_import;
12 12
13use ra_text_edit::{TextEdit, TextEditBuilder}; 13use ra_text_edit::{TextEdit, TextEditBuilder};
14use ra_syntax::{ 14use ra_syntax::{
15 Direction, SyntaxNodeRef, TextUnit, TextRange,SourceFileNode, AstNode, 15 Direction, SyntaxNode, TextUnit, TextRange, SourceFile, AstNode,
16 algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset}, 16 algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset},
17}; 17};
18 18
@@ -28,7 +28,7 @@ pub use self::{
28}; 28};
29 29
30/// Return all the assists applicable at the given position. 30/// Return all the assists applicable at the given position.
31pub fn assists(file: &SourceFileNode, range: TextRange) -> Vec<LocalEdit> { 31pub fn assists(file: &SourceFile, range: TextRange) -> Vec<LocalEdit> {
32 let ctx = AssistCtx::new(file, range); 32 let ctx = AssistCtx::new(file, range);
33 [ 33 [
34 flip_comma, 34 flip_comma,
@@ -50,7 +50,7 @@ pub struct LocalEdit {
50 pub cursor_position: Option<TextUnit>, 50 pub cursor_position: Option<TextUnit>,
51} 51}
52 52
53fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { 53fn non_trivia_sibling(node: &SyntaxNode, direction: Direction) -> Option<&SyntaxNode> {
54 node.siblings(direction) 54 node.siblings(direction)
55 .skip(1) 55 .skip(1)
56 .find(|node| !node.kind().is_trivia()) 56 .find(|node| !node.kind().is_trivia())
@@ -88,7 +88,7 @@ fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<Synta
88/// easier to just compute the edit eagarly :-) 88/// easier to just compute the edit eagarly :-)
89#[derive(Debug, Clone)] 89#[derive(Debug, Clone)]
90pub struct AssistCtx<'a> { 90pub struct AssistCtx<'a> {
91 source_file: &'a SourceFileNode, 91 source_file: &'a SourceFile,
92 range: TextRange, 92 range: TextRange,
93 should_compute_edit: bool, 93 should_compute_edit: bool,
94} 94}
@@ -106,7 +106,7 @@ struct AssistBuilder {
106} 106}
107 107
108impl<'a> AssistCtx<'a> { 108impl<'a> AssistCtx<'a> {
109 pub fn new(source_file: &'a SourceFileNode, range: TextRange) -> AssistCtx { 109 pub fn new(source_file: &'a SourceFile, range: TextRange) -> AssistCtx {
110 AssistCtx { 110 AssistCtx {
111 source_file, 111 source_file,
112 range, 112 range,
@@ -145,13 +145,13 @@ impl<'a> AssistCtx<'a> {
145 })) 145 }))
146 } 146 }
147 147
148 pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<SyntaxNodeRef<'a>> { 148 pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<&'a SyntaxNode> {
149 find_leaf_at_offset(self.source_file.syntax(), self.range.start()) 149 find_leaf_at_offset(self.source_file.syntax(), self.range.start())
150 } 150 }
151 pub(crate) fn node_at_offset<N: AstNode<'a>>(&self) -> Option<N> { 151 pub(crate) fn node_at_offset<N: AstNode>(&self) -> Option<&'a N> {
152 find_node_at_offset(self.source_file.syntax(), self.range.start()) 152 find_node_at_offset(self.source_file.syntax(), self.range.start())
153 } 153 }
154 pub(crate) fn covering_node(&self) -> SyntaxNodeRef<'a> { 154 pub(crate) fn covering_node(&self) -> &'a SyntaxNode {
155 find_covering_node(self.source_file.syntax(), self.range) 155 find_covering_node(self.source_file.syntax(), self.range)
156 } 156 }
157} 157}
diff --git a/crates/ra_editor/src/assists/add_derive.rs b/crates/ra_editor/src/assists/add_derive.rs
index 1e2cd4f30..6e964d011 100644
--- a/crates/ra_editor/src/assists/add_derive.rs
+++ b/crates/ra_editor/src/assists/add_derive.rs
@@ -28,7 +28,7 @@ pub fn add_derive(ctx: AssistCtx) -> Option<Assist> {
28} 28}
29 29
30// Insert `derive` after doc comments. 30// Insert `derive` after doc comments.
31fn derive_insertion_offset(nominal: ast::NominalDef) -> Option<TextUnit> { 31fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextUnit> {
32 let non_ws_child = nominal 32 let non_ws_child = nominal
33 .syntax() 33 .syntax()
34 .children() 34 .children()
diff --git a/crates/ra_editor/src/assists/change_visibility.rs b/crates/ra_editor/src/assists/change_visibility.rs
index 6c8466394..89729e2c2 100644
--- a/crates/ra_editor/src/assists/change_visibility.rs
+++ b/crates/ra_editor/src/assists/change_visibility.rs
@@ -46,7 +46,7 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> {
46 }) 46 })
47} 47}
48 48
49fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> { 49fn 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 @@
1use ra_syntax::{ 1use 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
7use crate::assists::{AssistCtx, Assist}; 7use 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.
42fn anchor_stmt(expr: ast::Expr) -> Option<SyntaxNodeRef> { 42fn anchor_stmt(expr: &ast::Expr) -> Option<&SyntaxNode> {
43 expr.syntax().ancestors().find(|&node| { 43 expr.syntax().ancestors().find(|&node| {
44 if ast::Stmt::cast(node).is_some() { 44 if ast::Stmt::cast(node).is_some() {
45 return true; 45 return true;
diff --git a/crates/ra_editor/src/diagnostics.rs b/crates/ra_editor/src/diagnostics.rs
index 199b0e502..2b695dfdf 100644
--- a/crates/ra_editor/src/diagnostics.rs
+++ b/crates/ra_editor/src/diagnostics.rs
@@ -1,25 +1,15 @@
1use itertools::Itertools; 1use itertools::Itertools;
2 2
3use ra_syntax::{ 3use 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};
10use ra_syntax::SyntaxNodeRef;
11use ra_text_edit::{
12 TextEdit,
13 TextEditBuilder,
14};
15 6
16use crate::{
17 Diagnostic,
18 LocalEdit,
19 Severity,
20}; 7};
8use ra_text_edit::{TextEdit, TextEditBuilder};
9
10use crate::{Diagnostic, LocalEdit, Severity};
21 11
22pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> { 12pub 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
49fn check_unnecessary_braces_in_use_statement( 39fn 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
81fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( 71fn 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
103fn check_struct_shorthand_initialization( 93fn 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 @@
1use ra_syntax::{ 1use 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
8pub fn extend_selection(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> { 7pub 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
42fn extend_single_word_in_comment_or_string( 41fn 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
69fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { 68fn 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
92fn pick_best<'a>(l: SyntaxNodeRef<'a>, r: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> { 91fn 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
103fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> { 102fn 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
113fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef { 112fn 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)]
126mod tests { 125mod 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 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ 3use 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
22pub fn folding_ranges(file: &SourceFileNode) -> Vec<Fold> { 21pub 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
72fn has_newline(node: SyntaxNodeRef) -> bool { 71fn 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
88fn contiguous_range_for_group<'a>( 87fn 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
126fn contiguous_range_for_comment<'a>( 125fn 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};
22use ra_text_edit::TextEditBuilder; 22use ra_text_edit::TextEditBuilder;
23use ra_syntax::{ 23use 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};
30use rustc_hash::FxHashSet; 29use 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
52pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { 51pub 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
70pub fn highlight(root: SyntaxNodeRef) -> Vec<HighlightedRange> { 69pub 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
120pub fn syntax_tree(file: &SourceFileNode) -> String { 119pub 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
124pub fn find_node_at_offset<'a, N: AstNode<'a>>( 123pub 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)]
132mod tests { 128mod 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
142fn main() {} 140fn 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;
3use ra_syntax::{ 3use 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
18pub fn file_structure(file: &SourceFileNode) -> Vec<StructureNode> { 18pub 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
41fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> { 41fn 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#"
96struct Foo { 96struct Foo {
97 x: i32 97 x: i32
diff --git a/crates/ra_editor/src/test_utils.rs b/crates/ra_editor/src/test_utils.rs
index f0a4f250a..bf40c92c0 100644
--- a/crates/ra_editor/src/test_utils.rs
+++ b/crates/ra_editor/src/test_utils.rs
@@ -1,15 +1,15 @@
1use ra_syntax::{SourceFileNode, TextRange, TextUnit}; 1use ra_syntax::{SourceFile, TextRange, TextUnit};
2 2
3use crate::LocalEdit; 3use crate::LocalEdit;
4pub use test_utils::*; 4pub use test_utils::*;
5 5
6pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>( 6pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>(
7 before: &str, 7 before: &str,
8 after: &str, 8 after: &str,
9 f: F, 9 f: F,
10) { 10) {
11 let (before_cursor_pos, before) = extract_offset(before); 11 let (before_cursor_pos, before) = extract_offset(before);
12 let file = SourceFileNode::parse(&before); 12 let file = SourceFile::parse(&before);
13 let result = f(&file, before_cursor_pos).expect("code action is not applicable"); 13 let result = f(&file, before_cursor_pos).expect("code action is not applicable");
14 let actual = result.edit.apply(&before); 14 let actual = result.edit.apply(&before);
15 let actual_cursor_pos = match result.cursor_position { 15 let actual_cursor_pos = match result.cursor_position {
@@ -20,13 +20,13 @@ pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>(
20 assert_eq_text!(after, &actual); 20 assert_eq_text!(after, &actual);
21} 21}
22 22
23pub fn check_action_range<F: Fn(&SourceFileNode, TextRange) -> Option<LocalEdit>>( 23pub fn check_action_range<F: Fn(&SourceFile, TextRange) -> Option<LocalEdit>>(
24 before: &str, 24 before: &str,
25 after: &str, 25 after: &str,
26 f: F, 26 f: F,
27) { 27) {
28 let (range, before) = extract_range(before); 28 let (range, before) = extract_range(before);
29 let file = SourceFileNode::parse(&before); 29 let file = SourceFile::parse(&before);
30 let result = f(&file, range).expect("code action is not applicable"); 30 let result = f(&file, range).expect("code action is not applicable");
31 let actual = result.edit.apply(&before); 31 let actual = result.edit.apply(&before);
32 let actual_cursor_pos = match result.cursor_position { 32 let actual_cursor_pos = match result.cursor_position {
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs
index 12500854c..5b260d2ac 100644
--- a/crates/ra_editor/src/typing.rs
+++ b/crates/ra_editor/src/typing.rs
@@ -5,15 +5,15 @@ use ra_syntax::{
5 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, 5 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset},
6 ast, 6 ast,
7 text_utils::intersect, 7 text_utils::intersect,
8 AstNode, Direction, SourceFileNode, SyntaxKind, 8 AstNode, Direction, SourceFile, SyntaxKind,
9 SyntaxKind::*, 9 SyntaxKind::*,
10 SyntaxNodeRef, TextRange, TextUnit, 10 SyntaxNode, TextRange, TextUnit,
11}; 11};
12use ra_text_edit::text_utils::contains_offset_nonstrict; 12use ra_text_edit::text_utils::contains_offset_nonstrict;
13 13
14use crate::{find_node_at_offset, LocalEdit, TextEditBuilder}; 14use crate::{find_node_at_offset, LocalEdit, TextEditBuilder};
15 15
16pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { 16pub 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
62pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { 62pub 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
88fn node_indent<'a>(file: &'a SourceFileNode, node: SyntaxNodeRef) -> Option<&'a str> { 88fn 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
108pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { 108pub 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
139pub fn on_dot_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { 139pub 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
189fn remove_newline( 189fn 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
269fn join_single_expr_block(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { 269fn 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
280fn single_expr(block: ast::Block) -> Option<ast::Expr> { 280fn 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
300fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { 300fn 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
310fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { 310fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str {
311 match left.kind() { 311 match left.kind() {
312 L_PAREN | L_BRACK => return "", 312 L_PAREN | L_BRACK => return "",
313 L_CURLY => { 313 L_CURLY => {
@@ -547,7 +547,7 @@ fn foo() {
547 547
548 fn check_join_lines_sel(before: &str, after: &str) { 548 fn check_join_lines_sel(before: &str, after: &str) {
549 let (sel, before) = extract_range(before); 549 let (sel, before) = extract_range(before);
550 let file = SourceFileNode::parse(&before); 550 let file = SourceFile::parse(&before);
551 let result = join_lines(&file, sel); 551 let result = join_lines(&file, sel);
552 let actual = result.edit.apply(&before); 552 let actual = result.edit.apply(&before);
553 assert_eq_text!(after, &actual); 553 assert_eq_text!(after, &actual);
@@ -626,7 +626,7 @@ pub fn handle_find_matching_brace() {
626 fn test_on_eq_typed() { 626 fn test_on_eq_typed() {
627 fn do_check(before: &str, after: &str) { 627 fn do_check(before: &str, after: &str) {
628 let (offset, before) = extract_offset(before); 628 let (offset, before) = extract_offset(before);
629 let file = SourceFileNode::parse(&before); 629 let file = SourceFile::parse(&before);
630 let result = on_eq_typed(&file, offset).unwrap(); 630 let result = on_eq_typed(&file, offset).unwrap();
631 let actual = result.edit.apply(&before); 631 let actual = result.edit.apply(&before);
632 assert_eq_text!(after, &actual); 632 assert_eq_text!(after, &actual);
@@ -670,7 +670,7 @@ fn foo() {
670 fn test_on_dot_typed() { 670 fn test_on_dot_typed() {
671 fn do_check(before: &str, after: &str) { 671 fn do_check(before: &str, after: &str) {
672 let (offset, before) = extract_offset(before); 672 let (offset, before) = extract_offset(before);
673 let file = SourceFileNode::parse(&before); 673 let file = SourceFile::parse(&before);
674 if let Some(result) = on_eq_typed(&file, offset) { 674 if let Some(result) = on_eq_typed(&file, offset) {
675 let actual = result.edit.apply(&before); 675 let actual = result.edit.apply(&before);
676 assert_eq_text!(after, &actual); 676 assert_eq_text!(after, &actual);
@@ -779,7 +779,7 @@ fn foo() {
779 fn test_on_enter() { 779 fn test_on_enter() {
780 fn apply_on_enter(before: &str) -> Option<String> { 780 fn apply_on_enter(before: &str) -> Option<String> {
781 let (offset, before) = extract_offset(before); 781 let (offset, before) = extract_offset(before);
782 let file = SourceFileNode::parse(&before); 782 let file = SourceFile::parse(&before);
783 let result = on_enter(&file, offset)?; 783 let result = on_enter(&file, offset)?;
784 let actual = result.edit.apply(&before); 784 let actual = result.edit.apply(&before);
785 let actual = add_cursor(&actual, result.cursor_position.unwrap()); 785 let actual = add_cursor(&actual, result.cursor_position.unwrap());
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index c6463235c..b700be267 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -42,7 +42,7 @@ pub struct StructData {
42} 42}
43 43
44impl StructData { 44impl 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
89impl EnumData { 89impl EnumData {
90 pub(crate) fn new(enum_def: ast::EnumDef) -> Self { 90 pub(crate) fn new(enum_def: &ast::EnumDef) -> Self {
91 let name = enum_def.name().map(|n| n.as_name()); 91 let name = enum_def.name().map(|n| n.as_name());
92 let variants = if let Some(evl) = enum_def.variant_list() { 92 let variants = if let Some(evl) = enum_def.variant_list() {
93 evl.variants() 93 evl.variants()
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 09b532f74..43cddb504 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -1,6 +1,6 @@
1use relative_path::RelativePathBuf; 1use relative_path::RelativePathBuf;
2use ra_db::{CrateId, Cancelable, FileId}; 2use ra_db::{CrateId, Cancelable, FileId};
3use ra_syntax::{ast, SyntaxNode}; 3use ra_syntax::{ast, TreePtr, SyntaxNode};
4 4
5use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope}; 5use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope};
6 6
@@ -36,8 +36,8 @@ pub struct Module {
36} 36}
37 37
38pub enum ModuleSource { 38pub 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 @@
1use ra_db::{Cancelable, SourceRootId, FileId}; 1use ra_db::{Cancelable, SourceRootId, FileId};
2use ra_syntax::{ast, SyntaxNode, AstNode}; 2use ra_syntax::{ast, SyntaxNode, AstNode, TreePtr};
3 3
4use crate::{ 4use 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 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_syntax::{SyntaxNode, SourceFileNode}; 3use ra_syntax::{SyntaxNode, TreePtr, SourceFile};
4use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, Cancelable}; 4use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, Cancelable};
5 5
6use crate::{ 6use 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
713pub(crate) fn collect_fn_body_syntax(node: ast::FnDef) -> BodySyntaxMapping { 715pub(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
8use ra_db::Cancelable; 8use ra_db::Cancelable;
9use ra_syntax::{ 9use 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
100pub(crate) fn fn_signature(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> { 100pub(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
146impl FnSignatureInfo { 145impl 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;
3use rustc_hash::{FxHashMap, FxHashSet}; 3use rustc_hash::{FxHashMap, FxHashSet};
4 4
5use ra_syntax::{ 5use 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
129impl ScopesWithSyntaxMapping { 129impl 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)]
310mod tests { 310mod 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 @@
1use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; 1use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId};
2use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast}; 2use ra_syntax::{TreePtr, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast};
3use ra_arena::{Arena, RawId, impl_arena_id}; 3use ra_arena::{Arena, RawId, impl_arena_id};
4 4
5use crate::{HirDatabase, PerNs, ModuleId, Def, Function, Struct, Enum, ImplBlock, Crate}; 5use 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)]
234pub struct SourceFileItems { 237pub 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
239impl SourceFileItems { 242impl 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
12use ra_db::LocalSyntaxPtr; 12use ra_db::LocalSyntaxPtr;
13use ra_syntax::{ 13use 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 {
28impl MacroDef { 28impl 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 {
152impl MacroExpansion { 152impl 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;
5use relative_path::RelativePathBuf; 5use relative_path::RelativePathBuf;
6use ra_db::{FileId, SourceRootId, Cancelable, SourceRoot}; 6use ra_db::{FileId, SourceRootId, Cancelable, SourceRoot};
7use ra_syntax::{ 7use 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};
12use ra_arena::{Arena, RawId, impl_arena_id}; 12use 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
216fn modules<'a>( 212fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator<Item = (Name, &ast::Module)> {
217 root: impl ast::ModuleItemOwner<'a>,
218) -> impl Iterator<Item = (Name, ast::Module<'a>)> {
219 root.items() 213 root.items()
220 .filter_map(|item| match item { 214 .filter_map(|item| match item.kind() {
221 ast::ModuleItem::Module(m) => Some(m), 215 ast::ModuleItemKind::Module(m) => Some(m),
222 _ => None, 216 _ => None,
223 }) 217 })
224 .filter_map(|module| { 218 .filter_map(|module| {
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs
index 599285346..dee1c9c5c 100644
--- a/crates/ra_hir/src/name.rs
+++ b/crates/ra_hir/src/name.rs
@@ -74,13 +74,13 @@ pub(crate) trait AsName {
74 fn as_name(&self) -> Name; 74 fn as_name(&self) -> Name;
75} 75}
76 76
77impl AsName for ast::NameRef<'_> { 77impl AsName for ast::NameRef {
78 fn as_name(&self) -> Name { 78 fn as_name(&self) -> Name {
79 Name::new(self.text()) 79 Name::new(self.text())
80 } 80 }
81} 81}
82 82
83impl AsName for ast::Name<'_> { 83impl AsName for ast::Name {
84 fn as_name(&self) -> Name { 84 fn as_name(&self) -> Name {
85 Name::new(self.text()) 85 Name::new(self.text())
86 } 86 }
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 9a412bc82..749fd604e 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -103,7 +103,7 @@ impl NamedImport {
103 item_id: Some(self.file_item_id), 103 item_id: Some(self.file_item_id),
104 }; 104 };
105 let syntax = db.file_item(source_item_id); 105 let syntax = db.file_item(source_item_id);
106 let offset = syntax.borrowed().range().start(); 106 let offset = syntax.range().start();
107 self.relative_range + offset 107 self.relative_range + offset
108 } 108 }
109} 109}
@@ -215,45 +215,45 @@ impl InputModuleItems {
215 &mut self, 215 &mut self,
216 file_id: HirFileId, 216 file_id: HirFileId,
217 file_items: &SourceFileItems, 217 file_items: &SourceFileItems,
218 item: ast::ModuleItem, 218 item: &ast::ModuleItem,
219 ) -> Option<()> { 219 ) -> Option<()> {
220 match item { 220 match item.kind() {
221 ast::ModuleItem::StructDef(it) => { 221 ast::ModuleItemKind::StructDef(it) => {
222 self.items.push(ModuleItem::new(file_id, file_items, it)?) 222 self.items.push(ModuleItem::new(file_id, file_items, it)?)
223 } 223 }
224 ast::ModuleItem::EnumDef(it) => { 224 ast::ModuleItemKind::EnumDef(it) => {
225 self.items.push(ModuleItem::new(file_id, file_items, it)?) 225 self.items.push(ModuleItem::new(file_id, file_items, it)?)
226 } 226 }
227 ast::ModuleItem::FnDef(it) => { 227 ast::ModuleItemKind::FnDef(it) => {
228 self.items.push(ModuleItem::new(file_id, file_items, it)?) 228 self.items.push(ModuleItem::new(file_id, file_items, it)?)
229 } 229 }
230 ast::ModuleItem::TraitDef(it) => { 230 ast::ModuleItemKind::TraitDef(it) => {
231 self.items.push(ModuleItem::new(file_id, file_items, it)?) 231 self.items.push(ModuleItem::new(file_id, file_items, it)?)
232 } 232 }
233 ast::ModuleItem::TypeDef(it) => { 233 ast::ModuleItemKind::TypeDef(it) => {
234 self.items.push(ModuleItem::new(file_id, file_items, it)?) 234 self.items.push(ModuleItem::new(file_id, file_items, it)?)
235 } 235 }
236 ast::ModuleItem::ImplBlock(_) => { 236 ast::ModuleItemKind::ImplBlock(_) => {
237 // impls don't define items 237 // impls don't define items
238 } 238 }
239 ast::ModuleItem::UseItem(it) => self.add_use_item(file_items, it), 239 ast::ModuleItemKind::UseItem(it) => self.add_use_item(file_items, it),
240 ast::ModuleItem::ExternCrateItem(_) => { 240 ast::ModuleItemKind::ExternCrateItem(_) => {
241 // TODO 241 // TODO
242 } 242 }
243 ast::ModuleItem::ConstDef(it) => { 243 ast::ModuleItemKind::ConstDef(it) => {
244 self.items.push(ModuleItem::new(file_id, file_items, it)?) 244 self.items.push(ModuleItem::new(file_id, file_items, it)?)
245 } 245 }
246 ast::ModuleItem::StaticDef(it) => { 246 ast::ModuleItemKind::StaticDef(it) => {
247 self.items.push(ModuleItem::new(file_id, file_items, it)?) 247 self.items.push(ModuleItem::new(file_id, file_items, it)?)
248 } 248 }
249 ast::ModuleItem::Module(it) => { 249 ast::ModuleItemKind::Module(it) => {
250 self.items.push(ModuleItem::new(file_id, file_items, it)?) 250 self.items.push(ModuleItem::new(file_id, file_items, it)?)
251 } 251 }
252 } 252 }
253 Some(()) 253 Some(())
254 } 254 }
255 255
256 fn add_use_item(&mut self, file_items: &SourceFileItems, item: ast::UseItem) { 256 fn add_use_item(&mut self, file_items: &SourceFileItems, item: &ast::UseItem) {
257 let file_item_id = file_items.id_of_unchecked(item.syntax()); 257 let file_item_id = file_items.id_of_unchecked(item.syntax());
258 let start_offset = item.syntax().range().start(); 258 let start_offset = item.syntax().range().start();
259 Path::expand_use_item(item, |path, range| { 259 Path::expand_use_item(item, |path, range| {
@@ -270,10 +270,10 @@ impl InputModuleItems {
270} 270}
271 271
272impl ModuleItem { 272impl 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
19impl Path { 19impl 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
101fn expand_use_tree( 101fn 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
149fn convert_path(prefix: Option<Path>, path: ast::Path) -> Option<Path> { 149fn 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
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7use ra_syntax::{ 7use ra_syntax::{
8 AstNode, SyntaxNode, 8 AstNode, SyntaxNode, TreePtr,
9 ast::{self, ModuleItemOwner} 9 ast::{self, ModuleItemOwner}
10}; 10};
11use ra_db::{SourceRootId, Cancelable,}; 11use 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
38pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<EnumData>> { 38pub(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
47pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { 46pub(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
54pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { 52pub(super) fn file_item(
53 db: &impl HirDatabase,
54 source_item_id: SourceItemId,
55) -> TreePtr<SyntaxNode> {
55 match source_item_id.item_id { 56 match source_item_id.item_id {
56 Some(id) => db.file_items(source_item_id.file_id)[id].clone(), 57 Some(id) => db.file_items(source_item_id.file_id)[id].to_owned(),
57 None => db.hir_source_file(source_item_id.file_id).syntax().owned(), 58 None => db
59 .hir_source_file(source_item_id.file_id)
60 .syntax()
61 .to_owned(),
58 } 62 }
59} 63}
60 64
@@ -88,7 +92,7 @@ pub(super) fn input_module_items(
88 let file_id = HirFileId::from(id); 92 let file_id = HirFileId::from(id);
89 let file_items = db.file_items(file_id); 93 let file_items = db.file_items(file_id);
90 //FIXME: expand recursively 94 //FIXME: expand recursively
91 for item in db.hir_source_file(file_id).borrowed().items() { 95 for item in db.hir_source_file(file_id).items() {
92 acc.add_item(file_id, &file_items, item); 96 acc.add_item(file_id, &file_items, item);
93 } 97 }
94 } 98 }
@@ -98,9 +102,9 @@ pub(super) fn input_module_items(
98 102
99 let mut res = InputModuleItems::default(); 103 let mut res = InputModuleItems::default();
100 match source { 104 match source {
101 ModuleSource::SourceFile(it) => fill(&mut res, &mut it.borrowed().items_with_macros()), 105 ModuleSource::SourceFile(it) => fill(&mut res, &mut it.items_with_macros()),
102 ModuleSource::Module(it) => { 106 ModuleSource::Module(it) => {
103 if let Some(item_list) = it.borrowed().item_list() { 107 if let Some(item_list) = it.item_list() {
104 fill(&mut res, &mut item_list.items_with_macros()) 108 fill(&mut res, &mut item_list.items_with_macros())
105 } 109 }
106 } 110 }
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 4c14650c0..82675c0e4 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -8,7 +8,7 @@
8use ra_db::{FileId, FilePosition, Cancelable}; 8use ra_db::{FileId, FilePosition, Cancelable};
9use ra_editor::find_node_at_offset; 9use ra_editor::find_node_at_offset;
10use ra_syntax::{ 10use 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
30pub fn module_from_declaration( 30pub 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(
60fn module_from_inline( 60fn 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(
77pub fn module_from_child_node( 77pub 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(
112pub fn function_from_source( 112pub 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(
122pub fn function_from_module( 122pub 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(
144pub fn function_from_child_node( 144pub fn function_from_child_node(
145 db: &impl HirDatabase, 145 db: &impl HirDatabase,
146 file_id: FileId, 146 file_id: FileId,
147 node: SyntaxNodeRef, 147 node: &SyntaxNode,
148) -> Cancelable<Option<Function>> { 148) -> Cancelable<Option<Function>> {
149 let fn_def = ctry!(node.ancestors().find_map(ast::FnDef::cast)); 149 let fn_def = ctry!(node.ancestors().find_map(ast::FnDef::cast));
150 function_from_source(db, file_id, fn_def) 150 function_from_source(db, file_id, fn_def)
@@ -170,8 +170,7 @@ pub fn macro_symbols(
170 if let Some(exp) = db.expand_macro_invocation(macro_call_id) { 170 if let Some(exp) = db.expand_macro_invocation(macro_call_id) {
171 let loc = macro_call_id.loc(db); 171 let loc = macro_call_id.loc(db);
172 let syntax = db.file_item(loc.source_item_id); 172 let syntax = db.file_item(loc.source_item_id);
173 let syntax = syntax.borrowed(); 173 let macro_call = ast::MacroCall::cast(&syntax).unwrap();
174 let macro_call = ast::MacroCall::cast(syntax).unwrap();
175 let off = macro_call.token_tree().unwrap().syntax().range().start(); 174 let off = macro_call.token_tree().unwrap().syntax().range().start();
176 let file = exp.file(); 175 let file = exp.file();
177 for trait_def in file.syntax().descendants().filter_map(ast::TraitDef::cast) { 176 for trait_def in file.syntax().descendants().filter_map(ast::TraitDef::cast) {
diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir/src/type_ref.rs
index 859f330c2..c9db4e0a5 100644
--- a/crates/ra_hir/src/type_ref.rs
+++ b/crates/ra_hir/src/type_ref.rs
@@ -56,9 +56,9 @@ pub enum TypeRef {
56 56
57impl TypeRef { 57impl 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::{
11use ra_analysis::{ 11use ra_analysis::{
12 FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, 12 FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange,
13}; 13};
14use ra_syntax::{text_utils::intersect, TextUnit}; 14use ra_syntax::{text_utils::intersect, TextUnit, AstNode};
15use ra_text_edit::text_utils::contains_offset_nonstrict; 15use ra_text_edit::text_utils::contains_offset_nonstrict;
16use rustc_hash::FxHashMap; 16use rustc_hash::FxHashMap;
17use serde_json::to_value; 17use 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"
13itertools = "0.8.0" 13itertools = "0.8.0"
14drop_bomb = "0.1.4" 14drop_bomb = "0.1.4"
15parking_lot = "0.7.0" 15parking_lot = "0.7.0"
16rowan = "0.1.2" 16rowan = "0.2.0"
17text_unit = "0.1.5" 17text_unit = "0.1.5"
18ra_text_edit = { path = "../ra_text_edit" } 18ra_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 @@
1pub mod visit; 1pub mod visit;
2 2
3use crate::{SyntaxNode, SyntaxNodeRef, TextRange, TextUnit}; 3use rowan::TransparentNewType;
4
5use crate::{SyntaxNode, TextRange, TextUnit};
4 6
5pub use rowan::LeafAtOffset; 7pub use rowan::LeafAtOffset;
6 8
7pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset<SyntaxNodeRef> { 9pub 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
15pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { 19pub 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
19pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { 23pub 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 @@
1use crate::{AstNode, SyntaxNodeRef}; 1use crate::{AstNode, SyntaxNode};
2 2
3use std::marker::PhantomData; 3use 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
16pub trait Visitor<'a>: Sized { 16pub 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 {
32pub trait VisitorCtx<'a>: Sized { 32pub 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> {
54impl<'a, T> Visitor<'a> for EmptyVisitor<T> { 54impl<'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> {
84impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> 84impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F>
85where 85where
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> {
105impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> 105impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F>
106where 106where
107 V: VisitorCtx<'a>, 107 V: VisitorCtx<'a>,
108 N: AstNode<'a>, 108 N: AstNode + 'a,
109 F: FnOnce(N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output, 109 F: FnOnce(&'a N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output,
110{ 110{
111 type Output = <V as VisitorCtx<'a>>::Output; 111 type Output = <V as VisitorCtx<'a>>::Output;
112 type Ctx = <V as VisitorCtx<'a>>::Ctx; 112 type Ctx = <V as VisitorCtx<'a>>::Ctx;
113 113
114 fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx> { 114 fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx> {
115 let VisCtx { inner, f, .. } = self; 115 let VisCtx { inner, f, .. } = self;
116 inner.accept(node).or_else(|ctx| match N::cast(node) { 116 inner.accept(node).or_else(|ctx| match N::cast(node) {
117 None => Err(ctx), 117 None => Err(ctx),
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 9ab59738f..0e303ee98 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -1,119 +1,115 @@
1mod generated; 1mod generated;
2 2
3use std::marker::PhantomData; 3use std::marker::PhantomData;
4use std::string::String as RustString;
5 4
6use itertools::Itertools; 5use itertools::Itertools;
7 6
8pub use self::generated::*; 7pub use self::generated::*;
9use crate::{ 8use 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.
20pub trait AstNode<'a>: Clone + Copy + 'a { 18pub 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
27pub trait NameOwner<'a>: AstNode<'a> { 26pub trait NameOwner: AstNode {
28 fn name(self) -> Option<Name<'a>> { 27 fn name(&self) -> Option<&Name> {
29 child_opt(self) 28 child_opt(self)
30 } 29 }
31} 30}
32 31
33pub trait VisibilityOwner<'a>: AstNode<'a> { 32pub trait VisibilityOwner: AstNode {
34 fn visibility(self) -> Option<Visibility<'a>> { 33 fn visibility(&self) -> Option<&Visibility> {
35 child_opt(self) 34 child_opt(self)
36 } 35 }
37} 36}
38 37
39pub trait LoopBodyOwner<'a>: AstNode<'a> { 38pub trait LoopBodyOwner: AstNode {
40 fn loop_body(self) -> Option<Block<'a>> { 39 fn loop_body(&self) -> Option<&Block> {
41 child_opt(self) 40 child_opt(self)
42 } 41 }
43} 42}
44 43
45pub trait ArgListOwner<'a>: AstNode<'a> { 44pub trait ArgListOwner: AstNode {
46 fn arg_list(self) -> Option<ArgList<'a>> { 45 fn arg_list(&self) -> Option<&ArgList> {
47 child_opt(self) 46 child_opt(self)
48 } 47 }
49} 48}
50 49
51pub trait FnDefOwner<'a>: AstNode<'a> { 50pub trait FnDefOwner: AstNode {
52 fn functions(self) -> AstChildren<'a, FnDef<'a>> { 51 fn functions(&self) -> AstChildren<FnDef> {
53 children(self) 52 children(self)
54 } 53 }
55} 54}
56 55
57// ModuleItem
58#[derive(Debug, Clone, Copy, PartialEq, Eq)] 56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub enum ItemOrMacro<'a> { 57pub enum ItemOrMacro<'a> {
60 Item(ModuleItem<'a>), 58 Item(&'a ModuleItem),
61 Macro(MacroCall<'a>), 59 Macro(&'a MacroCall),
62} 60}
63 61
64impl<'a> AstNode<'a> for ItemOrMacro<'a> { 62pub trait ModuleItemOwner: AstNode {
65 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 63 fn items(&self) -> AstChildren<ModuleItem> {
66 let res = if let Some(item) = ModuleItem::cast(syntax) { 64 children(self)
67 ItemOrMacro::Item(item)
68 } else if let Some(macro_call) = MacroCall::cast(syntax) {
69 ItemOrMacro::Macro(macro_call)
70 } else {
71 return None;
72 };
73 Some(res)
74 } 65 }
75 fn syntax(self) -> SyntaxNodeRef<'a> { 66 fn items_with_macros(&self) -> ItemOrMacroIter {
76 match self { 67 ItemOrMacroIter(self.syntax().children())
77 ItemOrMacro::Item(it) => it.syntax(),
78 ItemOrMacro::Macro(it) => it.syntax(),
79 }
80 } 68 }
81} 69}
82 70
83pub trait ModuleItemOwner<'a>: AstNode<'a> { 71#[derive(Debug)]
84 fn items(self) -> AstChildren<'a, ModuleItem<'a>> { 72pub struct ItemOrMacroIter<'a>(SyntaxNodeChildren<'a>);
85 children(self)
86 }
87 73
88 fn items_with_macros(self) -> AstChildren<'a, ItemOrMacro<'a>> { 74impl<'a> Iterator for ItemOrMacroIter<'a> {
89 children(self) 75 type Item = ItemOrMacro<'a>;
76 fn next(&mut self) -> Option<ItemOrMacro<'a>> {
77 loop {
78 let n = self.0.next()?;
79 if let Some(item) = ModuleItem::cast(n) {
80 return Some(ItemOrMacro::Item(item));
81 }
82 if let Some(call) = MacroCall::cast(n) {
83 return Some(ItemOrMacro::Macro(call));
84 }
85 }
90 } 86 }
91} 87}
92 88
93pub trait TypeParamsOwner<'a>: AstNode<'a> { 89pub trait TypeParamsOwner: AstNode {
94 fn type_param_list(self) -> Option<TypeParamList<'a>> { 90 fn type_param_list(&self) -> Option<&TypeParamList> {
95 child_opt(self) 91 child_opt(self)
96 } 92 }
97 93
98 fn where_clause(self) -> Option<WhereClause<'a>> { 94 fn where_clause(&self) -> Option<&WhereClause> {
99 child_opt(self) 95 child_opt(self)
100 } 96 }
101} 97}
102 98
103pub trait AttrsOwner<'a>: AstNode<'a> { 99pub trait AttrsOwner: AstNode {
104 fn attrs(self) -> AstChildren<'a, Attr<'a>> { 100 fn attrs(&self) -> AstChildren<Attr> {
105 children(self) 101 children(self)
106 } 102 }
107} 103}
108 104
109pub trait DocCommentsOwner<'a>: AstNode<'a> { 105pub trait DocCommentsOwner: AstNode {
110 fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { 106 fn doc_comments(&self) -> AstChildren<Comment> {
111 children(self) 107 children(self)
112 } 108 }
113 109
114 /// Returns the textual content of a doc comment block as a single string. 110 /// Returns the textual content of a doc comment block as a single string.
115 /// That is, strips leading `///` and joins lines 111 /// That is, strips leading `///` and joins lines
116 fn doc_comment_text(self) -> RustString { 112 fn doc_comment_text(&self) -> std::string::String {
117 self.doc_comments() 113 self.doc_comments()
118 .filter(|comment| comment.is_doc_comment()) 114 .filter(|comment| comment.is_doc_comment())
119 .map(|comment| { 115 .map(|comment| {
@@ -130,13 +126,13 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> {
130 } 126 }
131} 127}
132 128
133impl<'a> FnDef<'a> { 129impl FnDef {
134 pub fn has_atom_attr(&self, atom: &str) -> bool { 130 pub fn has_atom_attr(&self, atom: &str) -> bool {
135 self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) 131 self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom)
136 } 132 }
137} 133}
138 134
139impl<'a> Attr<'a> { 135impl Attr {
140 pub fn as_atom(&self) -> Option<SmolStr> { 136 pub fn as_atom(&self) -> Option<SmolStr> {
141 let tt = self.value()?; 137 let tt = self.value()?;
142 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; 138 let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?;
@@ -147,7 +143,7 @@ impl<'a> Attr<'a> {
147 } 143 }
148 } 144 }
149 145
150 pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> { 146 pub fn as_call(&self) -> Option<(SmolStr, &TokenTree)> {
151 let tt = self.value()?; 147 let tt = self.value()?;
152 let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; 148 let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?;
153 let args = TokenTree::cast(args)?; 149 let args = TokenTree::cast(args)?;
@@ -159,37 +155,37 @@ impl<'a> Attr<'a> {
159 } 155 }
160} 156}
161 157
162impl<'a> Lifetime<'a> { 158impl Lifetime {
163 pub fn text(&self) -> SmolStr { 159 pub fn text(&self) -> SmolStr {
164 self.syntax().leaf_text().unwrap().clone() 160 self.syntax().leaf_text().unwrap().clone()
165 } 161 }
166} 162}
167 163
168impl<'a> Char<'a> { 164impl Char {
169 pub fn text(&self) -> &SmolStr { 165 pub fn text(&self) -> &SmolStr {
170 &self.syntax().leaf_text().unwrap() 166 &self.syntax().leaf_text().unwrap()
171 } 167 }
172} 168}
173 169
174impl<'a> Byte<'a> { 170impl Byte {
175 pub fn text(&self) -> &SmolStr { 171 pub fn text(&self) -> &SmolStr {
176 &self.syntax().leaf_text().unwrap() 172 &self.syntax().leaf_text().unwrap()
177 } 173 }
178} 174}
179 175
180impl<'a> ByteString<'a> { 176impl ByteString {
181 pub fn text(&self) -> &SmolStr { 177 pub fn text(&self) -> &SmolStr {
182 &self.syntax().leaf_text().unwrap() 178 &self.syntax().leaf_text().unwrap()
183 } 179 }
184} 180}
185 181
186impl<'a> String<'a> { 182impl String {
187 pub fn text(&self) -> &SmolStr { 183 pub fn text(&self) -> &SmolStr {
188 &self.syntax().leaf_text().unwrap() 184 &self.syntax().leaf_text().unwrap()
189 } 185 }
190} 186}
191 187
192impl<'a> Comment<'a> { 188impl Comment {
193 pub fn text(&self) -> &SmolStr { 189 pub fn text(&self) -> &SmolStr {
194 self.syntax().leaf_text().unwrap() 190 self.syntax().leaf_text().unwrap()
195 } 191 }
@@ -251,7 +247,7 @@ impl CommentFlavor {
251 } 247 }
252} 248}
253 249
254impl<'a> Whitespace<'a> { 250impl Whitespace {
255 pub fn text(&self) -> &SmolStr { 251 pub fn text(&self) -> &SmolStr {
256 &self.syntax().leaf_text().unwrap() 252 &self.syntax().leaf_text().unwrap()
257 } 253 }
@@ -265,36 +261,36 @@ impl<'a> Whitespace<'a> {
265 } 261 }
266} 262}
267 263
268impl<'a> Name<'a> { 264impl Name {
269 pub fn text(&self) -> SmolStr { 265 pub fn text(&self) -> SmolStr {
270 let ident = self.syntax().first_child().unwrap(); 266 let ident = self.syntax().first_child().unwrap();
271 ident.leaf_text().unwrap().clone() 267 ident.leaf_text().unwrap().clone()
272 } 268 }
273} 269}
274 270
275impl<'a> NameRef<'a> { 271impl NameRef {
276 pub fn text(&self) -> SmolStr { 272 pub fn text(&self) -> SmolStr {
277 let ident = self.syntax().first_child().unwrap(); 273 let ident = self.syntax().first_child().unwrap();
278 ident.leaf_text().unwrap().clone() 274 ident.leaf_text().unwrap().clone()
279 } 275 }
280} 276}
281 277
282impl<'a> ImplBlock<'a> { 278impl ImplBlock {
283 pub fn target_type(self) -> Option<TypeRef<'a>> { 279 pub fn target_type(&self) -> Option<&TypeRef> {
284 match self.target() { 280 match self.target() {
285 (Some(t), None) | (_, Some(t)) => Some(t), 281 (Some(t), None) | (_, Some(t)) => Some(t),
286 _ => None, 282 _ => None,
287 } 283 }
288 } 284 }
289 285
290 pub fn target_trait(self) -> Option<TypeRef<'a>> { 286 pub fn target_trait(&self) -> Option<&TypeRef> {
291 match self.target() { 287 match self.target() {
292 (Some(t), Some(_)) => Some(t), 288 (Some(t), Some(_)) => Some(t),
293 _ => None, 289 _ => None,
294 } 290 }
295 } 291 }
296 292
297 fn target(self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) { 293 fn target(&self) -> (Option<&TypeRef>, Option<&TypeRef>) {
298 let mut types = children(self); 294 let mut types = children(self);
299 let first = types.next(); 295 let first = types.next();
300 let second = types.next(); 296 let second = types.next();
@@ -302,8 +298,8 @@ impl<'a> ImplBlock<'a> {
302 } 298 }
303} 299}
304 300
305impl<'a> Module<'a> { 301impl Module {
306 pub fn has_semi(self) -> bool { 302 pub fn has_semi(&self) -> bool {
307 match self.syntax().last_child() { 303 match self.syntax().last_child() {
308 None => false, 304 None => false,
309 Some(node) => node.kind() == SEMI, 305 Some(node) => node.kind() == SEMI,
@@ -311,8 +307,8 @@ impl<'a> Module<'a> {
311 } 307 }
312} 308}
313 309
314impl<'a> LetStmt<'a> { 310impl LetStmt {
315 pub fn has_semi(self) -> bool { 311 pub fn has_semi(&self) -> bool {
316 match self.syntax().last_child() { 312 match self.syntax().last_child() {
317 None => false, 313 None => false,
318 Some(node) => node.kind() == SEMI, 314 Some(node) => node.kind() == SEMI,
@@ -320,35 +316,35 @@ impl<'a> LetStmt<'a> {
320 } 316 }
321} 317}
322 318
323impl<'a> IfExpr<'a> { 319impl IfExpr {
324 pub fn then_branch(self) -> Option<Block<'a>> { 320 pub fn then_branch(&self) -> Option<&Block> {
325 self.blocks().nth(0) 321 self.blocks().nth(0)
326 } 322 }
327 pub fn else_branch(self) -> Option<Block<'a>> { 323 pub fn else_branch(&self) -> Option<&Block> {
328 self.blocks().nth(1) 324 self.blocks().nth(1)
329 } 325 }
330 fn blocks(self) -> AstChildren<'a, Block<'a>> { 326 fn blocks(&self) -> AstChildren<Block> {
331 children(self) 327 children(self)
332 } 328 }
333} 329}
334 330
335#[derive(Debug, Clone, Copy, PartialEq, Eq)] 331#[derive(Debug, Clone, Copy, PartialEq, Eq)]
336pub enum PathSegmentKind<'a> { 332pub enum PathSegmentKind<'a> {
337 Name(NameRef<'a>), 333 Name(&'a NameRef),
338 SelfKw, 334 SelfKw,
339 SuperKw, 335 SuperKw,
340 CrateKw, 336 CrateKw,
341} 337}
342 338
343impl<'a> PathSegment<'a> { 339impl PathSegment {
344 pub fn parent_path(self) -> Path<'a> { 340 pub fn parent_path(&self) -> &Path {
345 self.syntax() 341 self.syntax()
346 .parent() 342 .parent()
347 .and_then(Path::cast) 343 .and_then(Path::cast)
348 .expect("segments are always nested in paths") 344 .expect("segments are always nested in paths")
349 } 345 }
350 346
351 pub fn kind(self) -> Option<PathSegmentKind<'a>> { 347 pub fn kind(&self) -> Option<PathSegmentKind> {
352 let res = if let Some(name_ref) = self.name_ref() { 348 let res = if let Some(name_ref) = self.name_ref() {
353 PathSegmentKind::Name(name_ref) 349 PathSegmentKind::Name(name_ref)
354 } else { 350 } else {
@@ -363,20 +359,20 @@ impl<'a> PathSegment<'a> {
363 } 359 }
364} 360}
365 361
366impl<'a> Path<'a> { 362impl Path {
367 pub fn parent_path(self) -> Option<Path<'a>> { 363 pub fn parent_path(&self) -> Option<&Path> {
368 self.syntax().parent().and_then(Path::cast) 364 self.syntax().parent().and_then(Path::cast)
369 } 365 }
370} 366}
371 367
372impl<'a> UseTree<'a> { 368impl UseTree {
373 pub fn has_star(self) -> bool { 369 pub fn has_star(&self) -> bool {
374 self.syntax().children().any(|it| it.kind() == STAR) 370 self.syntax().children().any(|it| it.kind() == STAR)
375 } 371 }
376} 372}
377 373
378impl<'a> UseTreeList<'a> { 374impl UseTreeList {
379 pub fn parent_use_tree(self) -> UseTree<'a> { 375 pub fn parent_use_tree(&self) -> &UseTree {
380 self.syntax() 376 self.syntax()
381 .parent() 377 .parent()
382 .and_then(UseTree::cast) 378 .and_then(UseTree::cast)
@@ -384,22 +380,22 @@ impl<'a> UseTreeList<'a> {
384 } 380 }
385} 381}
386 382
387fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { 383fn child_opt<P: AstNode, C: AstNode>(parent: &P) -> Option<&C> {
388 children(parent).next() 384 children(parent).next()
389} 385}
390 386
391fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> { 387fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> {
392 AstChildren::new(parent.syntax()) 388 AstChildren::new(parent.syntax())
393} 389}
394 390
395#[derive(Debug)] 391#[derive(Debug)]
396pub struct AstChildren<'a, N> { 392pub struct AstChildren<'a, N> {
397 inner: SyntaxNodeChildren<RefRoot<'a>>, 393 inner: SyntaxNodeChildren<'a>,
398 ph: PhantomData<N>, 394 ph: PhantomData<N>,
399} 395}
400 396
401impl<'a, N> AstChildren<'a, N> { 397impl<'a, N> AstChildren<'a, N> {
402 fn new(parent: SyntaxNodeRef<'a>) -> Self { 398 fn new(parent: &'a SyntaxNode) -> Self {
403 AstChildren { 399 AstChildren {
404 inner: parent.children(), 400 inner: parent.children(),
405 ph: PhantomData, 401 ph: PhantomData,
@@ -407,9 +403,9 @@ impl<'a, N> AstChildren<'a, N> {
407 } 403 }
408} 404}
409 405
410impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { 406impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> {
411 type Item = N; 407 type Item = &'a N;
412 fn next(&mut self) -> Option<N> { 408 fn next(&mut self) -> Option<&'a N> {
413 loop { 409 loop {
414 if let Some(n) = N::cast(self.inner.next()?) { 410 if let Some(n) = N::cast(self.inner.next()?) {
415 return Some(n); 411 return Some(n);
@@ -420,13 +416,13 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> {
420 416
421#[derive(Debug, Clone, PartialEq, Eq)] 417#[derive(Debug, Clone, PartialEq, Eq)]
422pub enum StructFlavor<'a> { 418pub enum StructFlavor<'a> {
423 Tuple(PosFieldList<'a>), 419 Tuple(&'a PosFieldList),
424 Named(NamedFieldDefList<'a>), 420 Named(&'a NamedFieldDefList),
425 Unit, 421 Unit,
426} 422}
427 423
428impl<'a> StructFlavor<'a> { 424impl StructFlavor<'_> {
429 fn from_node<N: AstNode<'a>>(node: N) -> StructFlavor<'a> { 425 fn from_node<N: AstNode>(node: &N) -> StructFlavor {
430 if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { 426 if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) {
431 StructFlavor::Named(nfdl) 427 StructFlavor::Named(nfdl)
432 } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { 428 } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) {
@@ -437,31 +433,31 @@ impl<'a> StructFlavor<'a> {
437 } 433 }
438} 434}
439 435
440impl<'a> StructDef<'a> { 436impl StructDef {
441 pub fn flavor(self) -> StructFlavor<'a> { 437 pub fn flavor(&self) -> StructFlavor {
442 StructFlavor::from_node(self) 438 StructFlavor::from_node(self)
443 } 439 }
444} 440}
445 441
446impl<'a> EnumVariant<'a> { 442impl EnumVariant {
447 pub fn flavor(self) -> StructFlavor<'a> { 443 pub fn flavor(&self) -> StructFlavor {
448 StructFlavor::from_node(self) 444 StructFlavor::from_node(self)
449 } 445 }
450} 446}
451 447
452impl<'a> PointerType<'a> { 448impl PointerType {
453 pub fn is_mut(&self) -> bool { 449 pub fn is_mut(&self) -> bool {
454 self.syntax().children().any(|n| n.kind() == MUT_KW) 450 self.syntax().children().any(|n| n.kind() == MUT_KW)
455 } 451 }
456} 452}
457 453
458impl<'a> ReferenceType<'a> { 454impl ReferenceType {
459 pub fn is_mut(&self) -> bool { 455 pub fn is_mut(&self) -> bool {
460 self.syntax().children().any(|n| n.kind() == MUT_KW) 456 self.syntax().children().any(|n| n.kind() == MUT_KW)
461 } 457 }
462} 458}
463 459
464impl<'a> RefExpr<'a> { 460impl RefExpr {
465 pub fn is_mut(&self) -> bool { 461 pub fn is_mut(&self) -> bool {
466 self.syntax().children().any(|n| n.kind() == MUT_KW) 462 self.syntax().children().any(|n| n.kind() == MUT_KW)
467 } 463 }
@@ -477,7 +473,7 @@ pub enum PrefixOp {
477 Neg, 473 Neg,
478} 474}
479 475
480impl<'a> PrefixExpr<'a> { 476impl PrefixExpr {
481 pub fn op(&self) -> Option<PrefixOp> { 477 pub fn op(&self) -> Option<PrefixOp> {
482 match self.syntax().first_child()?.kind() { 478 match self.syntax().first_child()?.kind() {
483 STAR => Some(PrefixOp::Deref), 479 STAR => Some(PrefixOp::Deref),
@@ -552,7 +548,7 @@ pub enum BinOp {
552 BitXorAssign, 548 BitXorAssign,
553} 549}
554 550
555impl<'a> BinExpr<'a> { 551impl BinExpr {
556 pub fn op(&self) -> Option<BinOp> { 552 pub fn op(&self) -> Option<BinOp> {
557 self.syntax() 553 self.syntax()
558 .children() 554 .children()
@@ -592,15 +588,15 @@ impl<'a> BinExpr<'a> {
592 .next() 588 .next()
593 } 589 }
594 590
595 pub fn lhs(self) -> Option<Expr<'a>> { 591 pub fn lhs(&self) -> Option<&Expr> {
596 children(self).nth(0) 592 children(self).nth(0)
597 } 593 }
598 594
599 pub fn rhs(self) -> Option<Expr<'a>> { 595 pub fn rhs(&self) -> Option<&Expr> {
600 children(self).nth(1) 596 children(self).nth(1)
601 } 597 }
602 598
603 pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) { 599 pub fn sub_exprs(&self) -> (Option<&Expr>, Option<&Expr>) {
604 let mut children = children(self); 600 let mut children = children(self);
605 let first = children.next(); 601 let first = children.next();
606 let second = children.next(); 602 let second = children.next();
@@ -618,7 +614,7 @@ pub enum SelfParamFlavor {
618 MutRef, 614 MutRef,
619} 615}
620 616
621impl<'a> SelfParam<'a> { 617impl SelfParam {
622 pub fn flavor(&self) -> SelfParamFlavor { 618 pub fn flavor(&self) -> SelfParamFlavor {
623 let borrowed = self.syntax().children().any(|n| n.kind() == AMP); 619 let borrowed = self.syntax().children().any(|n| n.kind() == AMP);
624 if borrowed { 620 if borrowed {
@@ -641,7 +637,7 @@ impl<'a> SelfParam<'a> {
641 637
642#[test] 638#[test]
643fn test_doc_comment_of_items() { 639fn test_doc_comment_of_items() {
644 let file = SourceFileNode::parse( 640 let file = SourceFile::parse(
645 r#" 641 r#"
646 //! doc 642 //! doc
647 // non-doc 643 // non-doc
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 24f72393a..5e96ab142 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -9,4648 +9,3387 @@
9 9
10#![cfg_attr(rustfmt, rustfmt_skip)] 10#![cfg_attr(rustfmt, rustfmt_skip)]
11 11
12use std::hash::{Hash, Hasher}; 12use rowan::TransparentNewType;
13 13
14use crate::{ 14use 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)]
23pub struct ArgListNode<R: TreeRoot<RaTypes> = OwnedRoot> { 22#[repr(transparent)]
24 pub(crate) syntax: SyntaxNode<R>, 23pub struct ArgList {
24 pub(crate) syntax: SyntaxNode,
25} 25}
26pub type ArgList<'a> = ArgListNode<RefRoot<'a>>; 26unsafe impl TransparentNewType for ArgList {
27 27 type Repr = rowan::SyntaxNode<RaTypes>;
28impl<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}
31impl<R: TreeRoot<RaTypes>> Eq for ArgListNode<R> {}
32impl<R: TreeRoot<RaTypes>> Hash for ArgListNode<R> {
33 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
34} 28}
35 29
36impl<'a> AstNode<'a> for ArgList<'a> { 30impl 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
46impl<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
56impl<'a> ArgList<'a> { 42impl 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)]
64pub struct ArrayExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 50#[repr(transparent)]
65 pub(crate) syntax: SyntaxNode<R>, 51pub struct ArrayExpr {
52 pub(crate) syntax: SyntaxNode,
66} 53}
67pub type ArrayExpr<'a> = ArrayExprNode<RefRoot<'a>>; 54unsafe impl TransparentNewType for ArrayExpr {
68 55 type Repr = rowan::SyntaxNode<RaTypes>;
69impl<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}
72impl<R: TreeRoot<RaTypes>> Eq for ArrayExprNode<R> {}
73impl<R: TreeRoot<RaTypes>> Hash for ArrayExprNode<R> {
74 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
75} 56}
76 57
77impl<'a> AstNode<'a> for ArrayExpr<'a> { 58impl 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
87impl<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
97impl<'a> ArrayExpr<'a> {} 70impl ArrayExpr {}
98 71
99// ArrayType 72// ArrayType
100#[derive(Debug, Clone, Copy,)] 73#[derive(Debug, PartialEq, Eq, Hash)]
101pub struct ArrayTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { 74#[repr(transparent)]
102 pub(crate) syntax: SyntaxNode<R>, 75pub struct ArrayType {
103} 76 pub(crate) syntax: SyntaxNode,
104pub type ArrayType<'a> = ArrayTypeNode<RefRoot<'a>>;
105
106impl<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}
109impl<R: TreeRoot<RaTypes>> Eq for ArrayTypeNode<R> {} 78unsafe impl TransparentNewType for ArrayType {
110impl<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
114impl<'a> AstNode<'a> for ArrayType<'a> { 82impl 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
124impl<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 94impl ArrayType {
134impl<'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)]
146pub struct AttrNode<R: TreeRoot<RaTypes> = OwnedRoot> { 106#[repr(transparent)]
147 pub(crate) syntax: SyntaxNode<R>, 107pub struct Attr {
148} 108 pub(crate) syntax: SyntaxNode,
149pub type Attr<'a> = AttrNode<RefRoot<'a>>;
150
151impl<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}
154impl<R: TreeRoot<RaTypes>> Eq for AttrNode<R> {} 110unsafe impl TransparentNewType for Attr {
155impl<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
159impl<'a> AstNode<'a> for Attr<'a> { 114impl 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
169impl<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
179impl<'a> Attr<'a> { 126impl 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)]
187pub struct BinExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 134#[repr(transparent)]
188 pub(crate) syntax: SyntaxNode<R>, 135pub struct BinExpr {
189} 136 pub(crate) syntax: SyntaxNode,
190pub type BinExpr<'a> = BinExprNode<RefRoot<'a>>;
191
192impl<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}
195impl<R: TreeRoot<RaTypes>> Eq for BinExprNode<R> {} 138unsafe impl TransparentNewType for BinExpr {
196impl<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
200impl<'a> AstNode<'a> for BinExpr<'a> { 142impl 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
210impl<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
220impl<'a> BinExpr<'a> {} 154impl BinExpr {}
221 155
222// BindPat 156// BindPat
223#[derive(Debug, Clone, Copy,)] 157#[derive(Debug, PartialEq, Eq, Hash)]
224pub struct BindPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { 158#[repr(transparent)]
225 pub(crate) syntax: SyntaxNode<R>, 159pub struct BindPat {
160 pub(crate) syntax: SyntaxNode,
226} 161}
227pub type BindPat<'a> = BindPatNode<RefRoot<'a>>; 162unsafe impl TransparentNewType for BindPat {
228 163 type Repr = rowan::SyntaxNode<RaTypes>;
229impl<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}
232impl<R: TreeRoot<RaTypes>> Eq for BindPatNode<R> {}
233impl<R: TreeRoot<RaTypes>> Hash for BindPatNode<R> {
234 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
235} 164}
236 165
237impl<'a> AstNode<'a> for BindPat<'a> { 166impl 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
247impl<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
257impl<'a> ast::NameOwner<'a> for BindPat<'a> {} 178impl ast::NameOwner for BindPat {}
258impl<'a> BindPat<'a> {} 179impl BindPat {}
259 180
260// Block 181// Block
261#[derive(Debug, Clone, Copy,)] 182#[derive(Debug, PartialEq, Eq, Hash)]
262pub struct BlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { 183#[repr(transparent)]
263 pub(crate) syntax: SyntaxNode<R>, 184pub struct Block {
264} 185 pub(crate) syntax: SyntaxNode,
265pub type Block<'a> = BlockNode<RefRoot<'a>>;
266
267impl<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}
270impl<R: TreeRoot<RaTypes>> Eq for BlockNode<R> {} 187unsafe impl TransparentNewType for Block {
271impl<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
275impl<'a> AstNode<'a> for Block<'a> { 191impl 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
285impl<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 203impl Block {
295impl<'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)]
307pub struct BlockExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 215#[repr(transparent)]
308 pub(crate) syntax: SyntaxNode<R>, 216pub struct BlockExpr {
217 pub(crate) syntax: SyntaxNode,
309} 218}
310pub type BlockExpr<'a> = BlockExprNode<RefRoot<'a>>; 219unsafe impl TransparentNewType for BlockExpr {
311 220 type Repr = rowan::SyntaxNode<RaTypes>;
312impl<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}
315impl<R: TreeRoot<RaTypes>> Eq for BlockExprNode<R> {}
316impl<R: TreeRoot<RaTypes>> Hash for BlockExprNode<R> {
317 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
318} 221}
319 222
320impl<'a> AstNode<'a> for BlockExpr<'a> { 223impl 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
330impl<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
340impl<'a> BlockExpr<'a> { 235impl 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)]
348pub struct BreakExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 243#[repr(transparent)]
349 pub(crate) syntax: SyntaxNode<R>, 244pub struct BreakExpr {
245 pub(crate) syntax: SyntaxNode,
350} 246}
351pub type BreakExpr<'a> = BreakExprNode<RefRoot<'a>>; 247unsafe impl TransparentNewType for BreakExpr {
352 248 type Repr = rowan::SyntaxNode<RaTypes>;
353impl<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}
356impl<R: TreeRoot<RaTypes>> Eq for BreakExprNode<R> {}
357impl<R: TreeRoot<RaTypes>> Hash for BreakExprNode<R> {
358 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
359} 249}
360 250
361impl<'a> AstNode<'a> for BreakExpr<'a> { 251impl 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
371impl<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
381impl<'a> BreakExpr<'a> { 263impl 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)]
389pub struct ByteNode<R: TreeRoot<RaTypes> = OwnedRoot> { 271#[repr(transparent)]
390 pub(crate) syntax: SyntaxNode<R>, 272pub struct Byte {
273 pub(crate) syntax: SyntaxNode,
391} 274}
392pub type Byte<'a> = ByteNode<RefRoot<'a>>; 275unsafe impl TransparentNewType for Byte {
393 276 type Repr = rowan::SyntaxNode<RaTypes>;
394impl<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}
397impl<R: TreeRoot<RaTypes>> Eq for ByteNode<R> {}
398impl<R: TreeRoot<RaTypes>> Hash for ByteNode<R> {
399 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
400} 277}
401 278
402impl<'a> AstNode<'a> for Byte<'a> { 279impl 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
412impl<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
422impl<'a> Byte<'a> {} 291impl Byte {}
423 292
424// ByteString 293// ByteString
425#[derive(Debug, Clone, Copy,)] 294#[derive(Debug, PartialEq, Eq, Hash)]
426pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> { 295#[repr(transparent)]
427 pub(crate) syntax: SyntaxNode<R>, 296pub struct ByteString {
428} 297 pub(crate) syntax: SyntaxNode,
429pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>;
430
431impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteStringNode<R1>> for ByteStringNode<R2> {
432 fn eq(&self, other: &ByteStringNode<R1>) -> bool { self.syntax == other.syntax }
433} 298}
434impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {} 299unsafe impl TransparentNewType for ByteString {
435impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> { 300 type Repr = rowan::SyntaxNode<RaTypes>;
436 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
437} 301}
438 302
439impl<'a> AstNode<'a> for ByteString<'a> { 303impl AstNode for ByteString {
440 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 304 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
441 match syntax.kind() { 305 match syntax.kind() {
442 BYTE_STRING => Some(ByteString { syntax }), 306 BYTE_STRING => Some(ByteString::from_repr(syntax.into_repr())),
443 _ => None, 307 _ => None,
444 } 308 }
445 } 309 }
446 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 310 fn syntax(&self) -> &SyntaxNode { &self.syntax }
447} 311 fn to_owned(&self) -> TreePtr<ByteString> { TreePtr::cast(self.syntax.to_owned()) }
448
449impl<R: TreeRoot<RaTypes>> ByteStringNode<R> {
450 pub fn borrowed(&self) -> ByteString {
451 ByteStringNode { syntax: self.syntax.borrowed() }
452 }
453 pub fn owned(&self) -> ByteStringNode {
454 ByteStringNode { syntax: self.syntax.owned() }
455 }
456} 312}
457 313
458 314
459impl<'a> ByteString<'a> {} 315impl ByteString {}
460 316
461// CallExpr 317// CallExpr
462#[derive(Debug, Clone, Copy,)] 318#[derive(Debug, PartialEq, Eq, Hash)]
463pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 319#[repr(transparent)]
464 pub(crate) syntax: SyntaxNode<R>, 320pub struct CallExpr {
465} 321 pub(crate) syntax: SyntaxNode,
466pub type CallExpr<'a> = CallExprNode<RefRoot<'a>>;
467
468impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CallExprNode<R1>> for CallExprNode<R2> {
469 fn eq(&self, other: &CallExprNode<R1>) -> bool { self.syntax == other.syntax }
470} 322}
471impl<R: TreeRoot<RaTypes>> Eq for CallExprNode<R> {} 323unsafe impl TransparentNewType for CallExpr {
472impl<R: TreeRoot<RaTypes>> Hash for CallExprNode<R> { 324 type Repr = rowan::SyntaxNode<RaTypes>;
473 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
474} 325}
475 326
476impl<'a> AstNode<'a> for CallExpr<'a> { 327impl AstNode for CallExpr {
477 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 328 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
478 match syntax.kind() { 329 match syntax.kind() {
479 CALL_EXPR => Some(CallExpr { syntax }), 330 CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())),
480 _ => None, 331 _ => None,
481 } 332 }
482 } 333 }
483 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 334 fn syntax(&self) -> &SyntaxNode { &self.syntax }
484} 335 fn to_owned(&self) -> TreePtr<CallExpr> { TreePtr::cast(self.syntax.to_owned()) }
485
486impl<R: TreeRoot<RaTypes>> CallExprNode<R> {
487 pub fn borrowed(&self) -> CallExpr {
488 CallExprNode { syntax: self.syntax.borrowed() }
489 }
490 pub fn owned(&self) -> CallExprNode {
491 CallExprNode { syntax: self.syntax.owned() }
492 }
493} 336}
494 337
495 338
496impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} 339impl ast::ArgListOwner for CallExpr {}
497impl<'a> CallExpr<'a> { 340impl CallExpr {
498 pub fn expr(self) -> Option<Expr<'a>> { 341 pub fn expr(&self) -> Option<&Expr> {
499 super::child_opt(self) 342 super::child_opt(self)
500 } 343 }
501} 344}
502 345
503// CastExpr 346// CastExpr
504#[derive(Debug, Clone, Copy,)] 347#[derive(Debug, PartialEq, Eq, Hash)]
505pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 348#[repr(transparent)]
506 pub(crate) syntax: SyntaxNode<R>, 349pub struct CastExpr {
350 pub(crate) syntax: SyntaxNode,
507} 351}
508pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; 352unsafe impl TransparentNewType for CastExpr {
509 353 type Repr = rowan::SyntaxNode<RaTypes>;
510impl<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}
513impl<R: TreeRoot<RaTypes>> Eq for CastExprNode<R> {}
514impl<R: TreeRoot<RaTypes>> Hash for CastExprNode<R> {
515 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
516} 354}
517 355
518impl<'a> AstNode<'a> for CastExpr<'a> { 356impl AstNode for CastExpr {
519 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 357 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
520 match syntax.kind() { 358 match syntax.kind() {
521 CAST_EXPR => Some(CastExpr { syntax }), 359 CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())),
522 _ => None, 360 _ => None,
523 } 361 }
524 } 362 }
525 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 363 fn syntax(&self) -> &SyntaxNode { &self.syntax }
526} 364 fn to_owned(&self) -> TreePtr<CastExpr> { TreePtr::cast(self.syntax.to_owned()) }
527
528impl<R: TreeRoot<RaTypes>> CastExprNode<R> {
529 pub fn borrowed(&self) -> CastExpr {
530 CastExprNode { syntax: self.syntax.borrowed() }
531 }
532 pub fn owned(&self) -> CastExprNode {
533 CastExprNode { syntax: self.syntax.owned() }
534 }
535} 365}
536 366
537 367
538impl<'a> CastExpr<'a> { 368impl CastExpr {
539 pub fn expr(self) -> Option<Expr<'a>> { 369 pub fn expr(&self) -> Option<&Expr> {
540 super::child_opt(self) 370 super::child_opt(self)
541 } 371 }
542 372
543 pub fn type_ref(self) -> Option<TypeRef<'a>> { 373 pub fn type_ref(&self) -> Option<&TypeRef> {
544 super::child_opt(self) 374 super::child_opt(self)
545 } 375 }
546} 376}
547 377