diff options
-rw-r--r-- | Cargo.lock | 115 | ||||
-rw-r--r-- | Cargo.toml | 12 | ||||
-rw-r--r-- | crates/assists/src/handlers/fix_visibility.rs | 10 | ||||
-rw-r--r-- | crates/hir/src/semantics/source_to_def.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/adt.rs | 28 | ||||
-rw-r--r-- | crates/hir_ty/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/ide/src/completion/complete_postfix/format_like.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/ide/src/references.rs | 88 | ||||
-rw-r--r-- | crates/ide/src/references/rename.rs | 175 | ||||
-rw-r--r-- | crates/ide_db/src/search.rs | 116 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/proc_macro/bridge/client.rs | 1 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/proc_macro/bridge/mod.rs | 4 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/proc_macro/bridge/server.rs | 2 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/proc_macro/mod.rs | 22 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/rustc_server.rs | 10 | ||||
-rw-r--r-- | crates/profile/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/project_model/src/sysroot.rs | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 17 | ||||
-rw-r--r-- | crates/syntax/Cargo.toml | 2 | ||||
-rw-r--r-- | xtask/src/install.rs | 2 | ||||
-rw-r--r-- | xtask/tests/tidy.rs | 1 |
22 files changed, 442 insertions, 193 deletions
diff --git a/Cargo.lock b/Cargo.lock index a1786d201..fdb62e6ea 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -26,9 +26,9 @@ dependencies = [ | |||
26 | 26 | ||
27 | [[package]] | 27 | [[package]] |
28 | name = "anyhow" | 28 | name = "anyhow" |
29 | version = "1.0.32" | 29 | version = "1.0.33" |
30 | source = "registry+https://github.com/rust-lang/crates.io-index" | 30 | source = "registry+https://github.com/rust-lang/crates.io-index" |
31 | checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" | 31 | checksum = "a1fd36ffbb1fb7c834eac128ea8d0e310c5aeb635548f9d58861e1308d46e71c" |
32 | 32 | ||
33 | [[package]] | 33 | [[package]] |
34 | name = "anymap" | 34 | name = "anymap" |
@@ -82,12 +82,12 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" | |||
82 | 82 | ||
83 | [[package]] | 83 | [[package]] |
84 | name = "backtrace" | 84 | name = "backtrace" |
85 | version = "0.3.51" | 85 | version = "0.3.53" |
86 | source = "registry+https://github.com/rust-lang/crates.io-index" | 86 | source = "registry+https://github.com/rust-lang/crates.io-index" |
87 | checksum = "ec1931848a574faa8f7c71a12ea00453ff5effbb5f51afe7f77d7a48cace6ac1" | 87 | checksum = "707b586e0e2f247cbde68cdd2c3ce69ea7b7be43e1c5b426e37c9319c4b9838e" |
88 | dependencies = [ | 88 | dependencies = [ |
89 | "addr2line", | 89 | "addr2line", |
90 | "cfg-if", | 90 | "cfg-if 1.0.0", |
91 | "libc", | 91 | "libc", |
92 | "miniz_oxide", | 92 | "miniz_oxide", |
93 | "object", | 93 | "object", |
@@ -140,9 +140,9 @@ dependencies = [ | |||
140 | 140 | ||
141 | [[package]] | 141 | [[package]] |
142 | name = "cc" | 142 | name = "cc" |
143 | version = "1.0.60" | 143 | version = "1.0.61" |
144 | source = "registry+https://github.com/rust-lang/crates.io-index" | 144 | source = "registry+https://github.com/rust-lang/crates.io-index" |
145 | checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c" | 145 | checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" |
146 | 146 | ||
147 | [[package]] | 147 | [[package]] |
148 | name = "cfg" | 148 | name = "cfg" |
@@ -161,10 +161,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
161 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" | 161 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" |
162 | 162 | ||
163 | [[package]] | 163 | [[package]] |
164 | name = "cfg-if" | ||
165 | version = "1.0.0" | ||
166 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
167 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||
168 | |||
169 | [[package]] | ||
164 | name = "chalk-derive" | 170 | name = "chalk-derive" |
165 | version = "0.32.0" | 171 | version = "0.33.0" |
166 | source = "registry+https://github.com/rust-lang/crates.io-index" | 172 | source = "registry+https://github.com/rust-lang/crates.io-index" |
167 | checksum = "2d072b2ba723f0bada7c515d8b3725224bc4f5052d2a92dcbeb0b118ff37084a" | 173 | checksum = "569014cab9084a6b826fe2507cc6d08f7897ba144fb1bc74e71b593dc8a0b952" |
168 | dependencies = [ | 174 | dependencies = [ |
169 | "proc-macro2", | 175 | "proc-macro2", |
170 | "quote", | 176 | "quote", |
@@ -174,9 +180,9 @@ dependencies = [ | |||
174 | 180 | ||
175 | [[package]] | 181 | [[package]] |
176 | name = "chalk-ir" | 182 | name = "chalk-ir" |
177 | version = "0.32.0" | 183 | version = "0.33.0" |
178 | source = "registry+https://github.com/rust-lang/crates.io-index" | 184 | source = "registry+https://github.com/rust-lang/crates.io-index" |
179 | checksum = "f60cdb0e18c5455cb6a85e8464aad3622b70476018edfa8845691df66f7e9a05" | 185 | checksum = "8d9eab2a6590b696419f89c9ca3616fe8e8266ef676e6a6da8818c94963c9541" |
180 | dependencies = [ | 186 | dependencies = [ |
181 | "chalk-derive", | 187 | "chalk-derive", |
182 | "lazy_static", | 188 | "lazy_static", |
@@ -184,9 +190,9 @@ dependencies = [ | |||
184 | 190 | ||
185 | [[package]] | 191 | [[package]] |
186 | name = "chalk-recursive" | 192 | name = "chalk-recursive" |
187 | version = "0.32.0" | 193 | version = "0.33.0" |
188 | source = "registry+https://github.com/rust-lang/crates.io-index" | 194 | source = "registry+https://github.com/rust-lang/crates.io-index" |
189 | checksum = "b14f40242102e7c0e2791a2cc86dbbc213a1d7b7acc0e22b7da329f4957d1722" | 195 | checksum = "4a4671bcc70aa2d7e12ff4fe03f91d0c3c9ce387de915915e57fdf0c91dc5abd" |
190 | dependencies = [ | 196 | dependencies = [ |
191 | "chalk-derive", | 197 | "chalk-derive", |
192 | "chalk-ir", | 198 | "chalk-ir", |
@@ -197,9 +203,9 @@ dependencies = [ | |||
197 | 203 | ||
198 | [[package]] | 204 | [[package]] |
199 | name = "chalk-solve" | 205 | name = "chalk-solve" |
200 | version = "0.32.0" | 206 | version = "0.33.0" |
201 | source = "registry+https://github.com/rust-lang/crates.io-index" | 207 | source = "registry+https://github.com/rust-lang/crates.io-index" |
202 | checksum = "981534d499a8476ecc0b520be4d3864757f96211826a75360fbf2cb6fae362ab" | 208 | checksum = "45f75cc603f2fd302576c8b2976437f334e159e26d0afbb108a565b96c52184e" |
203 | dependencies = [ | 209 | dependencies = [ |
204 | "chalk-derive", | 210 | "chalk-derive", |
205 | "chalk-ir", | 211 | "chalk-ir", |
@@ -249,7 +255,7 @@ version = "1.2.0" | |||
249 | source = "registry+https://github.com/rust-lang/crates.io-index" | 255 | source = "registry+https://github.com/rust-lang/crates.io-index" |
250 | checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" | 256 | checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" |
251 | dependencies = [ | 257 | dependencies = [ |
252 | "cfg-if", | 258 | "cfg-if 0.1.10", |
253 | ] | 259 | ] |
254 | 260 | ||
255 | [[package]] | 261 | [[package]] |
@@ -280,7 +286,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
280 | checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" | 286 | checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" |
281 | dependencies = [ | 287 | dependencies = [ |
282 | "autocfg", | 288 | "autocfg", |
283 | "cfg-if", | 289 | "cfg-if 0.1.10", |
284 | "crossbeam-utils", | 290 | "crossbeam-utils", |
285 | "lazy_static", | 291 | "lazy_static", |
286 | "maybe-uninit", | 292 | "maybe-uninit", |
@@ -295,7 +301,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
295 | checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" | 301 | checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" |
296 | dependencies = [ | 302 | dependencies = [ |
297 | "autocfg", | 303 | "autocfg", |
298 | "cfg-if", | 304 | "cfg-if 0.1.10", |
299 | "lazy_static", | 305 | "lazy_static", |
300 | ] | 306 | ] |
301 | 307 | ||
@@ -351,7 +357,7 @@ version = "0.2.12" | |||
351 | source = "registry+https://github.com/rust-lang/crates.io-index" | 357 | source = "registry+https://github.com/rust-lang/crates.io-index" |
352 | checksum = "3ed85775dcc68644b5c950ac06a2b23768d3bc9390464151aaf27136998dcf9e" | 358 | checksum = "3ed85775dcc68644b5c950ac06a2b23768d3bc9390464151aaf27136998dcf9e" |
353 | dependencies = [ | 359 | dependencies = [ |
354 | "cfg-if", | 360 | "cfg-if 0.1.10", |
355 | "libc", | 361 | "libc", |
356 | "redox_syscall", | 362 | "redox_syscall", |
357 | "winapi 0.3.9", | 363 | "winapi 0.3.9", |
@@ -369,7 +375,7 @@ version = "1.0.18" | |||
369 | source = "registry+https://github.com/rust-lang/crates.io-index" | 375 | source = "registry+https://github.com/rust-lang/crates.io-index" |
370 | checksum = "da80be589a72651dcda34d8b35bcdc9b7254ad06325611074d9cc0fbb19f60ee" | 376 | checksum = "da80be589a72651dcda34d8b35bcdc9b7254ad06325611074d9cc0fbb19f60ee" |
371 | dependencies = [ | 377 | dependencies = [ |
372 | "cfg-if", | 378 | "cfg-if 0.1.10", |
373 | "crc32fast", | 379 | "crc32fast", |
374 | "libc", | 380 | "libc", |
375 | "miniz_oxide", | 381 | "miniz_oxide", |
@@ -468,9 +474,9 @@ dependencies = [ | |||
468 | 474 | ||
469 | [[package]] | 475 | [[package]] |
470 | name = "hermit-abi" | 476 | name = "hermit-abi" |
471 | version = "0.1.16" | 477 | version = "0.1.17" |
472 | source = "registry+https://github.com/rust-lang/crates.io-index" | 478 | source = "registry+https://github.com/rust-lang/crates.io-index" |
473 | checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151" | 479 | checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" |
474 | dependencies = [ | 480 | dependencies = [ |
475 | "libc", | 481 | "libc", |
476 | ] | 482 | ] |
@@ -668,7 +674,7 @@ version = "0.1.7" | |||
668 | source = "registry+https://github.com/rust-lang/crates.io-index" | 674 | source = "registry+https://github.com/rust-lang/crates.io-index" |
669 | checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66" | 675 | checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66" |
670 | dependencies = [ | 676 | dependencies = [ |
671 | "cfg-if", | 677 | "cfg-if 0.1.10", |
672 | ] | 678 | ] |
673 | 679 | ||
674 | [[package]] | 680 | [[package]] |
@@ -725,25 +731,25 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" | |||
725 | 731 | ||
726 | [[package]] | 732 | [[package]] |
727 | name = "libc" | 733 | name = "libc" |
728 | version = "0.2.78" | 734 | version = "0.2.79" |
729 | source = "registry+https://github.com/rust-lang/crates.io-index" | 735 | source = "registry+https://github.com/rust-lang/crates.io-index" |
730 | checksum = "aa7087f49d294270db4e1928fc110c976cd4b9e5a16348e0a1df09afa99e6c98" | 736 | checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" |
731 | 737 | ||
732 | [[package]] | 738 | [[package]] |
733 | name = "libloading" | 739 | name = "libloading" |
734 | version = "0.6.3" | 740 | version = "0.6.4" |
735 | source = "registry+https://github.com/rust-lang/crates.io-index" | 741 | source = "registry+https://github.com/rust-lang/crates.io-index" |
736 | checksum = "2443d8f0478b16759158b2f66d525991a05491138bc05814ef52a250148ef4f9" | 742 | checksum = "3557c9384f7f757f6d139cd3a4c62ef4e850696c16bf27924a5538c8a09717a1" |
737 | dependencies = [ | 743 | dependencies = [ |
738 | "cfg-if", | 744 | "cfg-if 0.1.10", |
739 | "winapi 0.3.9", | 745 | "winapi 0.3.9", |
740 | ] | 746 | ] |
741 | 747 | ||
742 | [[package]] | 748 | [[package]] |
743 | name = "libmimalloc-sys" | 749 | name = "libmimalloc-sys" |
744 | version = "0.1.17" | 750 | version = "0.1.18" |
745 | source = "registry+https://github.com/rust-lang/crates.io-index" | 751 | source = "registry+https://github.com/rust-lang/crates.io-index" |
746 | checksum = "2bd65748dfb74a807e8379fd49bf4d38964d92b8637b56f173f87e1d70433368" | 752 | checksum = "82151ff13433c4d403cb15d0e6fbda14b24d65bd1a5b33f7d52ec983cc00752d" |
747 | dependencies = [ | 753 | dependencies = [ |
748 | "cmake", | 754 | "cmake", |
749 | ] | 755 | ] |
@@ -763,7 +769,7 @@ version = "0.4.11" | |||
763 | source = "registry+https://github.com/rust-lang/crates.io-index" | 769 | source = "registry+https://github.com/rust-lang/crates.io-index" |
764 | checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" | 770 | checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" |
765 | dependencies = [ | 771 | dependencies = [ |
766 | "cfg-if", | 772 | "cfg-if 0.1.10", |
767 | ] | 773 | ] |
768 | 774 | ||
769 | [[package]] | 775 | [[package]] |
@@ -853,18 +859,18 @@ dependencies = [ | |||
853 | 859 | ||
854 | [[package]] | 860 | [[package]] |
855 | name = "mimalloc" | 861 | name = "mimalloc" |
856 | version = "0.1.21" | 862 | version = "0.1.22" |
857 | source = "registry+https://github.com/rust-lang/crates.io-index" | 863 | source = "registry+https://github.com/rust-lang/crates.io-index" |
858 | checksum = "2e18b3d01186c4a7bec0b56cff9a4b9d5a1461aa162c7b8eaf2e5ee10b265b02" | 864 | checksum = "4a5d2c9cb18f9cdc6d88f4aca6d3d8ea89c4c8202d6facfc7e56efdee97b80fa" |
859 | dependencies = [ | 865 | dependencies = [ |
860 | "libmimalloc-sys", | 866 | "libmimalloc-sys", |
861 | ] | 867 | ] |
862 | 868 | ||
863 | [[package]] | 869 | [[package]] |
864 | name = "miniz_oxide" | 870 | name = "miniz_oxide" |
865 | version = "0.4.2" | 871 | version = "0.4.3" |
866 | source = "registry+https://github.com/rust-lang/crates.io-index" | 872 | source = "registry+https://github.com/rust-lang/crates.io-index" |
867 | checksum = "c60c0dfe32c10b43a144bad8fc83538c52f58302c92300ea7ec7bf7b38d5a7b9" | 873 | checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" |
868 | dependencies = [ | 874 | dependencies = [ |
869 | "adler", | 875 | "adler", |
870 | "autocfg", | 876 | "autocfg", |
@@ -876,7 +882,7 @@ version = "0.6.22" | |||
876 | source = "registry+https://github.com/rust-lang/crates.io-index" | 882 | source = "registry+https://github.com/rust-lang/crates.io-index" |
877 | checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" | 883 | checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" |
878 | dependencies = [ | 884 | dependencies = [ |
879 | "cfg-if", | 885 | "cfg-if 0.1.10", |
880 | "fuchsia-zircon", | 886 | "fuchsia-zircon", |
881 | "fuchsia-zircon-sys", | 887 | "fuchsia-zircon-sys", |
882 | "iovec", | 888 | "iovec", |
@@ -919,7 +925,7 @@ version = "0.2.35" | |||
919 | source = "registry+https://github.com/rust-lang/crates.io-index" | 925 | source = "registry+https://github.com/rust-lang/crates.io-index" |
920 | checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" | 926 | checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" |
921 | dependencies = [ | 927 | dependencies = [ |
922 | "cfg-if", | 928 | "cfg-if 0.1.10", |
923 | "libc", | 929 | "libc", |
924 | "winapi 0.3.9", | 930 | "winapi 0.3.9", |
925 | ] | 931 | ] |
@@ -975,9 +981,9 @@ dependencies = [ | |||
975 | 981 | ||
976 | [[package]] | 982 | [[package]] |
977 | name = "object" | 983 | name = "object" |
978 | version = "0.20.0" | 984 | version = "0.21.1" |
979 | source = "registry+https://github.com/rust-lang/crates.io-index" | 985 | source = "registry+https://github.com/rust-lang/crates.io-index" |
980 | checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" | 986 | checksum = "37fd5004feb2ce328a52b0b3d01dbf4ffff72583493900ed15f22d4111c51693" |
981 | 987 | ||
982 | [[package]] | 988 | [[package]] |
983 | name = "once_cell" | 989 | name = "once_cell" |
@@ -1008,7 +1014,7 @@ version = "0.8.0" | |||
1008 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1014 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1009 | checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" | 1015 | checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" |
1010 | dependencies = [ | 1016 | dependencies = [ |
1011 | "cfg-if", | 1017 | "cfg-if 0.1.10", |
1012 | "cloudabi", | 1018 | "cloudabi", |
1013 | "instant", | 1019 | "instant", |
1014 | "libc", | 1020 | "libc", |
@@ -1130,7 +1136,7 @@ version = "0.0.0" | |||
1130 | dependencies = [ | 1136 | dependencies = [ |
1131 | "arena", | 1137 | "arena", |
1132 | "backtrace", | 1138 | "backtrace", |
1133 | "cfg-if", | 1139 | "cfg-if 1.0.0", |
1134 | "libc", | 1140 | "libc", |
1135 | "once_cell", | 1141 | "once_cell", |
1136 | "perf-event", | 1142 | "perf-event", |
@@ -1300,18 +1306,18 @@ dependencies = [ | |||
1300 | 1306 | ||
1301 | [[package]] | 1307 | [[package]] |
1302 | name = "rustc-ap-rustc_lexer" | 1308 | name = "rustc-ap-rustc_lexer" |
1303 | version = "681.0.0" | 1309 | version = "682.0.0" |
1304 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1310 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1305 | checksum = "01e579a90506e9d9c9a098f380cad55b9ecf9e7be9fa96cb67b31f52045f41a8" | 1311 | checksum = "5fea544ba13e72077e363981b0a4a87997b97f772b25a0aa7ec3df35a6adfe82" |
1306 | dependencies = [ | 1312 | dependencies = [ |
1307 | "unicode-xid", | 1313 | "unicode-xid", |
1308 | ] | 1314 | ] |
1309 | 1315 | ||
1310 | [[package]] | 1316 | [[package]] |
1311 | name = "rustc-demangle" | 1317 | name = "rustc-demangle" |
1312 | version = "0.1.16" | 1318 | version = "0.1.17" |
1313 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1319 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1314 | checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" | 1320 | checksum = "b2610b7f643d18c87dff3b489950269617e6601a51f1f05aa5daefee36f64f0b" |
1315 | 1321 | ||
1316 | [[package]] | 1322 | [[package]] |
1317 | name = "rustc-hash" | 1323 | name = "rustc-hash" |
@@ -1377,18 +1383,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" | |||
1377 | 1383 | ||
1378 | [[package]] | 1384 | [[package]] |
1379 | name = "scroll" | 1385 | name = "scroll" |
1380 | version = "0.10.1" | 1386 | version = "0.10.2" |
1381 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1387 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1382 | checksum = "abb2332cb595d33f7edd5700f4cbf94892e680c7f0ae56adab58a35190b66cb1" | 1388 | checksum = "fda28d4b4830b807a8b43f7b0e6b5df875311b3e7621d84577188c175b6ec1ec" |
1383 | dependencies = [ | 1389 | dependencies = [ |
1384 | "scroll_derive", | 1390 | "scroll_derive", |
1385 | ] | 1391 | ] |
1386 | 1392 | ||
1387 | [[package]] | 1393 | [[package]] |
1388 | name = "scroll_derive" | 1394 | name = "scroll_derive" |
1389 | version = "0.10.2" | 1395 | version = "0.10.3" |
1390 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1396 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1391 | checksum = "e367622f934864ffa1c704ba2b82280aab856e3d8213c84c5720257eb34b15b9" | 1397 | checksum = "6dfde5d1531034db129e95c76ac857e2baecea3443579d493d02224950b0fb6d" |
1392 | dependencies = [ | 1398 | dependencies = [ |
1393 | "proc-macro2", | 1399 | "proc-macro2", |
1394 | "quote", | 1400 | "quote", |
@@ -1504,9 +1510,9 @@ version = "0.0.0" | |||
1504 | 1510 | ||
1505 | [[package]] | 1511 | [[package]] |
1506 | name = "syn" | 1512 | name = "syn" |
1507 | version = "1.0.42" | 1513 | version = "1.0.44" |
1508 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1514 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1509 | checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228" | 1515 | checksum = "e03e57e4fcbfe7749842d53e24ccb9aa12b7252dbe5e91d2acad31834c8b8fdd" |
1510 | dependencies = [ | 1516 | dependencies = [ |
1511 | "proc-macro2", | 1517 | "proc-macro2", |
1512 | "quote", | 1518 | "quote", |
@@ -1633,7 +1639,7 @@ version = "0.1.21" | |||
1633 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1639 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1634 | checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" | 1640 | checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" |
1635 | dependencies = [ | 1641 | dependencies = [ |
1636 | "cfg-if", | 1642 | "cfg-if 0.1.10", |
1637 | "pin-project-lite", | 1643 | "pin-project-lite", |
1638 | "tracing-attributes", | 1644 | "tracing-attributes", |
1639 | "tracing-core", | 1645 | "tracing-core", |
@@ -1682,9 +1688,9 @@ dependencies = [ | |||
1682 | 1688 | ||
1683 | [[package]] | 1689 | [[package]] |
1684 | name = "tracing-subscriber" | 1690 | name = "tracing-subscriber" |
1685 | version = "0.2.12" | 1691 | version = "0.2.13" |
1686 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1692 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1687 | checksum = "82bb5079aa76438620837198db8a5c529fb9878c730bc2b28179b0241cf04c10" | 1693 | checksum = "4ef0a5e15477aa303afbfac3a44cba9b6430fdaad52423b1e6c0dbbe28c3eedd" |
1688 | dependencies = [ | 1694 | dependencies = [ |
1689 | "ansi_term", | 1695 | "ansi_term", |
1690 | "chrono", | 1696 | "chrono", |
@@ -1696,6 +1702,7 @@ dependencies = [ | |||
1696 | "sharded-slab", | 1702 | "sharded-slab", |
1697 | "smallvec", | 1703 | "smallvec", |
1698 | "thread_local", | 1704 | "thread_local", |
1705 | "tracing", | ||
1699 | "tracing-core", | 1706 | "tracing-core", |
1700 | "tracing-log", | 1707 | "tracing-log", |
1701 | "tracing-serde", | 1708 | "tracing-serde", |
diff --git a/Cargo.toml b/Cargo.toml index 218581d9d..87d33f06c 100644 --- a/Cargo.toml +++ b/Cargo.toml | |||
@@ -19,18 +19,6 @@ miniz_oxide.opt-level = 3 | |||
19 | incremental = true | 19 | incremental = true |
20 | debug = 0 # Set this to 1 or 2 to get more useful backtraces in debugger. | 20 | debug = 0 # Set this to 1 or 2 to get more useful backtraces in debugger. |
21 | 21 | ||
22 | # Ideally, we would use `build-override` here, but some crates are also | ||
23 | # needed at run-time and we end up compiling them twice. | ||
24 | [profile.release.package] | ||
25 | chalk-derive.opt-level = 0 | ||
26 | proc-macro2.opt-level = 0 | ||
27 | quote.opt-level = 0 | ||
28 | salsa-macros.opt-level = 0 | ||
29 | serde_derive.opt-level = 0 | ||
30 | syn.opt-level = 0 | ||
31 | tracing-attributes.opt-level = 0 | ||
32 | xtask.opt-level = 0 | ||
33 | |||
34 | [patch.'crates-io'] | 22 | [patch.'crates-io'] |
35 | # rowan = { path = "../rowan" } | 23 | # rowan = { path = "../rowan" } |
36 | 24 | ||
diff --git a/crates/assists/src/handlers/fix_visibility.rs b/crates/assists/src/handlers/fix_visibility.rs index 7cd76ea06..d505e9444 100644 --- a/crates/assists/src/handlers/fix_visibility.rs +++ b/crates/assists/src/handlers/fix_visibility.rs | |||
@@ -324,14 +324,14 @@ pub struct Foo { pub bar: () } | |||
324 | 324 | ||
325 | #[test] | 325 | #[test] |
326 | fn fix_visibility_of_enum_variant_field() { | 326 | fn fix_visibility_of_enum_variant_field() { |
327 | check_assist( | 327 | // Enum variants, as well as their fields, always get the enum's visibility. In fact, rustc |
328 | // rejects any visibility specifiers on them, so this assist should never fire on them. | ||
329 | check_assist_not_applicable( | ||
328 | fix_visibility, | 330 | fix_visibility, |
329 | r"mod foo { pub enum Foo { Bar { bar: () } } } | 331 | r"mod foo { pub enum Foo { Bar { bar: () } } } |
330 | fn main() { foo::Foo::Bar { <|>bar: () }; } ", | 332 | fn main() { foo::Foo::Bar { <|>bar: () }; } ", |
331 | r"mod foo { pub enum Foo { Bar { $0pub(crate) bar: () } } } | ||
332 | fn main() { foo::Foo::Bar { bar: () }; } ", | ||
333 | ); | 333 | ); |
334 | check_assist( | 334 | check_assist_not_applicable( |
335 | fix_visibility, | 335 | fix_visibility, |
336 | r" | 336 | r" |
337 | //- /lib.rs | 337 | //- /lib.rs |
@@ -340,8 +340,6 @@ fn main() { foo::Foo::Bar { <|>bar: () }; } | |||
340 | //- /foo.rs | 340 | //- /foo.rs |
341 | pub enum Foo { Bar { bar: () } } | 341 | pub enum Foo { Bar { bar: () } } |
342 | ", | 342 | ", |
343 | r"pub enum Foo { Bar { $0pub(crate) bar: () } } | ||
344 | ", | ||
345 | ); | 343 | ); |
346 | check_assist_not_applicable( | 344 | check_assist_not_applicable( |
347 | fix_visibility, | 345 | fix_visibility, |
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 5918b9541..66fc11611 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs | |||
@@ -189,6 +189,10 @@ impl SourceToDefCtx<'_, '_> { | |||
189 | let def = self.type_alias_to_def(container.with_value(it))?; | 189 | let def = self.type_alias_to_def(container.with_value(it))?; |
190 | def.into() | 190 | def.into() |
191 | }, | 191 | }, |
192 | ast::Variant(it) => { | ||
193 | let def = self.enum_variant_to_def(container.with_value(it))?; | ||
194 | VariantId::from(def).into() | ||
195 | }, | ||
192 | _ => continue, | 196 | _ => continue, |
193 | } | 197 | } |
194 | }; | 198 | }; |
diff --git a/crates/hir_def/src/adt.rs b/crates/hir_def/src/adt.rs index d69ff2fc7..6539959c3 100644 --- a/crates/hir_def/src/adt.rs +++ b/crates/hir_def/src/adt.rs | |||
@@ -14,7 +14,7 @@ use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree}; | |||
14 | use crate::{ | 14 | use crate::{ |
15 | body::{CfgExpander, LowerCtx}, | 15 | body::{CfgExpander, LowerCtx}, |
16 | db::DefDatabase, | 16 | db::DefDatabase, |
17 | item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem}, | 17 | item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem, RawVisibilityId}, |
18 | src::HasChildSource, | 18 | src::HasChildSource, |
19 | src::HasSource, | 19 | src::HasSource, |
20 | trace::Trace, | 20 | trace::Trace, |
@@ -91,7 +91,7 @@ impl StructData { | |||
91 | let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); | 91 | let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); |
92 | 92 | ||
93 | let strukt = &item_tree[loc.id.value]; | 93 | let strukt = &item_tree[loc.id.value]; |
94 | let variant_data = lower_fields(&item_tree, &cfg_options, &strukt.fields); | 94 | let variant_data = lower_fields(&item_tree, &cfg_options, &strukt.fields, None); |
95 | Arc::new(StructData { | 95 | Arc::new(StructData { |
96 | name: strukt.name.clone(), | 96 | name: strukt.name.clone(), |
97 | variant_data: Arc::new(variant_data), | 97 | variant_data: Arc::new(variant_data), |
@@ -105,7 +105,7 @@ impl StructData { | |||
105 | let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); | 105 | let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); |
106 | 106 | ||
107 | let union = &item_tree[loc.id.value]; | 107 | let union = &item_tree[loc.id.value]; |
108 | let variant_data = lower_fields(&item_tree, &cfg_options, &union.fields); | 108 | let variant_data = lower_fields(&item_tree, &cfg_options, &union.fields, None); |
109 | 109 | ||
110 | Arc::new(StructData { | 110 | Arc::new(StructData { |
111 | name: union.name.clone(), | 111 | name: union.name.clone(), |
@@ -126,7 +126,8 @@ impl EnumData { | |||
126 | for var_id in enum_.variants.clone() { | 126 | for var_id in enum_.variants.clone() { |
127 | if item_tree.attrs(var_id.into()).is_cfg_enabled(&cfg_options) { | 127 | if item_tree.attrs(var_id.into()).is_cfg_enabled(&cfg_options) { |
128 | let var = &item_tree[var_id]; | 128 | let var = &item_tree[var_id]; |
129 | let var_data = lower_fields(&item_tree, &cfg_options, &var.fields); | 129 | let var_data = |
130 | lower_fields(&item_tree, &cfg_options, &var.fields, Some(enum_.visibility)); | ||
130 | 131 | ||
131 | variants.alloc(EnumVariantData { | 132 | variants.alloc(EnumVariantData { |
132 | name: var.name.clone(), | 133 | name: var.name.clone(), |
@@ -296,13 +297,18 @@ fn lower_struct( | |||
296 | } | 297 | } |
297 | } | 298 | } |
298 | 299 | ||
299 | fn lower_fields(item_tree: &ItemTree, cfg_options: &CfgOptions, fields: &Fields) -> VariantData { | 300 | fn lower_fields( |
301 | item_tree: &ItemTree, | ||
302 | cfg_options: &CfgOptions, | ||
303 | fields: &Fields, | ||
304 | override_visibility: Option<RawVisibilityId>, | ||
305 | ) -> VariantData { | ||
300 | match fields { | 306 | match fields { |
301 | Fields::Record(flds) => { | 307 | Fields::Record(flds) => { |
302 | let mut arena = Arena::new(); | 308 | let mut arena = Arena::new(); |
303 | for field_id in flds.clone() { | 309 | for field_id in flds.clone() { |
304 | if item_tree.attrs(field_id.into()).is_cfg_enabled(cfg_options) { | 310 | if item_tree.attrs(field_id.into()).is_cfg_enabled(cfg_options) { |
305 | arena.alloc(lower_field(item_tree, &item_tree[field_id])); | 311 | arena.alloc(lower_field(item_tree, &item_tree[field_id], override_visibility)); |
306 | } | 312 | } |
307 | } | 313 | } |
308 | VariantData::Record(arena) | 314 | VariantData::Record(arena) |
@@ -311,7 +317,7 @@ fn lower_fields(item_tree: &ItemTree, cfg_options: &CfgOptions, fields: &Fields) | |||
311 | let mut arena = Arena::new(); | 317 | let mut arena = Arena::new(); |
312 | for field_id in flds.clone() { | 318 | for field_id in flds.clone() { |
313 | if item_tree.attrs(field_id.into()).is_cfg_enabled(cfg_options) { | 319 | if item_tree.attrs(field_id.into()).is_cfg_enabled(cfg_options) { |
314 | arena.alloc(lower_field(item_tree, &item_tree[field_id])); | 320 | arena.alloc(lower_field(item_tree, &item_tree[field_id], override_visibility)); |
315 | } | 321 | } |
316 | } | 322 | } |
317 | VariantData::Tuple(arena) | 323 | VariantData::Tuple(arena) |
@@ -320,10 +326,14 @@ fn lower_fields(item_tree: &ItemTree, cfg_options: &CfgOptions, fields: &Fields) | |||
320 | } | 326 | } |
321 | } | 327 | } |
322 | 328 | ||
323 | fn lower_field(item_tree: &ItemTree, field: &Field) -> FieldData { | 329 | fn lower_field( |
330 | item_tree: &ItemTree, | ||
331 | field: &Field, | ||
332 | override_visibility: Option<RawVisibilityId>, | ||
333 | ) -> FieldData { | ||
324 | FieldData { | 334 | FieldData { |
325 | name: field.name.clone(), | 335 | name: field.name.clone(), |
326 | type_ref: field.type_ref.clone(), | 336 | type_ref: field.type_ref.clone(), |
327 | visibility: item_tree[field.visibility].clone(), | 337 | visibility: item_tree[override_visibility.unwrap_or(field.visibility)].clone(), |
328 | } | 338 | } |
329 | } | 339 | } |
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index 0f3c85926..e9c62c6aa 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml | |||
@@ -17,9 +17,9 @@ ena = "0.14.0" | |||
17 | log = "0.4.8" | 17 | log = "0.4.8" |
18 | rustc-hash = "1.1.0" | 18 | rustc-hash = "1.1.0" |
19 | scoped-tls = "1" | 19 | scoped-tls = "1" |
20 | chalk-solve = "0.32" | 20 | chalk-solve = "0.33" |
21 | chalk-ir = "0.32" | 21 | chalk-ir = "0.33" |
22 | chalk-recursive = "0.32" | 22 | chalk-recursive = "0.33" |
23 | 23 | ||
24 | stdx = { path = "../stdx", version = "0.0.0" } | 24 | stdx = { path = "../stdx", version = "0.0.0" } |
25 | hir_def = { path = "../hir_def", version = "0.0.0" } | 25 | hir_def = { path = "../hir_def", version = "0.0.0" } |
diff --git a/crates/ide/src/completion/complete_postfix/format_like.rs b/crates/ide/src/completion/complete_postfix/format_like.rs index 81c33bf3a..50d1e5c81 100644 --- a/crates/ide/src/completion/complete_postfix/format_like.rs +++ b/crates/ide/src/completion/complete_postfix/format_like.rs | |||
@@ -25,6 +25,7 @@ static KINDS: &[(&str, &str)] = &[ | |||
25 | ("fmt", "format!"), | 25 | ("fmt", "format!"), |
26 | ("panic", "panic!"), | 26 | ("panic", "panic!"), |
27 | ("println", "println!"), | 27 | ("println", "println!"), |
28 | ("eprintln", "eprintln!"), | ||
28 | ("logd", "log::debug!"), | 29 | ("logd", "log::debug!"), |
29 | ("logt", "log::trace!"), | 30 | ("logt", "log::trace!"), |
30 | ("logi", "log::info!"), | 31 | ("logi", "log::info!"), |
@@ -259,6 +260,7 @@ mod tests { | |||
259 | fn test_into_suggestion() { | 260 | fn test_into_suggestion() { |
260 | let test_vector = &[ | 261 | let test_vector = &[ |
261 | ("println!", "{}", r#"println!("{}", $1)"#), | 262 | ("println!", "{}", r#"println!("{}", $1)"#), |
263 | ("eprintln!", "{}", r#"eprintln!("{}", $1)"#), | ||
262 | ( | 264 | ( |
263 | "log::info!", | 265 | "log::info!", |
264 | "{} {expr} {} {2 + 2}", | 266 | "{} {expr} {} {2 + 2}", |
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 5db6e1311..686cee3a1 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -77,7 +77,9 @@ pub use crate::{ | |||
77 | hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult}, | 77 | hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult}, |
78 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, | 78 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, |
79 | markup::Markup, | 79 | markup::Markup, |
80 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, | 80 | references::{ |
81 | Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult, RenameError, | ||
82 | }, | ||
81 | runnables::{Runnable, RunnableKind, TestId}, | 83 | runnables::{Runnable, RunnableKind, TestId}, |
82 | syntax_highlighting::{ | 84 | syntax_highlighting::{ |
83 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, | 85 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, |
@@ -498,7 +500,7 @@ impl Analysis { | |||
498 | &self, | 500 | &self, |
499 | position: FilePosition, | 501 | position: FilePosition, |
500 | new_name: &str, | 502 | new_name: &str, |
501 | ) -> Cancelable<Option<RangeInfo<SourceChange>>> { | 503 | ) -> Cancelable<Result<RangeInfo<SourceChange>, RenameError>> { |
502 | self.with_db(|db| references::rename(db, position, new_name)) | 504 | self.with_db(|db| references::rename(db, position, new_name)) |
503 | } | 505 | } |
504 | 506 | ||
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index e0830eb4f..f65a05ea3 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -26,6 +26,7 @@ use syntax::{ | |||
26 | use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; | 26 | use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; |
27 | 27 | ||
28 | pub(crate) use self::rename::rename; | 28 | pub(crate) use self::rename::rename; |
29 | pub use self::rename::RenameError; | ||
29 | 30 | ||
30 | pub use ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; | 31 | pub use ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; |
31 | 32 | ||
@@ -406,6 +407,23 @@ enum Foo { | |||
406 | } | 407 | } |
407 | 408 | ||
408 | #[test] | 409 | #[test] |
410 | fn test_find_all_refs_enum_var_field() { | ||
411 | check( | ||
412 | r#" | ||
413 | enum Foo { | ||
414 | A, | ||
415 | B { field<|>: u8 }, | ||
416 | C, | ||
417 | } | ||
418 | "#, | ||
419 | expect![[r#" | ||
420 | field RECORD_FIELD FileId(0) 26..35 26..31 Other | ||
421 | |||
422 | "#]], | ||
423 | ); | ||
424 | } | ||
425 | |||
426 | #[test] | ||
409 | fn test_find_all_refs_two_modules() { | 427 | fn test_find_all_refs_two_modules() { |
410 | check( | 428 | check( |
411 | r#" | 429 | r#" |
@@ -669,6 +687,76 @@ fn g() { f(); } | |||
669 | ); | 687 | ); |
670 | } | 688 | } |
671 | 689 | ||
690 | #[test] | ||
691 | fn test_find_all_refs_struct_pat() { | ||
692 | check( | ||
693 | r#" | ||
694 | struct S { | ||
695 | field<|>: u8, | ||
696 | } | ||
697 | |||
698 | fn f(s: S) { | ||
699 | match s { | ||
700 | S { field } => {} | ||
701 | } | ||
702 | } | ||
703 | "#, | ||
704 | expect![[r#" | ||
705 | field RECORD_FIELD FileId(0) 15..24 15..20 Other | ||
706 | |||
707 | FileId(0) 68..73 FieldShorthandForField Read | ||
708 | "#]], | ||
709 | ); | ||
710 | } | ||
711 | |||
712 | #[test] | ||
713 | fn test_find_all_refs_enum_var_pat() { | ||
714 | check( | ||
715 | r#" | ||
716 | enum En { | ||
717 | Variant { | ||
718 | field<|>: u8, | ||
719 | } | ||
720 | } | ||
721 | |||
722 | fn f(e: En) { | ||
723 | match e { | ||
724 | En::Variant { field } => {} | ||
725 | } | ||
726 | } | ||
727 | "#, | ||
728 | expect![[r#" | ||
729 | field RECORD_FIELD FileId(0) 32..41 32..37 Other | ||
730 | |||
731 | FileId(0) 102..107 FieldShorthandForField Read | ||
732 | "#]], | ||
733 | ); | ||
734 | } | ||
735 | |||
736 | #[test] | ||
737 | fn test_find_all_refs_enum_var_privacy() { | ||
738 | check( | ||
739 | r#" | ||
740 | mod m { | ||
741 | pub enum En { | ||
742 | Variant { | ||
743 | field<|>: u8, | ||
744 | } | ||
745 | } | ||
746 | } | ||
747 | |||
748 | fn f() -> m::En { | ||
749 | m::En::Variant { field: 0 } | ||
750 | } | ||
751 | "#, | ||
752 | expect![[r#" | ||
753 | field RECORD_FIELD FileId(0) 56..65 56..61 Other | ||
754 | |||
755 | FileId(0) 125..130 Other Read | ||
756 | "#]], | ||
757 | ); | ||
758 | } | ||
759 | |||
672 | fn check(ra_fixture: &str, expect: Expect) { | 760 | fn check(ra_fixture: &str, expect: Expect) { |
673 | check_with_scope(ra_fixture, None, expect) | 761 | check_with_scope(ra_fixture, None, expect) |
674 | } | 762 | } |
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 8cbe1ae5a..f3b5cfc8c 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs | |||
@@ -6,11 +6,16 @@ use ide_db::{ | |||
6 | defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, | 6 | defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, |
7 | RootDatabase, | 7 | RootDatabase, |
8 | }; | 8 | }; |
9 | use std::convert::TryInto; | 9 | |
10 | use std::{ | ||
11 | convert::TryInto, | ||
12 | error::Error, | ||
13 | fmt::{self, Display}, | ||
14 | }; | ||
10 | use syntax::{ | 15 | use syntax::{ |
11 | algo::find_node_at_offset, | 16 | algo::find_node_at_offset, |
12 | ast::{self, NameOwner}, | 17 | ast::{self, NameOwner}, |
13 | lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken, | 18 | lex_single_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken, |
14 | }; | 19 | }; |
15 | use test_utils::mark; | 20 | use test_utils::mark; |
16 | use text_edit::TextEdit; | 21 | use text_edit::TextEdit; |
@@ -20,17 +25,37 @@ use crate::{ | |||
20 | SourceChange, SourceFileEdit, TextRange, TextSize, | 25 | SourceChange, SourceFileEdit, TextRange, TextSize, |
21 | }; | 26 | }; |
22 | 27 | ||
28 | #[derive(Debug)] | ||
29 | pub struct RenameError(pub(crate) String); | ||
30 | |||
31 | impl fmt::Display for RenameError { | ||
32 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
33 | Display::fmt(&self.0, f) | ||
34 | } | ||
35 | } | ||
36 | |||
37 | impl Error for RenameError {} | ||
38 | |||
23 | pub(crate) fn rename( | 39 | pub(crate) fn rename( |
24 | db: &RootDatabase, | 40 | db: &RootDatabase, |
25 | position: FilePosition, | 41 | position: FilePosition, |
26 | new_name: &str, | 42 | new_name: &str, |
27 | ) -> Option<RangeInfo<SourceChange>> { | 43 | ) -> Result<RangeInfo<SourceChange>, RenameError> { |
28 | let sema = Semantics::new(db); | 44 | let sema = Semantics::new(db); |
29 | 45 | ||
30 | match lex_single_valid_syntax_kind(new_name)? { | 46 | match lex_single_syntax_kind(new_name) { |
31 | SyntaxKind::IDENT | SyntaxKind::UNDERSCORE => (), | 47 | Some(res) => match res { |
32 | SyntaxKind::SELF_KW => return rename_to_self(&sema, position), | 48 | (SyntaxKind::IDENT, _) => (), |
33 | _ => return None, | 49 | (SyntaxKind::UNDERSCORE, _) => (), |
50 | (SyntaxKind::SELF_KW, _) => return rename_to_self(&sema, position), | ||
51 | (_, Some(syntax_error)) => { | ||
52 | return Err(RenameError(format!("Invalid name `{}`: {}", new_name, syntax_error))) | ||
53 | } | ||
54 | (_, None) => { | ||
55 | return Err(RenameError(format!("Invalid name `{}`: not an identifier", new_name))) | ||
56 | } | ||
57 | }, | ||
58 | None => return Err(RenameError(format!("Invalid name `{}`: not an identifier", new_name))), | ||
34 | } | 59 | } |
35 | 60 | ||
36 | let source_file = sema.parse(position.file_id); | 61 | let source_file = sema.parse(position.file_id); |
@@ -103,7 +128,7 @@ fn rename_mod( | |||
103 | position: FilePosition, | 128 | position: FilePosition, |
104 | module: Module, | 129 | module: Module, |
105 | new_name: &str, | 130 | new_name: &str, |
106 | ) -> Option<RangeInfo<SourceChange>> { | 131 | ) -> Result<RangeInfo<SourceChange>, RenameError> { |
107 | let mut source_file_edits = Vec::new(); | 132 | let mut source_file_edits = Vec::new(); |
108 | let mut file_system_edits = Vec::new(); | 133 | let mut file_system_edits = Vec::new(); |
109 | 134 | ||
@@ -125,7 +150,7 @@ fn rename_mod( | |||
125 | 150 | ||
126 | if let Some(src) = module.declaration_source(sema.db) { | 151 | if let Some(src) = module.declaration_source(sema.db) { |
127 | let file_id = src.file_id.original_file(sema.db); | 152 | let file_id = src.file_id.original_file(sema.db); |
128 | let name = src.value.name()?; | 153 | let name = src.value.name().unwrap(); |
129 | let edit = SourceFileEdit { | 154 | let edit = SourceFileEdit { |
130 | file_id, | 155 | file_id, |
131 | edit: TextEdit::replace(name.syntax().text_range(), new_name.into()), | 156 | edit: TextEdit::replace(name.syntax().text_range(), new_name.into()), |
@@ -133,35 +158,40 @@ fn rename_mod( | |||
133 | source_file_edits.push(edit); | 158 | source_file_edits.push(edit); |
134 | } | 159 | } |
135 | 160 | ||
136 | let RangeInfo { range, info: refs } = find_all_refs(sema, position, None)?; | 161 | let RangeInfo { range, info: refs } = find_all_refs(sema, position, None) |
162 | .ok_or_else(|| RenameError("No references found at position".to_string()))?; | ||
137 | let ref_edits = refs | 163 | let ref_edits = refs |
138 | .references | 164 | .references |
139 | .into_iter() | 165 | .into_iter() |
140 | .map(|reference| source_edit_from_reference(reference, new_name)); | 166 | .map(|reference| source_edit_from_reference(reference, new_name)); |
141 | source_file_edits.extend(ref_edits); | 167 | source_file_edits.extend(ref_edits); |
142 | 168 | ||
143 | Some(RangeInfo::new(range, SourceChange::from_edits(source_file_edits, file_system_edits))) | 169 | Ok(RangeInfo::new(range, SourceChange::from_edits(source_file_edits, file_system_edits))) |
144 | } | 170 | } |
145 | 171 | ||
146 | fn rename_to_self( | 172 | fn rename_to_self( |
147 | sema: &Semantics<RootDatabase>, | 173 | sema: &Semantics<RootDatabase>, |
148 | position: FilePosition, | 174 | position: FilePosition, |
149 | ) -> Option<RangeInfo<SourceChange>> { | 175 | ) -> Result<RangeInfo<SourceChange>, RenameError> { |
150 | let source_file = sema.parse(position.file_id); | 176 | let source_file = sema.parse(position.file_id); |
151 | let syn = source_file.syntax(); | 177 | let syn = source_file.syntax(); |
152 | 178 | ||
153 | let fn_def = find_node_at_offset::<ast::Fn>(syn, position.offset)?; | 179 | let fn_def = find_node_at_offset::<ast::Fn>(syn, position.offset) |
154 | let params = fn_def.param_list()?; | 180 | .ok_or_else(|| RenameError("No surrounding method declaration found".to_string()))?; |
181 | let params = | ||
182 | fn_def.param_list().ok_or_else(|| RenameError("Method has no parameters".to_string()))?; | ||
155 | if params.self_param().is_some() { | 183 | if params.self_param().is_some() { |
156 | return None; // method already has self param | 184 | return Err(RenameError("Method already has a self parameter".to_string())); |
157 | } | 185 | } |
158 | let first_param = params.params().next()?; | 186 | let first_param = |
187 | params.params().next().ok_or_else(|| RenameError("Method has no parameters".into()))?; | ||
159 | let mutable = match first_param.ty() { | 188 | let mutable = match first_param.ty() { |
160 | Some(ast::Type::RefType(rt)) => rt.mut_token().is_some(), | 189 | Some(ast::Type::RefType(rt)) => rt.mut_token().is_some(), |
161 | _ => return None, // not renaming other types | 190 | _ => return Err(RenameError("Not renaming other types".to_string())), |
162 | }; | 191 | }; |
163 | 192 | ||
164 | let RangeInfo { range, info: refs } = find_all_refs(sema, position, None)?; | 193 | let RangeInfo { range, info: refs } = find_all_refs(sema, position, None) |
194 | .ok_or_else(|| RenameError("No reference found at position".to_string()))?; | ||
165 | 195 | ||
166 | let param_range = first_param.syntax().text_range(); | 196 | let param_range = first_param.syntax().text_range(); |
167 | let (param_ref, usages): (Vec<Reference>, Vec<Reference>) = refs | 197 | let (param_ref, usages): (Vec<Reference>, Vec<Reference>) = refs |
@@ -169,7 +199,7 @@ fn rename_to_self( | |||
169 | .partition(|reference| param_range.intersect(reference.file_range.range).is_some()); | 199 | .partition(|reference| param_range.intersect(reference.file_range.range).is_some()); |
170 | 200 | ||
171 | if param_ref.is_empty() { | 201 | if param_ref.is_empty() { |
172 | return None; | 202 | return Err(RenameError("Parameter to rename not found".to_string())); |
173 | } | 203 | } |
174 | 204 | ||
175 | let mut edits = usages | 205 | let mut edits = usages |
@@ -185,7 +215,7 @@ fn rename_to_self( | |||
185 | ), | 215 | ), |
186 | }); | 216 | }); |
187 | 217 | ||
188 | Some(RangeInfo::new(range, SourceChange::from(edits))) | 218 | Ok(RangeInfo::new(range, SourceChange::from(edits))) |
189 | } | 219 | } |
190 | 220 | ||
191 | fn text_edit_from_self_param( | 221 | fn text_edit_from_self_param( |
@@ -216,12 +246,13 @@ fn rename_self_to_param( | |||
216 | position: FilePosition, | 246 | position: FilePosition, |
217 | self_token: SyntaxToken, | 247 | self_token: SyntaxToken, |
218 | new_name: &str, | 248 | new_name: &str, |
219 | ) -> Option<RangeInfo<SourceChange>> { | 249 | ) -> Result<RangeInfo<SourceChange>, RenameError> { |
220 | let source_file = sema.parse(position.file_id); | 250 | let source_file = sema.parse(position.file_id); |
221 | let syn = source_file.syntax(); | 251 | let syn = source_file.syntax(); |
222 | 252 | ||
223 | let text = sema.db.file_text(position.file_id); | 253 | let text = sema.db.file_text(position.file_id); |
224 | let fn_def = find_node_at_offset::<ast::Fn>(syn, position.offset)?; | 254 | let fn_def = find_node_at_offset::<ast::Fn>(syn, position.offset) |
255 | .ok_or_else(|| RenameError("No surrounding method declaration found".to_string()))?; | ||
225 | let search_range = fn_def.syntax().text_range(); | 256 | let search_range = fn_def.syntax().text_range(); |
226 | 257 | ||
227 | let mut edits: Vec<SourceFileEdit> = vec![]; | 258 | let mut edits: Vec<SourceFileEdit> = vec![]; |
@@ -235,7 +266,8 @@ fn rename_self_to_param( | |||
235 | syn.token_at_offset(offset).find(|t| t.kind() == SyntaxKind::SELF_KW) | 266 | syn.token_at_offset(offset).find(|t| t.kind() == SyntaxKind::SELF_KW) |
236 | { | 267 | { |
237 | let edit = if let Some(ref self_param) = ast::SelfParam::cast(usage.parent()) { | 268 | let edit = if let Some(ref self_param) = ast::SelfParam::cast(usage.parent()) { |
238 | text_edit_from_self_param(syn, self_param, new_name)? | 269 | text_edit_from_self_param(syn, self_param, new_name) |
270 | .ok_or_else(|| RenameError("No target type found".to_string()))? | ||
239 | } else { | 271 | } else { |
240 | TextEdit::replace(usage.text_range(), String::from(new_name)) | 272 | TextEdit::replace(usage.text_range(), String::from(new_name)) |
241 | }; | 273 | }; |
@@ -246,15 +278,18 @@ fn rename_self_to_param( | |||
246 | let range = ast::SelfParam::cast(self_token.parent()) | 278 | let range = ast::SelfParam::cast(self_token.parent()) |
247 | .map_or(self_token.text_range(), |p| p.syntax().text_range()); | 279 | .map_or(self_token.text_range(), |p| p.syntax().text_range()); |
248 | 280 | ||
249 | Some(RangeInfo::new(range, SourceChange::from(edits))) | 281 | Ok(RangeInfo::new(range, SourceChange::from(edits))) |
250 | } | 282 | } |
251 | 283 | ||
252 | fn rename_reference( | 284 | fn rename_reference( |
253 | sema: &Semantics<RootDatabase>, | 285 | sema: &Semantics<RootDatabase>, |
254 | position: FilePosition, | 286 | position: FilePosition, |
255 | new_name: &str, | 287 | new_name: &str, |
256 | ) -> Option<RangeInfo<SourceChange>> { | 288 | ) -> Result<RangeInfo<SourceChange>, RenameError> { |
257 | let RangeInfo { range, info: refs } = find_all_refs(sema, position, None)?; | 289 | let RangeInfo { range, info: refs } = match find_all_refs(sema, position, None) { |
290 | Some(range_info) => range_info, | ||
291 | None => return Err(RenameError("No references found at position".to_string())), | ||
292 | }; | ||
258 | 293 | ||
259 | let edit = refs | 294 | let edit = refs |
260 | .into_iter() | 295 | .into_iter() |
@@ -262,10 +297,10 @@ fn rename_reference( | |||
262 | .collect::<Vec<_>>(); | 297 | .collect::<Vec<_>>(); |
263 | 298 | ||
264 | if edit.is_empty() { | 299 | if edit.is_empty() { |
265 | return None; | 300 | return Err(RenameError("No references found at position".to_string())); |
266 | } | 301 | } |
267 | 302 | ||
268 | Some(RangeInfo::new(range, SourceChange::from(edit))) | 303 | Ok(RangeInfo::new(range, SourceChange::from(edit))) |
269 | } | 304 | } |
270 | 305 | ||
271 | #[cfg(test)] | 306 | #[cfg(test)] |
@@ -280,25 +315,45 @@ mod tests { | |||
280 | fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) { | 315 | fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) { |
281 | let ra_fixture_after = &trim_indent(ra_fixture_after); | 316 | let ra_fixture_after = &trim_indent(ra_fixture_after); |
282 | let (analysis, position) = fixture::position(ra_fixture_before); | 317 | let (analysis, position) = fixture::position(ra_fixture_before); |
283 | let source_change = analysis.rename(position, new_name).unwrap(); | 318 | let rename_result = analysis |
284 | let mut text_edit_builder = TextEdit::builder(); | 319 | .rename(position, new_name) |
285 | let mut file_id: Option<FileId> = None; | 320 | .unwrap_or_else(|err| panic!("Rename to '{}' was cancelled: {}", new_name, err)); |
286 | if let Some(change) = source_change { | 321 | match rename_result { |
287 | for edit in change.info.source_file_edits { | 322 | Ok(source_change) => { |
288 | file_id = Some(edit.file_id); | 323 | let mut text_edit_builder = TextEdit::builder(); |
289 | for indel in edit.edit.into_iter() { | 324 | let mut file_id: Option<FileId> = None; |
290 | text_edit_builder.replace(indel.delete, indel.insert); | 325 | for edit in source_change.info.source_file_edits { |
326 | file_id = Some(edit.file_id); | ||
327 | for indel in edit.edit.into_iter() { | ||
328 | text_edit_builder.replace(indel.delete, indel.insert); | ||
329 | } | ||
291 | } | 330 | } |
331 | let mut result = analysis.file_text(file_id.unwrap()).unwrap().to_string(); | ||
332 | text_edit_builder.finish().apply(&mut result); | ||
333 | assert_eq_text!(ra_fixture_after, &*result); | ||
292 | } | 334 | } |
293 | } | 335 | Err(err) => { |
294 | let mut result = analysis.file_text(file_id.unwrap()).unwrap().to_string(); | 336 | if ra_fixture_after.starts_with("error:") { |
295 | text_edit_builder.finish().apply(&mut result); | 337 | let error_message = ra_fixture_after |
296 | assert_eq_text!(ra_fixture_after, &*result); | 338 | .chars() |
339 | .into_iter() | ||
340 | .skip("error:".len()) | ||
341 | .collect::<String>(); | ||
342 | assert_eq!(error_message.trim(), err.to_string()); | ||
343 | return; | ||
344 | } else { | ||
345 | panic!("Rename to '{}' failed unexpectedly: {}", new_name, err) | ||
346 | } | ||
347 | } | ||
348 | }; | ||
297 | } | 349 | } |
298 | 350 | ||
299 | fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) { | 351 | fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) { |
300 | let (analysis, position) = fixture::position(ra_fixture); | 352 | let (analysis, position) = fixture::position(ra_fixture); |
301 | let source_change = analysis.rename(position, new_name).unwrap().unwrap(); | 353 | let source_change = analysis |
354 | .rename(position, new_name) | ||
355 | .unwrap() | ||
356 | .expect("Expect returned RangeInfo to be Some, but was None"); | ||
302 | expect.assert_debug_eq(&source_change) | 357 | expect.assert_debug_eq(&source_change) |
303 | } | 358 | } |
304 | 359 | ||
@@ -313,11 +368,30 @@ mod tests { | |||
313 | } | 368 | } |
314 | 369 | ||
315 | #[test] | 370 | #[test] |
316 | fn test_rename_to_invalid_identifier() { | 371 | fn test_rename_to_invalid_identifier1() { |
317 | let (analysis, position) = fixture::position(r#"fn main() { let i<|> = 1; }"#); | 372 | check( |
318 | let new_name = "invalid!"; | 373 | "invalid!", |
319 | let source_change = analysis.rename(position, new_name).unwrap(); | 374 | r#"fn main() { let i<|> = 1; }"#, |
320 | assert!(source_change.is_none()); | 375 | "error: Invalid name `invalid!`: not an identifier", |
376 | ); | ||
377 | } | ||
378 | |||
379 | #[test] | ||
380 | fn test_rename_to_invalid_identifier2() { | ||
381 | check( | ||
382 | "multiple tokens", | ||
383 | r#"fn main() { let i<|> = 1; }"#, | ||
384 | "error: Invalid name `multiple tokens`: not an identifier", | ||
385 | ); | ||
386 | } | ||
387 | |||
388 | #[test] | ||
389 | fn test_rename_to_invalid_identifier3() { | ||
390 | check( | ||
391 | "let", | ||
392 | r#"fn main() { let i<|> = 1; }"#, | ||
393 | "error: Invalid name `let`: not an identifier", | ||
394 | ); | ||
321 | } | 395 | } |
322 | 396 | ||
323 | #[test] | 397 | #[test] |
@@ -350,6 +424,15 @@ fn main() { | |||
350 | } | 424 | } |
351 | 425 | ||
352 | #[test] | 426 | #[test] |
427 | fn test_rename_unresolved_reference() { | ||
428 | check( | ||
429 | "new_name", | ||
430 | r#"fn main() { let _ = unresolved_ref<|>; }"#, | ||
431 | "error: No references found at position", | ||
432 | ); | ||
433 | } | ||
434 | |||
435 | #[test] | ||
353 | fn test_rename_for_macro_args() { | 436 | fn test_rename_for_macro_args() { |
354 | check( | 437 | check( |
355 | "b", | 438 | "b", |
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index edab1d644..8e3dcd99c 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -12,8 +12,9 @@ use once_cell::unsync::Lazy; | |||
12 | use rustc_hash::FxHashMap; | 12 | use rustc_hash::FxHashMap; |
13 | use syntax::{ast, match_ast, AstNode, TextRange, TextSize}; | 13 | use syntax::{ast, match_ast, AstNode, TextRange, TextSize}; |
14 | 14 | ||
15 | use crate::defs::NameClass; | ||
15 | use crate::{ | 16 | use crate::{ |
16 | defs::{classify_name_ref, Definition, NameRefClass}, | 17 | defs::{classify_name, classify_name_ref, Definition, NameRefClass}, |
17 | RootDatabase, | 18 | RootDatabase, |
18 | }; | 19 | }; |
19 | 20 | ||
@@ -226,9 +227,9 @@ impl<'a> FindUsages<'a> { | |||
226 | 227 | ||
227 | let search_scope = { | 228 | let search_scope = { |
228 | let base = self.def.search_scope(sema.db); | 229 | let base = self.def.search_scope(sema.db); |
229 | match self.scope { | 230 | match &self.scope { |
230 | None => base, | 231 | None => base, |
231 | Some(scope) => base.intersection(&scope), | 232 | Some(scope) => base.intersection(scope), |
232 | } | 233 | } |
233 | }; | 234 | }; |
234 | 235 | ||
@@ -251,54 +252,83 @@ impl<'a> FindUsages<'a> { | |||
251 | continue; | 252 | continue; |
252 | } | 253 | } |
253 | 254 | ||
254 | let name_ref: ast::NameRef = | 255 | match sema.find_node_at_offset_with_descend(&tree, offset) { |
255 | match sema.find_node_at_offset_with_descend(&tree, offset) { | 256 | Some(name_ref) => { |
256 | Some(it) => it, | 257 | if self.found_name_ref(&name_ref, sink) { |
257 | None => continue, | ||
258 | }; | ||
259 | |||
260 | match classify_name_ref(&sema, &name_ref) { | ||
261 | Some(NameRefClass::Definition(def)) if &def == self.def => { | ||
262 | let kind = if is_record_lit_name_ref(&name_ref) | ||
263 | || is_call_expr_name_ref(&name_ref) | ||
264 | { | ||
265 | ReferenceKind::StructLiteral | ||
266 | } else { | ||
267 | ReferenceKind::Other | ||
268 | }; | ||
269 | |||
270 | let reference = Reference { | ||
271 | file_range: sema.original_range(name_ref.syntax()), | ||
272 | kind, | ||
273 | access: reference_access(&def, &name_ref), | ||
274 | }; | ||
275 | if sink(reference) { | ||
276 | return; | 258 | return; |
277 | } | 259 | } |
278 | } | 260 | } |
279 | Some(NameRefClass::FieldShorthand { local, field }) => { | 261 | None => match sema.find_node_at_offset_with_descend(&tree, offset) { |
280 | let reference = match self.def { | 262 | Some(name) => { |
281 | Definition::Field(_) if &field == self.def => Reference { | 263 | if self.found_name(&name, sink) { |
282 | file_range: self.sema.original_range(name_ref.syntax()), | 264 | return; |
283 | kind: ReferenceKind::FieldShorthandForField, | 265 | } |
284 | access: reference_access(&field, &name_ref), | ||
285 | }, | ||
286 | Definition::Local(l) if &local == l => Reference { | ||
287 | file_range: self.sema.original_range(name_ref.syntax()), | ||
288 | kind: ReferenceKind::FieldShorthandForLocal, | ||
289 | access: reference_access(&Definition::Local(local), &name_ref), | ||
290 | }, | ||
291 | _ => continue, // not a usage | ||
292 | }; | ||
293 | if sink(reference) { | ||
294 | return; | ||
295 | } | 266 | } |
296 | } | 267 | None => {} |
297 | _ => {} // not a usage | 268 | }, |
298 | } | 269 | } |
299 | } | 270 | } |
300 | } | 271 | } |
301 | } | 272 | } |
273 | |||
274 | fn found_name_ref( | ||
275 | &self, | ||
276 | name_ref: &ast::NameRef, | ||
277 | sink: &mut dyn FnMut(Reference) -> bool, | ||
278 | ) -> bool { | ||
279 | match classify_name_ref(self.sema, &name_ref) { | ||
280 | Some(NameRefClass::Definition(def)) if &def == self.def => { | ||
281 | let kind = if is_record_lit_name_ref(&name_ref) || is_call_expr_name_ref(&name_ref) | ||
282 | { | ||
283 | ReferenceKind::StructLiteral | ||
284 | } else { | ||
285 | ReferenceKind::Other | ||
286 | }; | ||
287 | |||
288 | let reference = Reference { | ||
289 | file_range: self.sema.original_range(name_ref.syntax()), | ||
290 | kind, | ||
291 | access: reference_access(&def, &name_ref), | ||
292 | }; | ||
293 | sink(reference) | ||
294 | } | ||
295 | Some(NameRefClass::FieldShorthand { local, field }) => { | ||
296 | let reference = match self.def { | ||
297 | Definition::Field(_) if &field == self.def => Reference { | ||
298 | file_range: self.sema.original_range(name_ref.syntax()), | ||
299 | kind: ReferenceKind::FieldShorthandForField, | ||
300 | access: reference_access(&field, &name_ref), | ||
301 | }, | ||
302 | Definition::Local(l) if &local == l => Reference { | ||
303 | file_range: self.sema.original_range(name_ref.syntax()), | ||
304 | kind: ReferenceKind::FieldShorthandForLocal, | ||
305 | access: reference_access(&Definition::Local(local), &name_ref), | ||
306 | }, | ||
307 | _ => return false, // not a usage | ||
308 | }; | ||
309 | sink(reference) | ||
310 | } | ||
311 | _ => false, // not a usage | ||
312 | } | ||
313 | } | ||
314 | |||
315 | fn found_name(&self, name: &ast::Name, sink: &mut dyn FnMut(Reference) -> bool) -> bool { | ||
316 | match classify_name(self.sema, name) { | ||
317 | Some(NameClass::FieldShorthand { local: _, field }) => { | ||
318 | let reference = match self.def { | ||
319 | Definition::Field(_) if &field == self.def => Reference { | ||
320 | file_range: self.sema.original_range(name.syntax()), | ||
321 | kind: ReferenceKind::FieldShorthandForField, | ||
322 | // FIXME: mutable patterns should have `Write` access | ||
323 | access: Some(ReferenceAccess::Read), | ||
324 | }, | ||
325 | _ => return false, // not a usage | ||
326 | }; | ||
327 | sink(reference) | ||
328 | } | ||
329 | _ => false, // not a usage | ||
330 | } | ||
331 | } | ||
302 | } | 332 | } |
303 | 333 | ||
304 | fn reference_access(def: &Definition, name_ref: &ast::NameRef) -> Option<ReferenceAccess> { | 334 | fn reference_access(def: &Definition, name_ref: &ast::NameRef) -> Option<ReferenceAccess> { |
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/client.rs b/crates/proc_macro_srv/src/proc_macro/bridge/client.rs index cb4b3bdb0..55d6330cc 100644 --- a/crates/proc_macro_srv/src/proc_macro/bridge/client.rs +++ b/crates/proc_macro_srv/src/proc_macro/bridge/client.rs | |||
@@ -160,6 +160,7 @@ macro_rules! define_handles { | |||
160 | } | 160 | } |
161 | define_handles! { | 161 | define_handles! { |
162 | 'owned: | 162 | 'owned: |
163 | FreeFunctions, | ||
163 | TokenStream, | 164 | TokenStream, |
164 | TokenStreamBuilder, | 165 | TokenStreamBuilder, |
165 | TokenStreamIter, | 166 | TokenStreamIter, |
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs b/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs index aeb05aad4..b97886eb9 100644 --- a/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs +++ b/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs | |||
@@ -57,6 +57,10 @@ use std::thread; | |||
57 | macro_rules! with_api { | 57 | macro_rules! with_api { |
58 | ($S:ident, $self:ident, $m:ident) => { | 58 | ($S:ident, $self:ident, $m:ident) => { |
59 | $m! { | 59 | $m! { |
60 | FreeFunctions { | ||
61 | fn drop($self: $S::FreeFunctions); | ||
62 | fn track_env_var(var: &str, value: Option<&str>); | ||
63 | }, | ||
60 | TokenStream { | 64 | TokenStream { |
61 | fn drop($self: $S::TokenStream); | 65 | fn drop($self: $S::TokenStream); |
62 | fn clone($self: &$S::TokenStream) -> $S::TokenStream; | 66 | fn clone($self: &$S::TokenStream) -> $S::TokenStream; |
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/server.rs b/crates/proc_macro_srv/src/proc_macro/bridge/server.rs index 45d41ac02..3acb239af 100644 --- a/crates/proc_macro_srv/src/proc_macro/bridge/server.rs +++ b/crates/proc_macro_srv/src/proc_macro/bridge/server.rs | |||
@@ -11,6 +11,8 @@ use super::client::HandleStore; | |||
11 | /// Declare an associated item of one of the traits below, optionally | 11 | /// Declare an associated item of one of the traits below, optionally |
12 | /// adjusting it (i.e., adding bounds to types and default bodies to methods). | 12 | /// adjusting it (i.e., adding bounds to types and default bodies to methods). |
13 | macro_rules! associated_item { | 13 | macro_rules! associated_item { |
14 | (type FreeFunctions) => | ||
15 | (type FreeFunctions: 'static;); | ||
14 | (type TokenStream) => | 16 | (type TokenStream) => |
15 | (type TokenStream: 'static + Clone;); | 17 | (type TokenStream: 'static + Clone;); |
16 | (type TokenStreamBuilder) => | 18 | (type TokenStreamBuilder) => |
diff --git a/crates/proc_macro_srv/src/proc_macro/mod.rs b/crates/proc_macro_srv/src/proc_macro/mod.rs index ee0dc9722..fc6e7344f 100644 --- a/crates/proc_macro_srv/src/proc_macro/mod.rs +++ b/crates/proc_macro_srv/src/proc_macro/mod.rs | |||
@@ -924,3 +924,25 @@ impl fmt::Debug for Literal { | |||
924 | self.0.fmt(f) | 924 | self.0.fmt(f) |
925 | } | 925 | } |
926 | } | 926 | } |
927 | |||
928 | pub mod tracked_env { | ||
929 | use std::env::{self, VarError}; | ||
930 | use std::ffi::OsStr; | ||
931 | |||
932 | /// Retrieve an environment variable and add it to build dependency info. | ||
933 | /// Build system executing the compiler will know that the variable was accessed during | ||
934 | /// compilation, and will be able to rerun the build when the value of that variable changes. | ||
935 | /// Besides the dependency tracking this function should be equivalent to `env::var` from the | ||
936 | /// standard library, except that the argument must be UTF-8. | ||
937 | pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> { | ||
938 | use std::ops::Deref; | ||
939 | |||
940 | let key: &str = key.as_ref(); | ||
941 | let value = env::var(key); | ||
942 | super::bridge::client::FreeFunctions::track_env_var( | ||
943 | key, | ||
944 | value.as_ref().map(|t| t.deref()).ok(), | ||
945 | ); | ||
946 | value | ||
947 | } | ||
948 | } | ||
diff --git a/crates/proc_macro_srv/src/rustc_server.rs b/crates/proc_macro_srv/src/rustc_server.rs index 7d1695c86..c5fe3591e 100644 --- a/crates/proc_macro_srv/src/rustc_server.rs +++ b/crates/proc_macro_srv/src/rustc_server.rs | |||
@@ -242,6 +242,8 @@ impl TokenStreamBuilder { | |||
242 | } | 242 | } |
243 | } | 243 | } |
244 | 244 | ||
245 | pub struct FreeFunctions; | ||
246 | |||
245 | #[derive(Clone)] | 247 | #[derive(Clone)] |
246 | pub struct TokenStreamIter { | 248 | pub struct TokenStreamIter { |
247 | trees: IntoIter<TokenTree>, | 249 | trees: IntoIter<TokenTree>, |
@@ -254,6 +256,7 @@ pub struct Rustc { | |||
254 | } | 256 | } |
255 | 257 | ||
256 | impl server::Types for Rustc { | 258 | impl server::Types for Rustc { |
259 | type FreeFunctions = FreeFunctions; | ||
257 | type TokenStream = TokenStream; | 260 | type TokenStream = TokenStream; |
258 | type TokenStreamBuilder = TokenStreamBuilder; | 261 | type TokenStreamBuilder = TokenStreamBuilder; |
259 | type TokenStreamIter = TokenStreamIter; | 262 | type TokenStreamIter = TokenStreamIter; |
@@ -267,6 +270,13 @@ impl server::Types for Rustc { | |||
267 | type MultiSpan = Vec<Span>; | 270 | type MultiSpan = Vec<Span>; |
268 | } | 271 | } |
269 | 272 | ||
273 | impl server::FreeFunctions for Rustc { | ||
274 | fn track_env_var(&mut self, _var: &str, _value: Option<&str>) { | ||
275 | // FIXME: track env var accesses | ||
276 | // https://github.com/rust-lang/rust/pull/71858 | ||
277 | } | ||
278 | } | ||
279 | |||
270 | impl server::TokenStream for Rustc { | 280 | impl server::TokenStream for Rustc { |
271 | fn new(&mut self) -> Self::TokenStream { | 281 | fn new(&mut self) -> Self::TokenStream { |
272 | Self::TokenStream::new() | 282 | Self::TokenStream::new() |
diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml index 261172d61..c5dfdff32 100644 --- a/crates/profile/Cargo.toml +++ b/crates/profile/Cargo.toml | |||
@@ -11,7 +11,7 @@ doctest = false | |||
11 | 11 | ||
12 | [dependencies] | 12 | [dependencies] |
13 | once_cell = "1.3.1" | 13 | once_cell = "1.3.1" |
14 | cfg-if = "0.1.10" | 14 | cfg-if = "1" |
15 | libc = "0.2.73" | 15 | libc = "0.2.73" |
16 | backtrace = { version = "0.3.44", optional = true } | 16 | backtrace = { version = "0.3.44", optional = true } |
17 | 17 | ||
diff --git a/crates/project_model/src/sysroot.rs b/crates/project_model/src/sysroot.rs index 871808d89..e529e07b0 100644 --- a/crates/project_model/src/sysroot.rs +++ b/crates/project_model/src/sysroot.rs | |||
@@ -90,9 +90,15 @@ impl Sysroot { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | if sysroot.by_name("core").is_none() { | 92 | if sysroot.by_name("core").is_none() { |
93 | let var_note = if env::var_os("RUST_SRC_PATH").is_some() { | ||
94 | " (`RUST_SRC_PATH` might be incorrect, try unsetting it)" | ||
95 | } else { | ||
96 | "" | ||
97 | }; | ||
93 | anyhow::bail!( | 98 | anyhow::bail!( |
94 | "could not find libcore in sysroot path `{}`", | 99 | "could not find libcore in sysroot path `{}`{}", |
95 | sysroot_src_dir.as_ref().display() | 100 | sysroot_src_dir.as_ref().display(), |
101 | var_note, | ||
96 | ); | 102 | ); |
97 | } | 103 | } |
98 | 104 | ||
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index ba73abcac..215be850f 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -646,14 +646,9 @@ pub(crate) fn handle_prepare_rename( | |||
646 | let _p = profile::span("handle_prepare_rename"); | 646 | let _p = profile::span("handle_prepare_rename"); |
647 | let position = from_proto::file_position(&snap, params)?; | 647 | let position = from_proto::file_position(&snap, params)?; |
648 | 648 | ||
649 | let optional_change = snap.analysis.rename(position, "dummy")?; | 649 | let change = snap.analysis.rename(position, "dummy")??; |
650 | let range = match optional_change { | ||
651 | None => return Ok(None), | ||
652 | Some(it) => it.range, | ||
653 | }; | ||
654 | |||
655 | let line_index = snap.analysis.file_line_index(position.file_id)?; | 650 | let line_index = snap.analysis.file_line_index(position.file_id)?; |
656 | let range = to_proto::range(&line_index, range); | 651 | let range = to_proto::range(&line_index, change.range); |
657 | Ok(Some(PrepareRenameResponse::Range(range))) | 652 | Ok(Some(PrepareRenameResponse::Range(range))) |
658 | } | 653 | } |
659 | 654 | ||
@@ -672,12 +667,8 @@ pub(crate) fn handle_rename( | |||
672 | .into()); | 667 | .into()); |
673 | } | 668 | } |
674 | 669 | ||
675 | let optional_change = snap.analysis.rename(position, &*params.new_name)?; | 670 | let change = snap.analysis.rename(position, &*params.new_name)??; |
676 | let source_change = match optional_change { | 671 | let workspace_edit = to_proto::workspace_edit(&snap, change.info)?; |
677 | None => return Ok(None), | ||
678 | Some(it) => it.info, | ||
679 | }; | ||
680 | let workspace_edit = to_proto::workspace_edit(&snap, source_change)?; | ||
681 | Ok(Some(workspace_edit)) | 672 | Ok(Some(workspace_edit)) |
682 | } | 673 | } |
683 | 674 | ||
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml index 0b15f10e9..547fe9f47 100644 --- a/crates/syntax/Cargo.toml +++ b/crates/syntax/Cargo.toml | |||
@@ -13,7 +13,7 @@ doctest = false | |||
13 | [dependencies] | 13 | [dependencies] |
14 | itertools = "0.9.0" | 14 | itertools = "0.9.0" |
15 | rowan = "0.10.0" | 15 | rowan = "0.10.0" |
16 | rustc_lexer = { version = "681.0.0", package = "rustc-ap-rustc_lexer" } | 16 | rustc_lexer = { version = "682.0.0", package = "rustc-ap-rustc_lexer" } |
17 | rustc-hash = "1.1.0" | 17 | rustc-hash = "1.1.0" |
18 | arrayvec = "0.5.1" | 18 | arrayvec = "0.5.1" |
19 | once_cell = "1.3.1" | 19 | once_cell = "1.3.1" |
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index d829790d7..fcc4f05e4 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -7,7 +7,7 @@ use anyhow::{bail, format_err, Context, Result}; | |||
7 | use crate::not_bash::{pushd, run}; | 7 | use crate::not_bash::{pushd, run}; |
8 | 8 | ||
9 | // Latest stable, feel free to send a PR if this lags behind. | 9 | // Latest stable, feel free to send a PR if this lags behind. |
10 | const REQUIRED_RUST_VERSION: u32 = 46; | 10 | const REQUIRED_RUST_VERSION: u32 = 47; |
11 | 11 | ||
12 | pub struct InstallCmd { | 12 | pub struct InstallCmd { |
13 | pub client: Option<ClientOpt>, | 13 | pub client: Option<ClientOpt>, |
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 01f04a17c..0c233f87d 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs | |||
@@ -123,6 +123,7 @@ ISC | |||
123 | MIT | 123 | MIT |
124 | MIT / Apache-2.0 | 124 | MIT / Apache-2.0 |
125 | MIT OR Apache-2.0 | 125 | MIT OR Apache-2.0 |
126 | MIT OR Zlib OR Apache-2.0 | ||
126 | MIT/Apache-2.0 | 127 | MIT/Apache-2.0 |
127 | Unlicense OR MIT | 128 | Unlicense OR MIT |
128 | Unlicense/MIT | 129 | Unlicense/MIT |