diff options
81 files changed, 1016 insertions, 778 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 77f2e2e16..1850068a3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml | |||
@@ -12,7 +12,7 @@ env: | |||
12 | CARGO_NET_RETRY: 10 | 12 | CARGO_NET_RETRY: 10 |
13 | CI: 1 | 13 | CI: 1 |
14 | RUST_BACKTRACE: short | 14 | RUST_BACKTRACE: short |
15 | RUSTFLAGS: -D warnings | 15 | RUSTFLAGS: "-D warnings -W unreachable-pub" |
16 | RUSTUP_MAX_RETRIES: 10 | 16 | RUSTUP_MAX_RETRIES: 10 |
17 | 17 | ||
18 | jobs: | 18 | jobs: |
diff --git a/.github/workflows/metrics.yaml b/.github/workflows/metrics.yaml index ea780e875..d189ce9c9 100644 --- a/.github/workflows/metrics.yaml +++ b/.github/workflows/metrics.yaml | |||
@@ -7,7 +7,7 @@ on: | |||
7 | env: | 7 | env: |
8 | CARGO_INCREMENTAL: 0 | 8 | CARGO_INCREMENTAL: 0 |
9 | CARGO_NET_RETRY: 10 | 9 | CARGO_NET_RETRY: 10 |
10 | RUSTFLAGS: -D warnings | 10 | RUSTFLAGS: "-D warnings -W unreachable-pub" |
11 | RUSTUP_MAX_RETRIES: 10 | 11 | RUSTUP_MAX_RETRIES: 10 |
12 | 12 | ||
13 | jobs: | 13 | jobs: |
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c1d56a8e0..919d58925 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml | |||
@@ -11,7 +11,7 @@ on: | |||
11 | env: | 11 | env: |
12 | CARGO_INCREMENTAL: 0 | 12 | CARGO_INCREMENTAL: 0 |
13 | CARGO_NET_RETRY: 10 | 13 | CARGO_NET_RETRY: 10 |
14 | RUSTFLAGS: -D warnings | 14 | RUSTFLAGS: "-D warnings -W unreachable-pub" |
15 | RUSTUP_MAX_RETRIES: 10 | 15 | RUSTUP_MAX_RETRIES: 10 |
16 | 16 | ||
17 | jobs: | 17 | jobs: |
diff --git a/.github/workflows/rustdoc.yaml b/.github/workflows/rustdoc.yaml index cf4bca840..897f64df0 100644 --- a/.github/workflows/rustdoc.yaml +++ b/.github/workflows/rustdoc.yaml | |||
@@ -7,7 +7,7 @@ on: | |||
7 | env: | 7 | env: |
8 | CARGO_INCREMENTAL: 0 | 8 | CARGO_INCREMENTAL: 0 |
9 | CARGO_NET_RETRY: 10 | 9 | CARGO_NET_RETRY: 10 |
10 | RUSTFLAGS: -D warnings | 10 | RUSTFLAGS: "-D warnings -W unreachable-pub" |
11 | RUSTUP_MAX_RETRIES: 10 | 11 | RUSTUP_MAX_RETRIES: 10 |
12 | 12 | ||
13 | jobs: | 13 | jobs: |
diff --git a/Cargo.lock b/Cargo.lock index fe211b9b3..f6b53d188 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -2,9 +2,9 @@ | |||
2 | # It is not intended for manual editing. | 2 | # It is not intended for manual editing. |
3 | [[package]] | 3 | [[package]] |
4 | name = "addr2line" | 4 | name = "addr2line" |
5 | version = "0.13.0" | 5 | version = "0.14.0" |
6 | source = "registry+https://github.com/rust-lang/crates.io-index" | 6 | source = "registry+https://github.com/rust-lang/crates.io-index" |
7 | checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" | 7 | checksum = "7c0929d69e78dd9bf5408269919fcbcaeb2e35e5d43e5815517cdc6a8e11a423" |
8 | dependencies = [ | 8 | dependencies = [ |
9 | "gimli", | 9 | "gimli", |
10 | ] | 10 | ] |
@@ -81,9 +81,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" | |||
81 | 81 | ||
82 | [[package]] | 82 | [[package]] |
83 | name = "backtrace" | 83 | name = "backtrace" |
84 | version = "0.3.53" | 84 | version = "0.3.54" |
85 | source = "registry+https://github.com/rust-lang/crates.io-index" | 85 | source = "registry+https://github.com/rust-lang/crates.io-index" |
86 | checksum = "707b586e0e2f247cbde68cdd2c3ce69ea7b7be43e1c5b426e37c9319c4b9838e" | 86 | checksum = "2baad346b2d4e94a24347adeee9c7a93f412ee94b9cc26e5b59dea23848e9f28" |
87 | dependencies = [ | 87 | dependencies = [ |
88 | "addr2line", | 88 | "addr2line", |
89 | "cfg-if 1.0.0", | 89 | "cfg-if 1.0.0", |
@@ -168,9 +168,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | |||
168 | 168 | ||
169 | [[package]] | 169 | [[package]] |
170 | name = "chalk-derive" | 170 | name = "chalk-derive" |
171 | version = "0.34.0" | 171 | version = "0.37.0" |
172 | source = "registry+https://github.com/rust-lang/crates.io-index" | 172 | source = "registry+https://github.com/rust-lang/crates.io-index" |
173 | checksum = "0e9f986750ecb4df889d0a95d4586bd921889497b33908cc75bb80eadb4c600a" | 173 | checksum = "564b529b0d620da43dc7ea46fa95b5c602e783e1870aeb07e8cbb6d7ff71bee6" |
174 | dependencies = [ | 174 | dependencies = [ |
175 | "proc-macro2", | 175 | "proc-macro2", |
176 | "quote", | 176 | "quote", |
@@ -180,9 +180,9 @@ dependencies = [ | |||
180 | 180 | ||
181 | [[package]] | 181 | [[package]] |
182 | name = "chalk-ir" | 182 | name = "chalk-ir" |
183 | version = "0.34.0" | 183 | version = "0.37.0" |
184 | source = "registry+https://github.com/rust-lang/crates.io-index" | 184 | source = "registry+https://github.com/rust-lang/crates.io-index" |
185 | checksum = "5c352c4649f1408bb3de5d86a248fda78d3d9cd1cbbd9502e7eca1be1e7ac368" | 185 | checksum = "e67d29482387f4cbed6d8f1b1f7d24f00ff10612c700c65fe4af220df11e4d24" |
186 | dependencies = [ | 186 | dependencies = [ |
187 | "chalk-derive", | 187 | "chalk-derive", |
188 | "lazy_static", | 188 | "lazy_static", |
@@ -190,9 +190,9 @@ dependencies = [ | |||
190 | 190 | ||
191 | [[package]] | 191 | [[package]] |
192 | name = "chalk-recursive" | 192 | name = "chalk-recursive" |
193 | version = "0.34.0" | 193 | version = "0.37.0" |
194 | source = "registry+https://github.com/rust-lang/crates.io-index" | 194 | source = "registry+https://github.com/rust-lang/crates.io-index" |
195 | checksum = "7294bb2ac5446fcb83ec9524b9113f59a8913f174a9c1dea6db60532f17a1579" | 195 | checksum = "5c52032be6fbdf91b6a7df3cafba3a6683fdabeff88e7ab73eea96e28657d973" |
196 | dependencies = [ | 196 | dependencies = [ |
197 | "chalk-derive", | 197 | "chalk-derive", |
198 | "chalk-ir", | 198 | "chalk-ir", |
@@ -203,9 +203,9 @@ dependencies = [ | |||
203 | 203 | ||
204 | [[package]] | 204 | [[package]] |
205 | name = "chalk-solve" | 205 | name = "chalk-solve" |
206 | version = "0.34.0" | 206 | version = "0.37.0" |
207 | source = "registry+https://github.com/rust-lang/crates.io-index" | 207 | source = "registry+https://github.com/rust-lang/crates.io-index" |
208 | checksum = "ffbca06963ed6f3d22faed840847a685f02feefa3825c0b94f9b791d03a0ac6f" | 208 | checksum = "e0378bdfe1547b6fd545f518373b08c1e0c14920f7555a62d049021250a2b89b" |
209 | dependencies = [ | 209 | dependencies = [ |
210 | "chalk-derive", | 210 | "chalk-derive", |
211 | "chalk-ir", | 211 | "chalk-ir", |
@@ -416,11 +416,11 @@ checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" | |||
416 | 416 | ||
417 | [[package]] | 417 | [[package]] |
418 | name = "flate2" | 418 | name = "flate2" |
419 | version = "1.0.18" | 419 | version = "1.0.19" |
420 | source = "registry+https://github.com/rust-lang/crates.io-index" | 420 | source = "registry+https://github.com/rust-lang/crates.io-index" |
421 | checksum = "da80be589a72651dcda34d8b35bcdc9b7254ad06325611074d9cc0fbb19f60ee" | 421 | checksum = "7411863d55df97a419aa64cb4d2f167103ea9d767e2c54a1868b7ac3f6b47129" |
422 | dependencies = [ | 422 | dependencies = [ |
423 | "cfg-if 0.1.10", | 423 | "cfg-if 1.0.0", |
424 | "crc32fast", | 424 | "crc32fast", |
425 | "libc", | 425 | "libc", |
426 | "miniz_oxide", | 426 | "miniz_oxide", |
@@ -459,9 +459,9 @@ dependencies = [ | |||
459 | 459 | ||
460 | [[package]] | 460 | [[package]] |
461 | name = "fst" | 461 | name = "fst" |
462 | version = "0.4.4" | 462 | version = "0.4.5" |
463 | source = "registry+https://github.com/rust-lang/crates.io-index" | 463 | source = "registry+https://github.com/rust-lang/crates.io-index" |
464 | checksum = "a7293de202dbfe786c0b3fe6110a027836c5438ed06db7b715c9955ff4bfea51" | 464 | checksum = "d79238883cf0307100b90aba4a755d8051a3182305dfe7f649a1e9dc0517006f" |
465 | 465 | ||
466 | [[package]] | 466 | [[package]] |
467 | name = "fuchsia-zircon" | 467 | name = "fuchsia-zircon" |
@@ -494,9 +494,9 @@ dependencies = [ | |||
494 | 494 | ||
495 | [[package]] | 495 | [[package]] |
496 | name = "gimli" | 496 | name = "gimli" |
497 | version = "0.22.0" | 497 | version = "0.23.0" |
498 | source = "registry+https://github.com/rust-lang/crates.io-index" | 498 | source = "registry+https://github.com/rust-lang/crates.io-index" |
499 | checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" | 499 | checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" |
500 | 500 | ||
501 | [[package]] | 501 | [[package]] |
502 | name = "goblin" | 502 | name = "goblin" |
@@ -723,11 +723,11 @@ dependencies = [ | |||
723 | 723 | ||
724 | [[package]] | 724 | [[package]] |
725 | name = "instant" | 725 | name = "instant" |
726 | version = "0.1.7" | 726 | version = "0.1.8" |
727 | source = "registry+https://github.com/rust-lang/crates.io-index" | 727 | source = "registry+https://github.com/rust-lang/crates.io-index" |
728 | checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66" | 728 | checksum = "cb1fc4429a33e1f80d41dc9fea4d108a88bec1de8053878898ae448a0b52f613" |
729 | dependencies = [ | 729 | dependencies = [ |
730 | "cfg-if 0.1.10", | 730 | "cfg-if 1.0.0", |
731 | ] | 731 | ] |
732 | 732 | ||
733 | [[package]] | 733 | [[package]] |
@@ -784,9 +784,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" | |||
784 | 784 | ||
785 | [[package]] | 785 | [[package]] |
786 | name = "libc" | 786 | name = "libc" |
787 | version = "0.2.79" | 787 | version = "0.2.80" |
788 | source = "registry+https://github.com/rust-lang/crates.io-index" | 788 | source = "registry+https://github.com/rust-lang/crates.io-index" |
789 | checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" | 789 | checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" |
790 | 790 | ||
791 | [[package]] | 791 | [[package]] |
792 | name = "libloading" | 792 | name = "libloading" |
@@ -900,9 +900,9 @@ dependencies = [ | |||
900 | 900 | ||
901 | [[package]] | 901 | [[package]] |
902 | name = "memchr" | 902 | name = "memchr" |
903 | version = "2.3.3" | 903 | version = "2.3.4" |
904 | source = "registry+https://github.com/rust-lang/crates.io-index" | 904 | source = "registry+https://github.com/rust-lang/crates.io-index" |
905 | checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" | 905 | checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" |
906 | 906 | ||
907 | [[package]] | 907 | [[package]] |
908 | name = "memmap" | 908 | name = "memmap" |
@@ -998,9 +998,9 @@ dependencies = [ | |||
998 | 998 | ||
999 | [[package]] | 999 | [[package]] |
1000 | name = "notify" | 1000 | name = "notify" |
1001 | version = "5.0.0-pre.3" | 1001 | version = "5.0.0-pre.4" |
1002 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1002 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1003 | checksum = "77d03607cf88b4b160ba0e9ed425fff3cee3b55ac813f0c685b3a3772da37d0e" | 1003 | checksum = "a8b946889dfdad884379cd56367d93b6d0ce8889cc027d26a69a3a31c0a03bb5" |
1004 | dependencies = [ | 1004 | dependencies = [ |
1005 | "anymap", | 1005 | "anymap", |
1006 | "bitflags", | 1006 | "bitflags", |
@@ -1018,9 +1018,9 @@ dependencies = [ | |||
1018 | 1018 | ||
1019 | [[package]] | 1019 | [[package]] |
1020 | name = "num-integer" | 1020 | name = "num-integer" |
1021 | version = "0.1.43" | 1021 | version = "0.1.44" |
1022 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1022 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1023 | checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" | 1023 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" |
1024 | dependencies = [ | 1024 | dependencies = [ |
1025 | "autocfg", | 1025 | "autocfg", |
1026 | "num-traits", | 1026 | "num-traits", |
@@ -1028,9 +1028,9 @@ dependencies = [ | |||
1028 | 1028 | ||
1029 | [[package]] | 1029 | [[package]] |
1030 | name = "num-traits" | 1030 | name = "num-traits" |
1031 | version = "0.2.12" | 1031 | version = "0.2.14" |
1032 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1032 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1033 | checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" | 1033 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" |
1034 | dependencies = [ | 1034 | dependencies = [ |
1035 | "autocfg", | 1035 | "autocfg", |
1036 | ] | 1036 | ] |
@@ -1047,9 +1047,9 @@ dependencies = [ | |||
1047 | 1047 | ||
1048 | [[package]] | 1048 | [[package]] |
1049 | name = "object" | 1049 | name = "object" |
1050 | version = "0.21.1" | 1050 | version = "0.22.0" |
1051 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1051 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1052 | checksum = "37fd5004feb2ce328a52b0b3d01dbf4ffff72583493900ed15f22d4111c51693" | 1052 | checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" |
1053 | 1053 | ||
1054 | [[package]] | 1054 | [[package]] |
1055 | name = "once_cell" | 1055 | name = "once_cell" |
@@ -1298,9 +1298,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" | |||
1298 | 1298 | ||
1299 | [[package]] | 1299 | [[package]] |
1300 | name = "regex" | 1300 | name = "regex" |
1301 | version = "1.4.1" | 1301 | version = "1.4.2" |
1302 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1302 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1303 | checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" | 1303 | checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" |
1304 | dependencies = [ | 1304 | dependencies = [ |
1305 | "regex-syntax", | 1305 | "regex-syntax", |
1306 | ] | 1306 | ] |
@@ -1317,9 +1317,9 @@ dependencies = [ | |||
1317 | 1317 | ||
1318 | [[package]] | 1318 | [[package]] |
1319 | name = "regex-syntax" | 1319 | name = "regex-syntax" |
1320 | version = "0.6.20" | 1320 | version = "0.6.21" |
1321 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1321 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1322 | checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" | 1322 | checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" |
1323 | 1323 | ||
1324 | [[package]] | 1324 | [[package]] |
1325 | name = "rowan" | 1325 | name = "rowan" |
@@ -1383,9 +1383,9 @@ dependencies = [ | |||
1383 | 1383 | ||
1384 | [[package]] | 1384 | [[package]] |
1385 | name = "rustc-ap-rustc_lexer" | 1385 | name = "rustc-ap-rustc_lexer" |
1386 | version = "685.0.0" | 1386 | version = "686.0.0" |
1387 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1387 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1388 | checksum = "4d6465438127d20bf9d0f5148f806c029934a74c9bce1103a42d47e81d3fe89a" | 1388 | checksum = "a5b04cd2159495584d976d501c5394498470c2e94e4f0cebb8186562d407a678" |
1389 | dependencies = [ | 1389 | dependencies = [ |
1390 | "unicode-xid", | 1390 | "unicode-xid", |
1391 | ] | 1391 | ] |
@@ -1614,9 +1614,9 @@ version = "0.0.0" | |||
1614 | 1614 | ||
1615 | [[package]] | 1615 | [[package]] |
1616 | name = "syn" | 1616 | name = "syn" |
1617 | version = "1.0.46" | 1617 | version = "1.0.48" |
1618 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1618 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1619 | checksum = "5ad5de3220ea04da322618ded2c42233d02baca219d6f160a3e9c87cda16c942" | 1619 | checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" |
1620 | dependencies = [ | 1620 | dependencies = [ |
1621 | "proc-macro2", | 1621 | "proc-macro2", |
1622 | "quote", | 1622 | "quote", |
diff --git a/Cargo.toml b/Cargo.toml index 87d33f06c..e30ef0e2f 100644 --- a/Cargo.toml +++ b/Cargo.toml | |||
@@ -22,7 +22,6 @@ debug = 0 # Set this to 1 or 2 to get more useful backtraces in debugger. | |||
22 | [patch.'crates-io'] | 22 | [patch.'crates-io'] |
23 | # rowan = { path = "../rowan" } | 23 | # rowan = { path = "../rowan" } |
24 | 24 | ||
25 | [patch.'https://github.com/rust-lang/chalk.git'] | ||
26 | # chalk-solve = { path = "../chalk/chalk-solve" } | 25 | # chalk-solve = { path = "../chalk/chalk-solve" } |
27 | # chalk-rust-ir = { path = "../chalk/chalk-rust-ir" } | ||
28 | # chalk-ir = { path = "../chalk/chalk-ir" } | 26 | # chalk-ir = { path = "../chalk/chalk-ir" } |
27 | # chalk-recursive = { path = "../chalk/chalk-recursive" } | ||
diff --git a/crates/assists/src/handlers/qualify_path.rs b/crates/assists/src/handlers/qualify_path.rs index f436bdbbf..d5bc4e574 100644 --- a/crates/assists/src/handlers/qualify_path.rs +++ b/crates/assists/src/handlers/qualify_path.rs | |||
@@ -56,12 +56,14 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
56 | ImportCandidate::QualifierStart(_) => { | 56 | ImportCandidate::QualifierStart(_) => { |
57 | mark::hit!(qualify_path_qualifier_start); | 57 | mark::hit!(qualify_path_qualifier_start); |
58 | let path = ast::Path::cast(import_assets.syntax_under_caret().clone())?; | 58 | let path = ast::Path::cast(import_assets.syntax_under_caret().clone())?; |
59 | let segment = path.segment()?; | 59 | let (prev_segment, segment) = (path.qualifier()?.segment()?, path.segment()?); |
60 | QualifyCandidate::QualifierStart(segment) | 60 | QualifyCandidate::QualifierStart(segment, prev_segment.generic_arg_list()) |
61 | } | 61 | } |
62 | ImportCandidate::UnqualifiedName(_) => { | 62 | ImportCandidate::UnqualifiedName(_) => { |
63 | mark::hit!(qualify_path_unqualified_name); | 63 | mark::hit!(qualify_path_unqualified_name); |
64 | QualifyCandidate::UnqualifiedName | 64 | let path = ast::Path::cast(import_assets.syntax_under_caret().clone())?; |
65 | let generics = path.segment()?.generic_arg_list(); | ||
66 | QualifyCandidate::UnqualifiedName(generics) | ||
65 | } | 67 | } |
66 | ImportCandidate::TraitAssocItem(_) => { | 68 | ImportCandidate::TraitAssocItem(_) => { |
67 | mark::hit!(qualify_path_trait_assoc_item); | 69 | mark::hit!(qualify_path_trait_assoc_item); |
@@ -96,22 +98,25 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
96 | } | 98 | } |
97 | 99 | ||
98 | enum QualifyCandidate<'db> { | 100 | enum QualifyCandidate<'db> { |
99 | QualifierStart(ast::PathSegment), | 101 | QualifierStart(ast::PathSegment, Option<ast::GenericArgList>), |
100 | UnqualifiedName, | 102 | UnqualifiedName(Option<ast::GenericArgList>), |
101 | TraitAssocItem(ast::Path, ast::PathSegment), | 103 | TraitAssocItem(ast::Path, ast::PathSegment), |
102 | TraitMethod(&'db RootDatabase, ast::MethodCallExpr), | 104 | TraitMethod(&'db RootDatabase, ast::MethodCallExpr), |
103 | } | 105 | } |
104 | 106 | ||
105 | impl QualifyCandidate<'_> { | 107 | impl QualifyCandidate<'_> { |
106 | fn qualify(&self, mut replacer: impl FnMut(String), import: hir::ModPath, item: hir::ItemInNs) { | 108 | fn qualify(&self, mut replacer: impl FnMut(String), import: hir::ModPath, item: hir::ItemInNs) { |
109 | let import = mod_path_to_ast(&import); | ||
107 | match self { | 110 | match self { |
108 | QualifyCandidate::QualifierStart(segment) => { | 111 | QualifyCandidate::QualifierStart(segment, generics) => { |
109 | let import = mod_path_to_ast(&import); | 112 | let generics = generics.as_ref().map_or_else(String::new, ToString::to_string); |
110 | replacer(format!("{}::{}", import, segment)); | 113 | replacer(format!("{}{}::{}", import, generics, segment)); |
114 | } | ||
115 | QualifyCandidate::UnqualifiedName(generics) => { | ||
116 | let generics = generics.as_ref().map_or_else(String::new, ToString::to_string); | ||
117 | replacer(format!("{}{}", import.to_string(), generics)); | ||
111 | } | 118 | } |
112 | QualifyCandidate::UnqualifiedName => replacer(mod_path_to_ast(&import).to_string()), | ||
113 | QualifyCandidate::TraitAssocItem(qualifier, segment) => { | 119 | QualifyCandidate::TraitAssocItem(qualifier, segment) => { |
114 | let import = mod_path_to_ast(&import); | ||
115 | replacer(format!("<{} as {}>::{}", qualifier, import, segment)); | 120 | replacer(format!("<{} as {}>::{}", qualifier, import, segment)); |
116 | } | 121 | } |
117 | &QualifyCandidate::TraitMethod(db, ref mcall_expr) => { | 122 | &QualifyCandidate::TraitMethod(db, ref mcall_expr) => { |
@@ -124,25 +129,27 @@ impl QualifyCandidate<'_> { | |||
124 | db: &RootDatabase, | 129 | db: &RootDatabase, |
125 | mcall_expr: &ast::MethodCallExpr, | 130 | mcall_expr: &ast::MethodCallExpr, |
126 | mut replacer: impl FnMut(String), | 131 | mut replacer: impl FnMut(String), |
127 | import: hir::ModPath, | 132 | import: ast::Path, |
128 | item: hir::ItemInNs, | 133 | item: hir::ItemInNs, |
129 | ) -> Option<()> { | 134 | ) -> Option<()> { |
130 | let receiver = mcall_expr.receiver()?; | 135 | let receiver = mcall_expr.receiver()?; |
131 | let trait_method_name = mcall_expr.name_ref()?; | 136 | let trait_method_name = mcall_expr.name_ref()?; |
137 | let generics = | ||
138 | mcall_expr.generic_arg_list().as_ref().map_or_else(String::new, ToString::to_string); | ||
132 | let arg_list = mcall_expr.arg_list().map(|arg_list| arg_list.args()); | 139 | let arg_list = mcall_expr.arg_list().map(|arg_list| arg_list.args()); |
133 | let trait_ = item_as_trait(item)?; | 140 | let trait_ = item_as_trait(item)?; |
134 | let method = find_trait_method(db, trait_, &trait_method_name)?; | 141 | let method = find_trait_method(db, trait_, &trait_method_name)?; |
135 | if let Some(self_access) = method.self_param(db).map(|sp| sp.access(db)) { | 142 | if let Some(self_access) = method.self_param(db).map(|sp| sp.access(db)) { |
136 | let import = mod_path_to_ast(&import); | ||
137 | let receiver = match self_access { | 143 | let receiver = match self_access { |
138 | hir::Access::Shared => make::expr_ref(receiver, false), | 144 | hir::Access::Shared => make::expr_ref(receiver, false), |
139 | hir::Access::Exclusive => make::expr_ref(receiver, true), | 145 | hir::Access::Exclusive => make::expr_ref(receiver, true), |
140 | hir::Access::Owned => receiver, | 146 | hir::Access::Owned => receiver, |
141 | }; | 147 | }; |
142 | replacer(format!( | 148 | replacer(format!( |
143 | "{}::{}{}", | 149 | "{}::{}{}{}", |
144 | import, | 150 | import, |
145 | trait_method_name, | 151 | trait_method_name, |
152 | generics, | ||
146 | match arg_list.clone() { | 153 | match arg_list.clone() { |
147 | Some(args) => make::arg_list(iter::once(receiver).chain(args)), | 154 | Some(args) => make::arg_list(iter::once(receiver).chain(args)), |
148 | None => make::arg_list(iter::once(receiver)), | 155 | None => make::arg_list(iter::once(receiver)), |
@@ -1045,4 +1052,153 @@ fn main() { | |||
1045 | ", | 1052 | ", |
1046 | ); | 1053 | ); |
1047 | } | 1054 | } |
1055 | |||
1056 | #[test] | ||
1057 | fn keep_generic_annotations() { | ||
1058 | check_assist( | ||
1059 | qualify_path, | ||
1060 | r" | ||
1061 | //- /lib.rs crate:dep | ||
1062 | pub mod generic { pub struct Thing<'a, T>(&'a T); } | ||
1063 | |||
1064 | //- /main.rs crate:main deps:dep | ||
1065 | fn foo() -> Thin<|>g<'static, ()> {} | ||
1066 | |||
1067 | fn main() {} | ||
1068 | ", | ||
1069 | r" | ||
1070 | fn foo() -> dep::generic::Thing<'static, ()> {} | ||
1071 | |||
1072 | fn main() {} | ||
1073 | ", | ||
1074 | ); | ||
1075 | } | ||
1076 | |||
1077 | #[test] | ||
1078 | fn keep_generic_annotations_leading_colon() { | ||
1079 | check_assist( | ||
1080 | qualify_path, | ||
1081 | r" | ||
1082 | //- /lib.rs crate:dep | ||
1083 | pub mod generic { pub struct Thing<'a, T>(&'a T); } | ||
1084 | |||
1085 | //- /main.rs crate:main deps:dep | ||
1086 | fn foo() -> Thin<|>g::<'static, ()> {} | ||
1087 | |||
1088 | fn main() {} | ||
1089 | ", | ||
1090 | r" | ||
1091 | fn foo() -> dep::generic::Thing::<'static, ()> {} | ||
1092 | |||
1093 | fn main() {} | ||
1094 | ", | ||
1095 | ); | ||
1096 | } | ||
1097 | |||
1098 | #[test] | ||
1099 | fn associated_struct_const_generic() { | ||
1100 | check_assist( | ||
1101 | qualify_path, | ||
1102 | r" | ||
1103 | mod test_mod { | ||
1104 | pub struct TestStruct<T> {} | ||
1105 | impl<T> TestStruct<T> { | ||
1106 | const TEST_CONST: u8 = 42; | ||
1107 | } | ||
1108 | } | ||
1109 | |||
1110 | fn main() { | ||
1111 | TestStruct::<()>::TEST_CONST<|> | ||
1112 | } | ||
1113 | ", | ||
1114 | r" | ||
1115 | mod test_mod { | ||
1116 | pub struct TestStruct<T> {} | ||
1117 | impl<T> TestStruct<T> { | ||
1118 | const TEST_CONST: u8 = 42; | ||
1119 | } | ||
1120 | } | ||
1121 | |||
1122 | fn main() { | ||
1123 | test_mod::TestStruct::<()>::TEST_CONST | ||
1124 | } | ||
1125 | ", | ||
1126 | ); | ||
1127 | } | ||
1128 | |||
1129 | #[test] | ||
1130 | fn associated_trait_const_generic() { | ||
1131 | check_assist( | ||
1132 | qualify_path, | ||
1133 | r" | ||
1134 | mod test_mod { | ||
1135 | pub trait TestTrait { | ||
1136 | const TEST_CONST: u8; | ||
1137 | } | ||
1138 | pub struct TestStruct<T> {} | ||
1139 | impl<T> TestTrait for TestStruct<T> { | ||
1140 | const TEST_CONST: u8 = 42; | ||
1141 | } | ||
1142 | } | ||
1143 | |||
1144 | fn main() { | ||
1145 | test_mod::TestStruct::<()>::TEST_CONST<|> | ||
1146 | } | ||
1147 | ", | ||
1148 | r" | ||
1149 | mod test_mod { | ||
1150 | pub trait TestTrait { | ||
1151 | const TEST_CONST: u8; | ||
1152 | } | ||
1153 | pub struct TestStruct<T> {} | ||
1154 | impl<T> TestTrait for TestStruct<T> { | ||
1155 | const TEST_CONST: u8 = 42; | ||
1156 | } | ||
1157 | } | ||
1158 | |||
1159 | fn main() { | ||
1160 | <test_mod::TestStruct::<()> as test_mod::TestTrait>::TEST_CONST | ||
1161 | } | ||
1162 | ", | ||
1163 | ); | ||
1164 | } | ||
1165 | |||
1166 | #[test] | ||
1167 | fn trait_method_generic() { | ||
1168 | check_assist( | ||
1169 | qualify_path, | ||
1170 | r" | ||
1171 | mod test_mod { | ||
1172 | pub trait TestTrait { | ||
1173 | fn test_method<T>(&self); | ||
1174 | } | ||
1175 | pub struct TestStruct {} | ||
1176 | impl TestTrait for TestStruct { | ||
1177 | fn test_method<T>(&self) {} | ||
1178 | } | ||
1179 | } | ||
1180 | |||
1181 | fn main() { | ||
1182 | let test_struct = test_mod::TestStruct {}; | ||
1183 | test_struct.test_meth<|>od::<()>() | ||
1184 | } | ||
1185 | ", | ||
1186 | r" | ||
1187 | mod test_mod { | ||
1188 | pub trait TestTrait { | ||
1189 | fn test_method<T>(&self); | ||
1190 | } | ||
1191 | pub struct TestStruct {} | ||
1192 | impl TestTrait for TestStruct { | ||
1193 | fn test_method<T>(&self) {} | ||
1194 | } | ||
1195 | } | ||
1196 | |||
1197 | fn main() { | ||
1198 | let test_struct = test_mod::TestStruct {}; | ||
1199 | test_mod::TestTrait::test_method::<()>(&test_struct) | ||
1200 | } | ||
1201 | ", | ||
1202 | ); | ||
1203 | } | ||
1048 | } | 1204 | } |
diff --git a/crates/assists/src/utils/import_assets.rs b/crates/assists/src/utils/import_assets.rs index 23db3a74b..f47edbb76 100644 --- a/crates/assists/src/utils/import_assets.rs +++ b/crates/assists/src/utils/import_assets.rs | |||
@@ -26,13 +26,13 @@ pub(crate) enum ImportCandidate { | |||
26 | 26 | ||
27 | #[derive(Debug)] | 27 | #[derive(Debug)] |
28 | pub(crate) struct TraitImportCandidate { | 28 | pub(crate) struct TraitImportCandidate { |
29 | pub ty: hir::Type, | 29 | pub(crate) ty: hir::Type, |
30 | pub name: ast::NameRef, | 30 | pub(crate) name: ast::NameRef, |
31 | } | 31 | } |
32 | 32 | ||
33 | #[derive(Debug)] | 33 | #[derive(Debug)] |
34 | pub(crate) struct PathImportCandidate { | 34 | pub(crate) struct PathImportCandidate { |
35 | pub name: ast::NameRef, | 35 | pub(crate) name: ast::NameRef, |
36 | } | 36 | } |
37 | 37 | ||
38 | #[derive(Debug)] | 38 | #[derive(Debug)] |
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs index 033fbcedc..a76bd5ebf 100644 --- a/crates/assists/src/utils/insert_use.rs +++ b/crates/assists/src/utils/insert_use.rs | |||
@@ -17,13 +17,13 @@ use syntax::{ | |||
17 | use test_utils::mark; | 17 | use test_utils::mark; |
18 | 18 | ||
19 | #[derive(Debug)] | 19 | #[derive(Debug)] |
20 | pub enum ImportScope { | 20 | pub(crate) enum ImportScope { |
21 | File(ast::SourceFile), | 21 | File(ast::SourceFile), |
22 | Module(ast::ItemList), | 22 | Module(ast::ItemList), |
23 | } | 23 | } |
24 | 24 | ||
25 | impl ImportScope { | 25 | impl ImportScope { |
26 | pub fn from(syntax: SyntaxNode) -> Option<Self> { | 26 | pub(crate) fn from(syntax: SyntaxNode) -> Option<Self> { |
27 | if let Some(module) = ast::Module::cast(syntax.clone()) { | 27 | if let Some(module) = ast::Module::cast(syntax.clone()) { |
28 | module.item_list().map(ImportScope::Module) | 28 | module.item_list().map(ImportScope::Module) |
29 | } else if let this @ Some(_) = ast::SourceFile::cast(syntax.clone()) { | 29 | } else if let this @ Some(_) = ast::SourceFile::cast(syntax.clone()) { |
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 87f0a0ce5..31907ed98 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs | |||
@@ -12,9 +12,7 @@ use cfg::CfgOptions; | |||
12 | use rustc_hash::{FxHashMap, FxHashSet}; | 12 | use rustc_hash::{FxHashMap, FxHashSet}; |
13 | use syntax::SmolStr; | 13 | use syntax::SmolStr; |
14 | use tt::TokenExpander; | 14 | use tt::TokenExpander; |
15 | use vfs::{file_set::FileSet, VfsPath}; | 15 | use vfs::{file_set::FileSet, FileId, VfsPath}; |
16 | |||
17 | pub use vfs::FileId; | ||
18 | 16 | ||
19 | /// Files are grouped into source roots. A source root is a directory on the | 17 | /// Files are grouped into source roots. A source root is a directory on the |
20 | /// file systems which is watched for changes. Typically it corresponds to a | 18 | /// file systems which is watched for changes. Typically it corresponds to a |
diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index 0804202d6..ce75a5337 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs | |||
@@ -14,11 +14,11 @@ pub use crate::{ | |||
14 | change::Change, | 14 | change::Change, |
15 | input::{ | 15 | input::{ |
16 | CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, | 16 | CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, |
17 | FileId, ProcMacroId, SourceRoot, SourceRootId, | 17 | ProcMacroId, SourceRoot, SourceRootId, |
18 | }, | 18 | }, |
19 | }; | 19 | }; |
20 | pub use salsa; | 20 | pub use salsa; |
21 | pub use vfs::{file_set::FileSet, VfsPath}; | 21 | pub use vfs::{file_set::FileSet, FileId, VfsPath}; |
22 | 22 | ||
23 | #[macro_export] | 23 | #[macro_export] |
24 | macro_rules! impl_intern_key { | 24 | macro_rules! impl_intern_key { |
diff --git a/crates/completion/src/completions/postfix/format_like.rs b/crates/completion/src/completions/postfix/format_like.rs index f35114ed1..88ba86acb 100644 --- a/crates/completion/src/completions/postfix/format_like.rs +++ b/crates/completion/src/completions/postfix/format_like.rs | |||
@@ -88,7 +88,7 @@ enum State { | |||
88 | } | 88 | } |
89 | 89 | ||
90 | impl FormatStrParser { | 90 | impl FormatStrParser { |
91 | pub fn new(input: String) -> Self { | 91 | pub(crate) fn new(input: String) -> Self { |
92 | Self { | 92 | Self { |
93 | input: input.into(), | 93 | input: input.into(), |
94 | output: String::new(), | 94 | output: String::new(), |
@@ -98,7 +98,7 @@ impl FormatStrParser { | |||
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | pub fn parse(&mut self) -> Result<(), ()> { | 101 | pub(crate) fn parse(&mut self) -> Result<(), ()> { |
102 | let mut current_expr = String::new(); | 102 | let mut current_expr = String::new(); |
103 | 103 | ||
104 | let mut placeholder_id = 1; | 104 | let mut placeholder_id = 1; |
@@ -194,7 +194,7 @@ impl FormatStrParser { | |||
194 | Ok(()) | 194 | Ok(()) |
195 | } | 195 | } |
196 | 196 | ||
197 | pub fn into_suggestion(&self, macro_name: &str) -> String { | 197 | pub(crate) fn into_suggestion(&self, macro_name: &str) -> String { |
198 | assert!(self.parsed, "Attempt to get a suggestion from not parsed expression"); | 198 | assert!(self.parsed, "Attempt to get a suggestion from not parsed expression"); |
199 | 199 | ||
200 | let expressions_as_string = self.extracted_expressions.join(", "); | 200 | let expressions_as_string = self.extracted_expressions.join(", "); |
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 563145f92..30a5e4580 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -4,7 +4,6 @@ use std::{iter, sync::Arc}; | |||
4 | use arrayvec::ArrayVec; | 4 | use arrayvec::ArrayVec; |
5 | use base_db::{CrateDisplayName, CrateId, Edition, FileId}; | 5 | use base_db::{CrateDisplayName, CrateId, Edition, FileId}; |
6 | use either::Either; | 6 | use either::Either; |
7 | use hir_def::find_path::PrefixKind; | ||
8 | use hir_def::{ | 7 | use hir_def::{ |
9 | adt::ReprKind, | 8 | adt::ReprKind, |
10 | adt::StructKind, | 9 | adt::StructKind, |
@@ -12,16 +11,18 @@ use hir_def::{ | |||
12 | builtin_type::BuiltinType, | 11 | builtin_type::BuiltinType, |
13 | expr::{BindingAnnotation, Pat, PatId}, | 12 | expr::{BindingAnnotation, Pat, PatId}, |
14 | import_map, | 13 | import_map, |
14 | item_tree::ItemTreeNode, | ||
15 | lang_item::LangItemTarget, | 15 | lang_item::LangItemTarget, |
16 | path::ModPath, | 16 | path::ModPath, |
17 | per_ns::PerNs, | 17 | per_ns::PerNs, |
18 | resolver::{HasResolver, Resolver}, | 18 | resolver::{HasResolver, Resolver}, |
19 | src::HasSource as _, | 19 | src::HasSource as _, |
20 | type_ref::{Mutability, TypeRef}, | 20 | type_ref::{Mutability, TypeRef}, |
21 | AdtId, AssocContainerId, AttrDefId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, | 21 | AdtId, AssocContainerId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, DefWithBodyId, EnumId, |
22 | HasModule, ImplId, LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StaticId, | 22 | FunctionId, GenericDefId, HasModule, ImplId, LocalEnumVariantId, LocalFieldId, LocalModuleId, |
23 | StructId, TraitId, TypeAliasId, TypeParamId, UnionId, | 23 | Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, |
24 | }; | 24 | }; |
25 | use hir_def::{find_path::PrefixKind, item_scope::ItemInNs, visibility::Visibility}; | ||
25 | use hir_expand::{ | 26 | use hir_expand::{ |
26 | diagnostics::DiagnosticSink, | 27 | diagnostics::DiagnosticSink, |
27 | name::{name, AsName}, | 28 | name::{name, AsName}, |
@@ -275,11 +276,6 @@ impl ModuleDef { | |||
275 | } | 276 | } |
276 | } | 277 | } |
277 | 278 | ||
278 | pub use hir_def::{ | ||
279 | attr::Attrs, item_scope::ItemInNs, item_tree::ItemTreeNode, visibility::Visibility, | ||
280 | AssocItemId, AssocItemLoc, | ||
281 | }; | ||
282 | |||
283 | impl Module { | 279 | impl Module { |
284 | pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module { | 280 | pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module { |
285 | Module { id: ModuleId { krate: krate.id, local_id: crate_module_id } } | 281 | Module { id: ModuleId { krate: krate.id, local_id: crate_module_id } } |
diff --git a/crates/hir/src/from_id.rs b/crates/hir/src/from_id.rs index 033f53ac2..265ef6d1f 100644 --- a/crates/hir/src/from_id.rs +++ b/crates/hir/src/from_id.rs | |||
@@ -4,13 +4,13 @@ | |||
4 | //! are splitting the hir. | 4 | //! are splitting the hir. |
5 | 5 | ||
6 | use hir_def::{ | 6 | use hir_def::{ |
7 | expr::PatId, AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, GenericDefId, | 7 | expr::PatId, item_scope::ItemInNs, AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, |
8 | ModuleDefId, VariantId, | 8 | GenericDefId, ModuleDefId, VariantId, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | code_model::ItemInNs, Adt, AssocItem, DefWithBody, EnumVariant, Field, GenericDef, Local, | 12 | Adt, AssocItem, DefWithBody, EnumVariant, Field, GenericDef, Local, MacroDef, ModuleDef, |
13 | MacroDef, ModuleDef, VariantDef, | 13 | VariantDef, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | macro_rules! from_id { | 16 | macro_rules! from_id { |
diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 3bad2338a..c77494152 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs | |||
@@ -6,6 +6,7 @@ use hir_def::{ | |||
6 | src::{HasChildSource, HasSource as _}, | 6 | src::{HasChildSource, HasSource as _}, |
7 | Lookup, VariantId, | 7 | Lookup, VariantId, |
8 | }; | 8 | }; |
9 | use hir_expand::InFile; | ||
9 | use syntax::ast; | 10 | use syntax::ast; |
10 | 11 | ||
11 | use crate::{ | 12 | use crate::{ |
@@ -13,8 +14,6 @@ use crate::{ | |||
13 | Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, | 14 | Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, |
14 | }; | 15 | }; |
15 | 16 | ||
16 | pub use hir_expand::InFile; | ||
17 | |||
18 | pub trait HasSource { | 17 | pub trait HasSource { |
19 | type Ast; | 18 | type Ast; |
20 | fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast>; | 19 | fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast>; |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 4094a76cb..0d184379f 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -36,7 +36,7 @@ pub use crate::{ | |||
36 | Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, | 36 | Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, |
37 | Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, | 37 | Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, |
38 | GenericDef, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, | 38 | GenericDef, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, |
39 | Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, | 39 | Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, |
40 | }, | 40 | }, |
41 | has_source::HasSource, | 41 | has_source::HasSource, |
42 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, | 42 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, |
@@ -53,6 +53,7 @@ pub use hir_def::{ | |||
53 | nameres::ModuleSource, | 53 | nameres::ModuleSource, |
54 | path::{ModPath, PathKind}, | 54 | path::{ModPath, PathKind}, |
55 | type_ref::{Mutability, TypeRef}, | 55 | type_ref::{Mutability, TypeRef}, |
56 | visibility::Visibility, | ||
56 | }; | 57 | }; |
57 | pub use hir_expand::{ | 58 | pub use hir_expand::{ |
58 | name::known, name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, | 59 | name::known, name::AsName, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, |
diff --git a/crates/hir_def/src/body/diagnostics.rs b/crates/hir_def/src/body/diagnostics.rs index cfa47d189..e57bdc133 100644 --- a/crates/hir_def/src/body/diagnostics.rs +++ b/crates/hir_def/src/body/diagnostics.rs | |||
@@ -5,12 +5,12 @@ use hir_expand::diagnostics::DiagnosticSink; | |||
5 | use crate::diagnostics::InactiveCode; | 5 | use crate::diagnostics::InactiveCode; |
6 | 6 | ||
7 | #[derive(Debug, Eq, PartialEq)] | 7 | #[derive(Debug, Eq, PartialEq)] |
8 | pub enum BodyDiagnostic { | 8 | pub(crate) enum BodyDiagnostic { |
9 | InactiveCode(InactiveCode), | 9 | InactiveCode(InactiveCode), |
10 | } | 10 | } |
11 | 11 | ||
12 | impl BodyDiagnostic { | 12 | impl BodyDiagnostic { |
13 | pub fn add_to(&self, sink: &mut DiagnosticSink<'_>) { | 13 | pub(crate) fn add_to(&self, sink: &mut DiagnosticSink<'_>) { |
14 | match self { | 14 | match self { |
15 | BodyDiagnostic::InactiveCode(diag) => { | 15 | BodyDiagnostic::InactiveCode(diag) => { |
16 | sink.push(diag.clone()); | 16 | sink.push(diag.clone()); |
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index ddc267b83..1deaa90f2 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs | |||
@@ -45,14 +45,14 @@ pub(crate) struct LowerCtx { | |||
45 | } | 45 | } |
46 | 46 | ||
47 | impl LowerCtx { | 47 | impl LowerCtx { |
48 | pub fn new(db: &dyn DefDatabase, file_id: HirFileId) -> Self { | 48 | pub(crate) fn new(db: &dyn DefDatabase, file_id: HirFileId) -> Self { |
49 | LowerCtx { hygiene: Hygiene::new(db.upcast(), file_id) } | 49 | LowerCtx { hygiene: Hygiene::new(db.upcast(), file_id) } |
50 | } | 50 | } |
51 | pub fn with_hygiene(hygiene: &Hygiene) -> Self { | 51 | pub(crate) fn with_hygiene(hygiene: &Hygiene) -> Self { |
52 | LowerCtx { hygiene: hygiene.clone() } | 52 | LowerCtx { hygiene: hygiene.clone() } |
53 | } | 53 | } |
54 | 54 | ||
55 | pub fn lower_path(&self, ast: ast::Path) -> Option<Path> { | 55 | pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> { |
56 | Path::from_src(ast, &self.hygiene) | 56 | Path::from_src(ast, &self.hygiene) |
57 | } | 57 | } |
58 | } | 58 | } |
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index f24a1dd77..1b22d1eec 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs | |||
@@ -486,12 +486,12 @@ impl AsMacroCall for InFile<&ast::MacroCall> { | |||
486 | /// Helper wrapper for `AstId` with `ModPath` | 486 | /// Helper wrapper for `AstId` with `ModPath` |
487 | #[derive(Clone, Debug, Eq, PartialEq)] | 487 | #[derive(Clone, Debug, Eq, PartialEq)] |
488 | struct AstIdWithPath<T: ast::AstNode> { | 488 | struct AstIdWithPath<T: ast::AstNode> { |
489 | pub ast_id: AstId<T>, | 489 | ast_id: AstId<T>, |
490 | pub path: path::ModPath, | 490 | path: path::ModPath, |
491 | } | 491 | } |
492 | 492 | ||
493 | impl<T: ast::AstNode> AstIdWithPath<T> { | 493 | impl<T: ast::AstNode> AstIdWithPath<T> { |
494 | pub fn new(file_id: HirFileId, ast_id: FileAstId<T>, path: path::ModPath) -> AstIdWithPath<T> { | 494 | fn new(file_id: HirFileId, ast_id: FileAstId<T>, path: path::ModPath) -> AstIdWithPath<T> { |
495 | AstIdWithPath { ast_id: AstId::new(file_id, ast_id), path } | 495 | AstIdWithPath { ast_id: AstId::new(file_id, ast_id), path } |
496 | } | 496 | } |
497 | } | 497 | } |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 1ff45d244..59b6644c3 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -122,13 +122,13 @@ enum ImportSource { | |||
122 | 122 | ||
123 | #[derive(Clone, Debug, Eq, PartialEq)] | 123 | #[derive(Clone, Debug, Eq, PartialEq)] |
124 | struct Import { | 124 | struct Import { |
125 | pub path: ModPath, | 125 | path: ModPath, |
126 | pub alias: Option<ImportAlias>, | 126 | alias: Option<ImportAlias>, |
127 | pub visibility: RawVisibility, | 127 | visibility: RawVisibility, |
128 | pub is_glob: bool, | 128 | is_glob: bool, |
129 | pub is_prelude: bool, | 129 | is_prelude: bool, |
130 | pub is_extern_crate: bool, | 130 | is_extern_crate: bool, |
131 | pub is_macro_use: bool, | 131 | is_macro_use: bool, |
132 | source: ImportSource, | 132 | source: ImportSource, |
133 | } | 133 | } |
134 | 134 | ||
diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs index 2b36c824a..00fe711fe 100644 --- a/crates/hir_def/src/test_db.rs +++ b/crates/hir_def/src/test_db.rs | |||
@@ -25,7 +25,7 @@ use crate::{db::DefDatabase, ModuleDefId}; | |||
25 | crate::db::DefDatabaseStorage | 25 | crate::db::DefDatabaseStorage |
26 | )] | 26 | )] |
27 | #[derive(Default)] | 27 | #[derive(Default)] |
28 | pub struct TestDB { | 28 | pub(crate) struct TestDB { |
29 | storage: salsa::Storage<TestDB>, | 29 | storage: salsa::Storage<TestDB>, |
30 | events: Mutex<Option<Vec<salsa::Event>>>, | 30 | events: Mutex<Option<Vec<salsa::Event>>>, |
31 | } | 31 | } |
@@ -72,7 +72,7 @@ impl FileLoader for TestDB { | |||
72 | } | 72 | } |
73 | 73 | ||
74 | impl TestDB { | 74 | impl TestDB { |
75 | pub fn module_for_file(&self, file_id: FileId) -> crate::ModuleId { | 75 | pub(crate) fn module_for_file(&self, file_id: FileId) -> crate::ModuleId { |
76 | for &krate in self.relevant_crates(file_id).iter() { | 76 | for &krate in self.relevant_crates(file_id).iter() { |
77 | let crate_def_map = self.crate_def_map(krate); | 77 | let crate_def_map = self.crate_def_map(krate); |
78 | for (local_id, data) in crate_def_map.modules.iter() { | 78 | for (local_id, data) in crate_def_map.modules.iter() { |
@@ -84,13 +84,13 @@ impl TestDB { | |||
84 | panic!("Can't find module for file") | 84 | panic!("Can't find module for file") |
85 | } | 85 | } |
86 | 86 | ||
87 | pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> { | 87 | pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> { |
88 | *self.events.lock().unwrap() = Some(Vec::new()); | 88 | *self.events.lock().unwrap() = Some(Vec::new()); |
89 | f(); | 89 | f(); |
90 | self.events.lock().unwrap().take().unwrap() | 90 | self.events.lock().unwrap().take().unwrap() |
91 | } | 91 | } |
92 | 92 | ||
93 | pub fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { | 93 | pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { |
94 | let events = self.log(f); | 94 | let events = self.log(f); |
95 | events | 95 | events |
96 | .into_iter() | 96 | .into_iter() |
@@ -105,7 +105,7 @@ impl TestDB { | |||
105 | .collect() | 105 | .collect() |
106 | } | 106 | } |
107 | 107 | ||
108 | pub fn extract_annotations(&self) -> FxHashMap<FileId, Vec<(TextRange, String)>> { | 108 | pub(crate) fn extract_annotations(&self) -> FxHashMap<FileId, Vec<(TextRange, String)>> { |
109 | let mut files = Vec::new(); | 109 | let mut files = Vec::new(); |
110 | let crate_graph = self.crate_graph(); | 110 | let crate_graph = self.crate_graph(); |
111 | for krate in crate_graph.iter() { | 111 | for krate in crate_graph.iter() { |
@@ -129,7 +129,7 @@ impl TestDB { | |||
129 | .collect() | 129 | .collect() |
130 | } | 130 | } |
131 | 131 | ||
132 | pub fn diagnostics<F: FnMut(&dyn Diagnostic)>(&self, mut cb: F) { | 132 | pub(crate) fn diagnostics<F: FnMut(&dyn Diagnostic)>(&self, mut cb: F) { |
133 | let crate_graph = self.crate_graph(); | 133 | let crate_graph = self.crate_graph(); |
134 | for krate in crate_graph.iter() { | 134 | for krate in crate_graph.iter() { |
135 | let crate_def_map = self.crate_def_map(krate); | 135 | let crate_def_map = self.crate_def_map(krate); |
@@ -148,7 +148,7 @@ impl TestDB { | |||
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | pub fn check_diagnostics(&self) { | 151 | pub(crate) fn check_diagnostics(&self) { |
152 | let db: &TestDB = self; | 152 | let db: &TestDB = self; |
153 | let annotations = db.extract_annotations(); | 153 | let annotations = db.extract_annotations(); |
154 | assert!(!annotations.is_empty()); | 154 | assert!(!annotations.is_empty()); |
diff --git a/crates/hir_expand/src/test_db.rs b/crates/hir_expand/src/test_db.rs index 86a5d867e..fca501e1f 100644 --- a/crates/hir_expand/src/test_db.rs +++ b/crates/hir_expand/src/test_db.rs | |||
@@ -14,7 +14,7 @@ use rustc_hash::FxHashSet; | |||
14 | crate::db::AstDatabaseStorage | 14 | crate::db::AstDatabaseStorage |
15 | )] | 15 | )] |
16 | #[derive(Default)] | 16 | #[derive(Default)] |
17 | pub struct TestDB { | 17 | pub(crate) struct TestDB { |
18 | storage: salsa::Storage<TestDB>, | 18 | storage: salsa::Storage<TestDB>, |
19 | events: Mutex<Option<Vec<salsa::Event>>>, | 19 | events: Mutex<Option<Vec<salsa::Event>>>, |
20 | } | 20 | } |
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index 367a1b98d..fdc65a5c3 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 = { version = "0.34", default-features = false } | 20 | chalk-solve = { version = "0.37", default-features = false } |
21 | chalk-ir = "0.34" | 21 | chalk-ir = "0.37" |
22 | chalk-recursive = "0.34" | 22 | chalk-recursive = "0.37" |
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/hir_ty/src/diagnostics/decl_check/case_conv.rs b/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs index b0144a289..14e4d92f0 100644 --- a/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs +++ b/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | 6 | ||
7 | /// Converts an identifier to an UpperCamelCase form. | 7 | /// Converts an identifier to an UpperCamelCase form. |
8 | /// Returns `None` if the string is already is UpperCamelCase. | 8 | /// Returns `None` if the string is already is UpperCamelCase. |
9 | pub fn to_camel_case(ident: &str) -> Option<String> { | 9 | pub(crate) fn to_camel_case(ident: &str) -> Option<String> { |
10 | if is_camel_case(ident) { | 10 | if is_camel_case(ident) { |
11 | return None; | 11 | return None; |
12 | } | 12 | } |
@@ -59,7 +59,7 @@ pub fn to_camel_case(ident: &str) -> Option<String> { | |||
59 | 59 | ||
60 | /// Converts an identifier to a lower_snake_case form. | 60 | /// Converts an identifier to a lower_snake_case form. |
61 | /// Returns `None` if the string is already in lower_snake_case. | 61 | /// Returns `None` if the string is already in lower_snake_case. |
62 | pub fn to_lower_snake_case(ident: &str) -> Option<String> { | 62 | pub(crate) fn to_lower_snake_case(ident: &str) -> Option<String> { |
63 | if is_lower_snake_case(ident) { | 63 | if is_lower_snake_case(ident) { |
64 | return None; | 64 | return None; |
65 | } else if is_upper_snake_case(ident) { | 65 | } else if is_upper_snake_case(ident) { |
@@ -71,7 +71,7 @@ pub fn to_lower_snake_case(ident: &str) -> Option<String> { | |||
71 | 71 | ||
72 | /// Converts an identifier to an UPPER_SNAKE_CASE form. | 72 | /// Converts an identifier to an UPPER_SNAKE_CASE form. |
73 | /// Returns `None` if the string is already is UPPER_SNAKE_CASE. | 73 | /// Returns `None` if the string is already is UPPER_SNAKE_CASE. |
74 | pub fn to_upper_snake_case(ident: &str) -> Option<String> { | 74 | pub(crate) fn to_upper_snake_case(ident: &str) -> Option<String> { |
75 | if is_upper_snake_case(ident) { | 75 | if is_upper_snake_case(ident) { |
76 | return None; | 76 | return None; |
77 | } else if is_lower_snake_case(ident) { | 77 | } else if is_lower_snake_case(ident) { |
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index 278a4b947..434b19354 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs | |||
@@ -17,17 +17,10 @@ use crate::{ | |||
17 | ApplicationTy, InferenceResult, Ty, TypeCtor, | 17 | ApplicationTy, InferenceResult, Ty, TypeCtor, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | pub use hir_def::{ | 20 | pub(crate) use hir_def::{ |
21 | body::{ | 21 | body::{Body, BodySourceMap}, |
22 | scope::{ExprScopes, ScopeEntry, ScopeId}, | 22 | expr::{Expr, ExprId, MatchArm, Pat, PatId}, |
23 | Body, BodySourceMap, ExprPtr, ExprSource, PatPtr, PatSource, | 23 | LocalFieldId, VariantId, |
24 | }, | ||
25 | expr::{ | ||
26 | ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, | ||
27 | MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, UnaryOp, | ||
28 | }, | ||
29 | src::HasSource, | ||
30 | LocalFieldId, Lookup, VariantId, | ||
31 | }; | 24 | }; |
32 | 25 | ||
33 | pub(super) struct ExprValidator<'a, 'b: 'a> { | 26 | pub(super) struct ExprValidator<'a, 'b: 'a> { |
diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index 2da9688ca..6dc862826 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs | |||
@@ -59,12 +59,12 @@ impl<'a, 'b> UnsafeValidator<'a, 'b> { | |||
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | pub struct UnsafeExpr { | 62 | pub(crate) struct UnsafeExpr { |
63 | pub expr: ExprId, | 63 | pub(crate) expr: ExprId, |
64 | pub inside_unsafe_block: bool, | 64 | pub(crate) inside_unsafe_block: bool, |
65 | } | 65 | } |
66 | 66 | ||
67 | pub fn unsafe_expressions( | 67 | pub(crate) fn unsafe_expressions( |
68 | db: &dyn HirDatabase, | 68 | db: &dyn HirDatabase, |
69 | infer: &InferenceResult, | 69 | infer: &InferenceResult, |
70 | def: DefWithBodyId, | 70 | def: DefWithBodyId, |
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index d2e151f25..14e8c0633 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -26,6 +26,20 @@ pub trait HirDisplay { | |||
26 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError>; | 26 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError>; |
27 | 27 | ||
28 | /// Returns a `Display`able type that is human-readable. | 28 | /// Returns a `Display`able type that is human-readable. |
29 | fn into_displayable<'a>( | ||
30 | &'a self, | ||
31 | db: &'a dyn HirDatabase, | ||
32 | max_size: Option<usize>, | ||
33 | omit_verbose_types: bool, | ||
34 | display_target: DisplayTarget, | ||
35 | ) -> HirDisplayWrapper<'a, Self> | ||
36 | where | ||
37 | Self: Sized, | ||
38 | { | ||
39 | HirDisplayWrapper { db, t: self, max_size, omit_verbose_types, display_target } | ||
40 | } | ||
41 | |||
42 | /// Returns a `Display`able type that is human-readable. | ||
29 | /// Use this for showing types to the user (e.g. diagnostics) | 43 | /// Use this for showing types to the user (e.g. diagnostics) |
30 | fn display<'a>(&'a self, db: &'a dyn HirDatabase) -> HirDisplayWrapper<'a, Self> | 44 | fn display<'a>(&'a self, db: &'a dyn HirDatabase) -> HirDisplayWrapper<'a, Self> |
31 | where | 45 | where |
@@ -82,6 +96,20 @@ pub trait HirDisplay { | |||
82 | }; | 96 | }; |
83 | Ok(result) | 97 | Ok(result) |
84 | } | 98 | } |
99 | |||
100 | /// Returns a String representation of `self` for test purposes | ||
101 | fn display_test<'a>(&'a self, db: &'a dyn HirDatabase) -> HirDisplayWrapper<'a, Self> | ||
102 | where | ||
103 | Self: Sized, | ||
104 | { | ||
105 | HirDisplayWrapper { | ||
106 | db, | ||
107 | t: self, | ||
108 | max_size: None, | ||
109 | omit_verbose_types: false, | ||
110 | display_target: DisplayTarget::Test, | ||
111 | } | ||
112 | } | ||
85 | } | 113 | } |
86 | 114 | ||
87 | impl<'a> HirFormatter<'a> { | 115 | impl<'a> HirFormatter<'a> { |
@@ -126,7 +154,7 @@ impl<'a> HirFormatter<'a> { | |||
126 | } | 154 | } |
127 | 155 | ||
128 | #[derive(Clone, Copy)] | 156 | #[derive(Clone, Copy)] |
129 | enum DisplayTarget { | 157 | pub enum DisplayTarget { |
130 | /// Display types for inlays, doc popups, autocompletion, etc... | 158 | /// Display types for inlays, doc popups, autocompletion, etc... |
131 | /// Showing `{unknown}` or not qualifying paths is fine here. | 159 | /// Showing `{unknown}` or not qualifying paths is fine here. |
132 | /// There's no reason for this to fail. | 160 | /// There's no reason for this to fail. |
@@ -134,12 +162,17 @@ enum DisplayTarget { | |||
134 | /// Display types for inserting them in source files. | 162 | /// Display types for inserting them in source files. |
135 | /// The generated code should compile, so paths need to be qualified. | 163 | /// The generated code should compile, so paths need to be qualified. |
136 | SourceCode { module_id: ModuleId }, | 164 | SourceCode { module_id: ModuleId }, |
165 | /// Only for test purpose to keep real types | ||
166 | Test, | ||
137 | } | 167 | } |
138 | 168 | ||
139 | impl DisplayTarget { | 169 | impl DisplayTarget { |
140 | fn is_source_code(&self) -> bool { | 170 | fn is_source_code(&self) -> bool { |
141 | matches!(self, Self::SourceCode {..}) | 171 | matches!(self, Self::SourceCode {..}) |
142 | } | 172 | } |
173 | fn is_test(&self) -> bool { | ||
174 | matches!(self, Self::Test) | ||
175 | } | ||
143 | } | 176 | } |
144 | 177 | ||
145 | #[derive(Debug)] | 178 | #[derive(Debug)] |
@@ -213,32 +246,32 @@ impl HirDisplay for ApplicationTy { | |||
213 | TypeCtor::Str => write!(f, "str")?, | 246 | TypeCtor::Str => write!(f, "str")?, |
214 | TypeCtor::Slice => { | 247 | TypeCtor::Slice => { |
215 | let t = self.parameters.as_single(); | 248 | let t = self.parameters.as_single(); |
216 | write!(f, "[{}]", t.display(f.db))?; | 249 | write!(f, "[")?; |
250 | t.hir_fmt(f)?; | ||
251 | write!(f, "]")?; | ||
217 | } | 252 | } |
218 | TypeCtor::Array => { | 253 | TypeCtor::Array => { |
219 | let t = self.parameters.as_single(); | 254 | let t = self.parameters.as_single(); |
220 | write!(f, "[{}; _]", t.display(f.db))?; | 255 | write!(f, "[")?; |
256 | t.hir_fmt(f)?; | ||
257 | write!(f, "; _]")?; | ||
221 | } | 258 | } |
222 | TypeCtor::RawPtr(m) => { | 259 | TypeCtor::RawPtr(m) => { |
223 | let t = self.parameters.as_single(); | 260 | let t = self.parameters.as_single(); |
224 | let ty_display = t.display(f.db); | ||
225 | 261 | ||
226 | write!(f, "*{}", m.as_keyword_for_ptr())?; | 262 | write!(f, "*{}", m.as_keyword_for_ptr())?; |
227 | if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) { | 263 | if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) { |
228 | write!(f, "(")?; | 264 | write!(f, "(")?; |
229 | write!(f, "{}", ty_display)?; | 265 | t.hir_fmt(f)?; |
230 | write!(f, ")")?; | 266 | write!(f, ")")?; |
231 | } else { | 267 | } else { |
232 | write!(f, "{}", ty_display)?; | 268 | t.hir_fmt(f)?; |
233 | } | 269 | } |
234 | } | 270 | } |
235 | TypeCtor::Ref(m) => { | 271 | TypeCtor::Ref(m) => { |
236 | let t = self.parameters.as_single(); | 272 | let t = self.parameters.as_single(); |
237 | let ty_display = if f.omit_verbose_types() { | 273 | let ty_display = |
238 | t.display_truncated(f.db, f.max_size) | 274 | t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); |
239 | } else { | ||
240 | t.display(f.db) | ||
241 | }; | ||
242 | 275 | ||
243 | write!(f, "&{}", m.as_keyword_for_ref())?; | 276 | write!(f, "&{}", m.as_keyword_for_ref())?; |
244 | if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) { | 277 | if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) { |
@@ -253,7 +286,9 @@ impl HirDisplay for ApplicationTy { | |||
253 | TypeCtor::Tuple { .. } => { | 286 | TypeCtor::Tuple { .. } => { |
254 | let ts = &self.parameters; | 287 | let ts = &self.parameters; |
255 | if ts.len() == 1 { | 288 | if ts.len() == 1 { |
256 | write!(f, "({},)", ts[0].display(f.db))?; | 289 | write!(f, "(")?; |
290 | ts[0].hir_fmt(f)?; | ||
291 | write!(f, ",)")?; | ||
257 | } else { | 292 | } else { |
258 | write!(f, "(")?; | 293 | write!(f, "(")?; |
259 | f.write_joined(&*ts.0, ", ")?; | 294 | f.write_joined(&*ts.0, ", ")?; |
@@ -274,11 +309,12 @@ impl HirDisplay for ApplicationTy { | |||
274 | write!(f, ")")?; | 309 | write!(f, ")")?; |
275 | let ret = sig.ret(); | 310 | let ret = sig.ret(); |
276 | if *ret != Ty::unit() { | 311 | if *ret != Ty::unit() { |
277 | let ret_display = if f.omit_verbose_types() { | 312 | let ret_display = ret.into_displayable( |
278 | ret.display_truncated(f.db, f.max_size) | 313 | f.db, |
279 | } else { | 314 | f.max_size, |
280 | ret.display(f.db) | 315 | f.omit_verbose_types, |
281 | }; | 316 | f.display_target, |
317 | ); | ||
282 | write!(f, " -> {}", ret_display)?; | 318 | write!(f, " -> {}", ret_display)?; |
283 | } | 319 | } |
284 | } | 320 | } |
@@ -310,17 +346,19 @@ impl HirDisplay for ApplicationTy { | |||
310 | write!(f, ")")?; | 346 | write!(f, ")")?; |
311 | let ret = sig.ret(); | 347 | let ret = sig.ret(); |
312 | if *ret != Ty::unit() { | 348 | if *ret != Ty::unit() { |
313 | let ret_display = if f.omit_verbose_types() { | 349 | let ret_display = ret.into_displayable( |
314 | ret.display_truncated(f.db, f.max_size) | 350 | f.db, |
315 | } else { | 351 | f.max_size, |
316 | ret.display(f.db) | 352 | f.omit_verbose_types, |
317 | }; | 353 | f.display_target, |
354 | ); | ||
355 | |||
318 | write!(f, " -> {}", ret_display)?; | 356 | write!(f, " -> {}", ret_display)?; |
319 | } | 357 | } |
320 | } | 358 | } |
321 | TypeCtor::Adt(def_id) => { | 359 | TypeCtor::Adt(def_id) => { |
322 | match f.display_target { | 360 | match f.display_target { |
323 | DisplayTarget::Diagnostics => { | 361 | DisplayTarget::Diagnostics | DisplayTarget::Test => { |
324 | let name = match def_id { | 362 | let name = match def_id { |
325 | AdtId::StructId(it) => f.db.struct_data(it).name.clone(), | 363 | AdtId::StructId(it) => f.db.struct_data(it).name.clone(), |
326 | AdtId::UnionId(it) => f.db.union_data(it).name.clone(), | 364 | AdtId::UnionId(it) => f.db.union_data(it).name.clone(), |
@@ -389,12 +427,23 @@ impl HirDisplay for ApplicationTy { | |||
389 | _ => panic!("not an associated type"), | 427 | _ => panic!("not an associated type"), |
390 | }; | 428 | }; |
391 | let trait_ = f.db.trait_data(trait_); | 429 | let trait_ = f.db.trait_data(trait_); |
392 | let type_alias = f.db.type_alias_data(type_alias); | 430 | let type_alias_data = f.db.type_alias_data(type_alias); |
393 | write!(f, "{}::{}", trait_.name, type_alias.name)?; | 431 | |
394 | if self.parameters.len() > 0 { | 432 | // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types) |
395 | write!(f, "<")?; | 433 | if f.display_target.is_test() { |
396 | f.write_joined(&*self.parameters.0, ", ")?; | 434 | write!(f, "{}::{}", trait_.name, type_alias_data.name)?; |
397 | write!(f, ">")?; | 435 | if self.parameters.len() > 0 { |
436 | write!(f, "<")?; | ||
437 | f.write_joined(&*self.parameters.0, ", ")?; | ||
438 | write!(f, ">")?; | ||
439 | } | ||
440 | } else { | ||
441 | let projection_ty = ProjectionTy { | ||
442 | associated_ty: type_alias, | ||
443 | parameters: self.parameters.clone(), | ||
444 | }; | ||
445 | |||
446 | projection_ty.hir_fmt(f)?; | ||
398 | } | 447 | } |
399 | } | 448 | } |
400 | TypeCtor::ForeignType(type_alias) => { | 449 | TypeCtor::ForeignType(type_alias) => { |
@@ -439,11 +488,12 @@ impl HirDisplay for ApplicationTy { | |||
439 | write!(f, "|")?; | 488 | write!(f, "|")?; |
440 | }; | 489 | }; |
441 | 490 | ||
442 | let ret_display = if f.omit_verbose_types() { | 491 | let ret_display = sig.ret().into_displayable( |
443 | sig.ret().display_truncated(f.db, f.max_size) | 492 | f.db, |
444 | } else { | 493 | f.max_size, |
445 | sig.ret().display(f.db) | 494 | f.omit_verbose_types, |
446 | }; | 495 | f.display_target, |
496 | ); | ||
447 | write!(f, " -> {}", ret_display)?; | 497 | write!(f, " -> {}", ret_display)?; |
448 | } else { | 498 | } else { |
449 | write!(f, "{{closure}}")?; | 499 | write!(f, "{{closure}}")?; |
@@ -461,7 +511,13 @@ impl HirDisplay for ProjectionTy { | |||
461 | } | 511 | } |
462 | 512 | ||
463 | let trait_ = f.db.trait_data(self.trait_(f.db)); | 513 | let trait_ = f.db.trait_data(self.trait_(f.db)); |
464 | write!(f, "<{} as {}", self.parameters[0].display(f.db), trait_.name)?; | 514 | let first_parameter = self.parameters[0].into_displayable( |
515 | f.db, | ||
516 | f.max_size, | ||
517 | f.omit_verbose_types, | ||
518 | f.display_target, | ||
519 | ); | ||
520 | write!(f, "<{} as {}", first_parameter, trait_.name)?; | ||
465 | if self.parameters.len() > 1 { | 521 | if self.parameters.len() > 1 { |
466 | write!(f, "<")?; | 522 | write!(f, "<")?; |
467 | f.write_joined(&self.parameters[1..], ", ")?; | 523 | f.write_joined(&self.parameters[1..], ", ")?; |
@@ -640,10 +696,10 @@ impl HirDisplay for GenericPredicate { | |||
640 | projection_pred.projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; | 696 | projection_pred.projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; |
641 | write!( | 697 | write!( |
642 | f, | 698 | f, |
643 | ">::{} = {}", | 699 | ">::{} = ", |
644 | f.db.type_alias_data(projection_pred.projection_ty.associated_ty).name, | 700 | f.db.type_alias_data(projection_pred.projection_ty.associated_ty).name, |
645 | projection_pred.ty.display(f.db) | ||
646 | )?; | 701 | )?; |
702 | projection_pred.ty.hir_fmt(f)?; | ||
647 | } | 703 | } |
648 | GenericPredicate::Error => write!(f, "{{error}}")?, | 704 | GenericPredicate::Error => write!(f, "{{error}}")?, |
649 | } | 705 | } |
@@ -654,13 +710,18 @@ impl HirDisplay for GenericPredicate { | |||
654 | impl HirDisplay for Obligation { | 710 | impl HirDisplay for Obligation { |
655 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 711 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
656 | match self { | 712 | match self { |
657 | Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db)), | 713 | Obligation::Trait(tr) => { |
658 | Obligation::Projection(proj) => write!( | 714 | write!(f, "Implements(")?; |
659 | f, | 715 | tr.hir_fmt(f)?; |
660 | "Normalize({} => {})", | 716 | write!(f, ")") |
661 | proj.projection_ty.display(f.db), | 717 | } |
662 | proj.ty.display(f.db) | 718 | Obligation::Projection(proj) => { |
663 | ), | 719 | write!(f, "Normalize(")?; |
720 | proj.projection_ty.hir_fmt(f)?; | ||
721 | write!(f, " => ")?; | ||
722 | proj.ty.hir_fmt(f)?; | ||
723 | write!(f, ")") | ||
724 | } | ||
664 | } | 725 | } |
665 | } | 726 | } |
666 | } | 727 | } |
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 644ebd42d..a14d67c06 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -94,7 +94,7 @@ enum BindingMode { | |||
94 | } | 94 | } |
95 | 95 | ||
96 | impl BindingMode { | 96 | impl BindingMode { |
97 | pub fn convert(annotation: BindingAnnotation) -> BindingMode { | 97 | fn convert(annotation: BindingAnnotation) -> BindingMode { |
98 | match annotation { | 98 | match annotation { |
99 | BindingAnnotation::Unannotated | BindingAnnotation::Mutable => BindingMode::Move, | 99 | BindingAnnotation::Unannotated | BindingAnnotation::Mutable => BindingMode::Move, |
100 | BindingAnnotation::Ref => BindingMode::Ref(Mutability::Shared), | 100 | BindingAnnotation::Ref => BindingMode::Ref(Mutability::Shared), |
@@ -214,9 +214,9 @@ struct InferenceContext<'a> { | |||
214 | 214 | ||
215 | #[derive(Clone, Debug)] | 215 | #[derive(Clone, Debug)] |
216 | struct BreakableContext { | 216 | struct BreakableContext { |
217 | pub may_break: bool, | 217 | may_break: bool, |
218 | pub break_ty: Ty, | 218 | break_ty: Ty, |
219 | pub label: Option<name::Name>, | 219 | label: Option<name::Name>, |
220 | } | 220 | } |
221 | 221 | ||
222 | fn find_breakable<'c>( | 222 | fn find_breakable<'c>( |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 8ac4cf89a..605951b10 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -107,7 +107,7 @@ impl<'a> InferenceContext<'a> { | |||
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | pub fn callable_sig(&mut self, ty: &Ty, num_args: usize) -> Option<(Vec<Ty>, Ty)> { | 110 | pub(crate) fn callable_sig(&mut self, ty: &Ty, num_args: usize) -> Option<(Vec<Ty>, Ty)> { |
111 | match ty.callable_sig(self.db) { | 111 | match ty.callable_sig(self.db) { |
112 | Some(sig) => Some((sig.params().to_vec(), sig.ret().clone())), | 112 | Some(sig) => Some((sig.params().to_vec(), sig.ret().clone())), |
113 | None => self.callable_sig_from_fn_trait(ty, num_args), | 113 | None => self.callable_sig_from_fn_trait(ty, num_args), |
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 2e895d911..76984242e 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs | |||
@@ -35,7 +35,7 @@ where | |||
35 | 35 | ||
36 | #[derive(Debug)] | 36 | #[derive(Debug)] |
37 | pub(super) struct Canonicalized<T> { | 37 | pub(super) struct Canonicalized<T> { |
38 | pub value: Canonical<T>, | 38 | pub(super) value: Canonical<T>, |
39 | free_vars: Vec<InferTy>, | 39 | free_vars: Vec<InferTy>, |
40 | } | 40 | } |
41 | 41 | ||
@@ -127,7 +127,7 @@ where | |||
127 | } | 127 | } |
128 | 128 | ||
129 | impl<T> Canonicalized<T> { | 129 | impl<T> Canonicalized<T> { |
130 | pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { | 130 | pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { |
131 | ty.walk_mut_binders( | 131 | ty.walk_mut_binders( |
132 | &mut |ty, binders| { | 132 | &mut |ty, binders| { |
133 | if let &mut Ty::Bound(bound) = ty { | 133 | if let &mut Ty::Bound(bound) = ty { |
@@ -141,7 +141,11 @@ impl<T> Canonicalized<T> { | |||
141 | ty | 141 | ty |
142 | } | 142 | } |
143 | 143 | ||
144 | pub fn apply_solution(&self, ctx: &mut InferenceContext<'_>, solution: Canonical<Substs>) { | 144 | pub(super) fn apply_solution( |
145 | &self, | ||
146 | ctx: &mut InferenceContext<'_>, | ||
147 | solution: Canonical<Substs>, | ||
148 | ) { | ||
145 | // the solution may contain new variables, which we need to convert to new inference vars | 149 | // the solution may contain new variables, which we need to convert to new inference vars |
146 | let new_vars = Substs( | 150 | let new_vars = Substs( |
147 | solution | 151 | solution |
@@ -164,7 +168,7 @@ impl<T> Canonicalized<T> { | |||
164 | } | 168 | } |
165 | } | 169 | } |
166 | 170 | ||
167 | pub fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substs> { | 171 | pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substs> { |
168 | let mut table = InferenceTable::new(); | 172 | let mut table = InferenceTable::new(); |
169 | let vars = Substs( | 173 | let vars = Substs( |
170 | tys.kinds | 174 | tys.kinds |
@@ -199,41 +203,46 @@ pub(crate) struct InferenceTable { | |||
199 | } | 203 | } |
200 | 204 | ||
201 | impl InferenceTable { | 205 | impl InferenceTable { |
202 | pub fn new() -> Self { | 206 | pub(crate) fn new() -> Self { |
203 | InferenceTable { var_unification_table: InPlaceUnificationTable::new() } | 207 | InferenceTable { var_unification_table: InPlaceUnificationTable::new() } |
204 | } | 208 | } |
205 | 209 | ||
206 | pub fn new_type_var(&mut self) -> Ty { | 210 | pub(crate) fn new_type_var(&mut self) -> Ty { |
207 | Ty::Infer(InferTy::TypeVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) | 211 | Ty::Infer(InferTy::TypeVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) |
208 | } | 212 | } |
209 | 213 | ||
210 | pub fn new_integer_var(&mut self) -> Ty { | 214 | pub(crate) fn new_integer_var(&mut self) -> Ty { |
211 | Ty::Infer(InferTy::IntVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) | 215 | Ty::Infer(InferTy::IntVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) |
212 | } | 216 | } |
213 | 217 | ||
214 | pub fn new_float_var(&mut self) -> Ty { | 218 | pub(crate) fn new_float_var(&mut self) -> Ty { |
215 | Ty::Infer(InferTy::FloatVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) | 219 | Ty::Infer(InferTy::FloatVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) |
216 | } | 220 | } |
217 | 221 | ||
218 | pub fn new_maybe_never_type_var(&mut self) -> Ty { | 222 | pub(crate) fn new_maybe_never_type_var(&mut self) -> Ty { |
219 | Ty::Infer(InferTy::MaybeNeverTypeVar( | 223 | Ty::Infer(InferTy::MaybeNeverTypeVar( |
220 | self.var_unification_table.new_key(TypeVarValue::Unknown), | 224 | self.var_unification_table.new_key(TypeVarValue::Unknown), |
221 | )) | 225 | )) |
222 | } | 226 | } |
223 | 227 | ||
224 | pub fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { | 228 | pub(crate) fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { |
225 | self.resolve_ty_completely_inner(&mut Vec::new(), ty) | 229 | self.resolve_ty_completely_inner(&mut Vec::new(), ty) |
226 | } | 230 | } |
227 | 231 | ||
228 | pub fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty { | 232 | pub(crate) fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty { |
229 | self.resolve_ty_as_possible_inner(&mut Vec::new(), ty) | 233 | self.resolve_ty_as_possible_inner(&mut Vec::new(), ty) |
230 | } | 234 | } |
231 | 235 | ||
232 | pub fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { | 236 | pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { |
233 | self.unify_inner(ty1, ty2, 0) | 237 | self.unify_inner(ty1, ty2, 0) |
234 | } | 238 | } |
235 | 239 | ||
236 | pub fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs, depth: usize) -> bool { | 240 | pub(crate) fn unify_substs( |
241 | &mut self, | ||
242 | substs1: &Substs, | ||
243 | substs2: &Substs, | ||
244 | depth: usize, | ||
245 | ) -> bool { | ||
237 | substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| self.unify_inner(t1, t2, depth)) | 246 | substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| self.unify_inner(t1, t2, depth)) |
238 | } | 247 | } |
239 | 248 | ||
@@ -331,7 +340,7 @@ impl InferenceTable { | |||
331 | 340 | ||
332 | /// If `ty` is a type variable with known type, returns that type; | 341 | /// If `ty` is a type variable with known type, returns that type; |
333 | /// otherwise, return ty. | 342 | /// otherwise, return ty. |
334 | pub fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { | 343 | pub(crate) fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { |
335 | let mut ty = Cow::Borrowed(ty); | 344 | let mut ty = Cow::Borrowed(ty); |
336 | // The type variable could resolve to a int/float variable. Hence try | 345 | // The type variable could resolve to a int/float variable. Hence try |
337 | // resolving up to three times; each type of variable shouldn't occur | 346 | // resolving up to three times; each type of variable shouldn't occur |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 768d95eff..5a8c97198 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | //! The type system. We currently use this to infer types for completion, hover | 1 | //! The type system. We currently use this to infer types for completion, hover |
2 | //! information and various assists. | 2 | //! information and various assists. |
3 | |||
4 | #[allow(unused)] | 3 | #[allow(unused)] |
5 | macro_rules! eprintln { | 4 | macro_rules! eprintln { |
6 | ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; | 5 | ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; |
@@ -1115,5 +1114,5 @@ pub struct ReturnTypeImplTraits { | |||
1115 | 1114 | ||
1116 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 1115 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
1117 | pub(crate) struct ReturnTypeImplTrait { | 1116 | pub(crate) struct ReturnTypeImplTrait { |
1118 | pub bounds: Binders<Vec<GenericPredicate>>, | 1117 | pub(crate) bounds: Binders<Vec<GenericPredicate>>, |
1119 | } | 1118 | } |
diff --git a/crates/hir_ty/src/test_db.rs b/crates/hir_ty/src/test_db.rs index 15b8435e9..22254b765 100644 --- a/crates/hir_ty/src/test_db.rs +++ b/crates/hir_ty/src/test_db.rs | |||
@@ -21,7 +21,7 @@ use test_utils::extract_annotations; | |||
21 | crate::db::HirDatabaseStorage | 21 | crate::db::HirDatabaseStorage |
22 | )] | 22 | )] |
23 | #[derive(Default)] | 23 | #[derive(Default)] |
24 | pub struct TestDB { | 24 | pub(crate) struct TestDB { |
25 | storage: salsa::Storage<TestDB>, | 25 | storage: salsa::Storage<TestDB>, |
26 | events: Mutex<Option<Vec<salsa::Event>>>, | 26 | events: Mutex<Option<Vec<salsa::Event>>>, |
27 | } | 27 | } |
@@ -113,13 +113,13 @@ impl TestDB { | |||
113 | } | 113 | } |
114 | 114 | ||
115 | impl TestDB { | 115 | impl TestDB { |
116 | pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> { | 116 | pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> { |
117 | *self.events.lock().unwrap() = Some(Vec::new()); | 117 | *self.events.lock().unwrap() = Some(Vec::new()); |
118 | f(); | 118 | f(); |
119 | self.events.lock().unwrap().take().unwrap() | 119 | self.events.lock().unwrap().take().unwrap() |
120 | } | 120 | } |
121 | 121 | ||
122 | pub fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { | 122 | pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { |
123 | let events = self.log(f); | 123 | let events = self.log(f); |
124 | events | 124 | events |
125 | .into_iter() | 125 | .into_iter() |
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs index 0445efc9e..104ef334c 100644 --- a/crates/hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs | |||
@@ -74,7 +74,7 @@ fn check_types_impl(ra_fixture: &str, display_source: bool) { | |||
74 | let module = db.module_for_file(file_id); | 74 | let module = db.module_for_file(file_id); |
75 | ty.display_source_code(&db, module).unwrap() | 75 | ty.display_source_code(&db, module).unwrap() |
76 | } else { | 76 | } else { |
77 | ty.display(&db).to_string() | 77 | ty.display_test(&db).to_string() |
78 | }; | 78 | }; |
79 | assert_eq!(expected, actual); | 79 | assert_eq!(expected, actual); |
80 | checked_one = true; | 80 | checked_one = true; |
@@ -163,7 +163,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
163 | macro_prefix, | 163 | macro_prefix, |
164 | range, | 164 | range, |
165 | ellipsize(text, 15), | 165 | ellipsize(text, 15), |
166 | ty.display(&db) | 166 | ty.display_test(&db) |
167 | ); | 167 | ); |
168 | } | 168 | } |
169 | if include_mismatches { | 169 | if include_mismatches { |
@@ -179,8 +179,8 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
179 | "{}{:?}: expected {}, got {}\n", | 179 | "{}{:?}: expected {}, got {}\n", |
180 | macro_prefix, | 180 | macro_prefix, |
181 | range, | 181 | range, |
182 | mismatch.expected.display(&db), | 182 | mismatch.expected.display_test(&db), |
183 | mismatch.actual.display(&db), | 183 | mismatch.actual.display_test(&db), |
184 | ); | 184 | ); |
185 | } | 185 | } |
186 | } | 186 | } |
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index cbe5cd7dd..55e2c3a3e 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -3,7 +3,7 @@ use std::sync::Arc; | |||
3 | 3 | ||
4 | use log::debug; | 4 | use log::debug; |
5 | 5 | ||
6 | use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg, TypeName}; | 6 | use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg}; |
7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; | 7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; |
8 | 8 | ||
9 | use base_db::{salsa::InternKey, CrateId}; | 9 | use base_db::{salsa::InternKey, CrateId}; |
@@ -27,7 +27,7 @@ use mapping::{ | |||
27 | TypeAliasAsValue, | 27 | TypeAliasAsValue, |
28 | }; | 28 | }; |
29 | 29 | ||
30 | pub use self::interner::*; | 30 | pub(crate) use self::interner::*; |
31 | 31 | ||
32 | pub(super) mod tls; | 32 | pub(super) mod tls; |
33 | mod interner; | 33 | mod interner; |
@@ -81,7 +81,10 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
81 | 81 | ||
82 | let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); | 82 | let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); |
83 | 83 | ||
84 | fn binder_kind(ty: &Ty, binders: &CanonicalVarKinds<Interner>) -> Option<chalk_ir::TyKind> { | 84 | fn binder_kind( |
85 | ty: &Ty, | ||
86 | binders: &CanonicalVarKinds<Interner>, | ||
87 | ) -> Option<chalk_ir::TyVariableKind> { | ||
85 | if let Ty::Bound(bv) = ty { | 88 | if let Ty::Bound(bv) = ty { |
86 | let binders = binders.as_slice(&Interner); | 89 | let binders = binders.as_slice(&Interner); |
87 | if bv.debruijn == DebruijnIndex::INNERMOST { | 90 | if bv.debruijn == DebruijnIndex::INNERMOST { |
@@ -95,8 +98,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
95 | 98 | ||
96 | let self_ty_fp = TyFingerprint::for_impl(&ty); | 99 | let self_ty_fp = TyFingerprint::for_impl(&ty); |
97 | let fps: &[TyFingerprint] = match binder_kind(&ty, binders) { | 100 | let fps: &[TyFingerprint] = match binder_kind(&ty, binders) { |
98 | Some(chalk_ir::TyKind::Integer) => &ALL_INT_FPS, | 101 | Some(chalk_ir::TyVariableKind::Integer) => &ALL_INT_FPS, |
99 | Some(chalk_ir::TyKind::Float) => &ALL_FLOAT_FPS, | 102 | Some(chalk_ir::TyVariableKind::Float) => &ALL_FLOAT_FPS, |
100 | _ => self_ty_fp.as_ref().map(std::slice::from_ref).unwrap_or(&[]), | 103 | _ => self_ty_fp.as_ref().map(std::slice::from_ref).unwrap_or(&[]), |
101 | }; | 104 | }; |
102 | 105 | ||
@@ -129,12 +132,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
129 | debug!("impls_for_trait returned {} impls", result.len()); | 132 | debug!("impls_for_trait returned {} impls", result.len()); |
130 | result | 133 | result |
131 | } | 134 | } |
132 | fn impl_provided_for( | 135 | fn impl_provided_for(&self, auto_trait_id: TraitId, kind: &chalk_ir::TyKind<Interner>) -> bool { |
133 | &self, | 136 | debug!("impl_provided_for {:?}, {:?}", auto_trait_id, kind); |
134 | auto_trait_id: TraitId, | ||
135 | application_ty: &chalk_ir::ApplicationTy<Interner>, | ||
136 | ) -> bool { | ||
137 | debug!("impl_provided_for {:?}, {:?}", auto_trait_id, application_ty); | ||
138 | false // FIXME | 137 | false // FIXME |
139 | } | 138 | } |
140 | fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc<AssociatedTyValue> { | 139 | fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc<AssociatedTyValue> { |
@@ -466,7 +465,7 @@ pub(crate) fn struct_datum_query( | |||
466 | struct_id: AdtId, | 465 | struct_id: AdtId, |
467 | ) -> Arc<StructDatum> { | 466 | ) -> Arc<StructDatum> { |
468 | debug!("struct_datum {:?}", struct_id); | 467 | debug!("struct_datum {:?}", struct_id); |
469 | let type_ctor: TypeCtor = from_chalk(db, TypeName::Adt(struct_id)); | 468 | let type_ctor = TypeCtor::Adt(from_chalk(db, struct_id)); |
470 | debug!("struct {:?} = {:?}", struct_id, type_ctor); | 469 | debug!("struct {:?} = {:?}", struct_id, type_ctor); |
471 | let num_params = type_ctor.num_ty_params(db); | 470 | let num_params = type_ctor.num_ty_params(db); |
472 | let upstream = type_ctor.krate(db) != Some(krate); | 471 | let upstream = type_ctor.krate(db) != Some(krate); |
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index f9304b7d0..39569e690 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs | |||
@@ -10,21 +10,21 @@ use std::{fmt, sync::Arc}; | |||
10 | #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] | 10 | #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] |
11 | pub struct Interner; | 11 | pub struct Interner; |
12 | 12 | ||
13 | pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | 13 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; |
14 | pub type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; | 14 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; |
15 | pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | 15 | pub(crate) type ForeignDefId = chalk_ir::ForeignDefId<Interner>; |
16 | pub type TraitId = chalk_ir::TraitId<Interner>; | 16 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; |
17 | pub type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; | 17 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; |
18 | pub type AdtId = chalk_ir::AdtId<Interner>; | 18 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; |
19 | pub type StructDatum = chalk_solve::rust_ir::AdtDatum<Interner>; | 19 | pub(crate) type StructDatum = chalk_solve::rust_ir::AdtDatum<Interner>; |
20 | pub type ImplId = chalk_ir::ImplId<Interner>; | 20 | pub(crate) type ImplId = chalk_ir::ImplId<Interner>; |
21 | pub type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; | 21 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; |
22 | pub type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; | 22 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; |
23 | pub type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; | 23 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; |
24 | pub type FnDefId = chalk_ir::FnDefId<Interner>; | 24 | pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>; |
25 | pub type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; | 25 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; |
26 | pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; | 26 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; |
27 | pub type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; | 27 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; |
28 | 28 | ||
29 | impl chalk_ir::interner::Interner for Interner { | 29 | impl chalk_ir::interner::Interner for Interner { |
30 | type InternedType = Arc<chalk_ir::TyData<Self>>; | 30 | type InternedType = Arc<chalk_ir::TyData<Self>>; |
@@ -122,13 +122,6 @@ impl chalk_ir::interner::Interner for Interner { | |||
122 | tls::with_current_program(|prog| Some(prog?.debug_program_clause_implication(pci, fmt))) | 122 | tls::with_current_program(|prog| Some(prog?.debug_program_clause_implication(pci, fmt))) |
123 | } | 123 | } |
124 | 124 | ||
125 | fn debug_application_ty( | ||
126 | application_ty: &chalk_ir::ApplicationTy<Interner>, | ||
127 | fmt: &mut fmt::Formatter<'_>, | ||
128 | ) -> Option<fmt::Result> { | ||
129 | tls::with_current_program(|prog| Some(prog?.debug_application_ty(application_ty, fmt))) | ||
130 | } | ||
131 | |||
132 | fn debug_substitution( | 125 | fn debug_substitution( |
133 | substitution: &chalk_ir::Substitution<Interner>, | 126 | substitution: &chalk_ir::Substitution<Interner>, |
134 | fmt: &mut fmt::Formatter<'_>, | 127 | fmt: &mut fmt::Formatter<'_>, |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index dd7affcec..86cbc4c7e 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | use chalk_ir::{ | 6 | use chalk_ir::{ |
7 | cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, Scalar, | 7 | cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, Scalar, |
8 | TypeName, UniverseIndex, | 8 | UniverseIndex, |
9 | }; | 9 | }; |
10 | use chalk_solve::rust_ir; | 10 | use chalk_solve::rust_ir; |
11 | 11 | ||
@@ -32,7 +32,7 @@ impl ToChalk for Ty { | |||
32 | TypeCtor::Array => array_to_chalk(db, apply_ty.parameters), | 32 | TypeCtor::Array => array_to_chalk(db, apply_ty.parameters), |
33 | TypeCtor::FnPtr { num_args: _, is_varargs } => { | 33 | TypeCtor::FnPtr { num_args: _, is_varargs } => { |
34 | let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner); | 34 | let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner); |
35 | chalk_ir::TyData::Function(chalk_ir::FnPointer { | 35 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
36 | num_binders: 0, | 36 | num_binders: 0, |
37 | sig: chalk_ir::FnSig { | 37 | sig: chalk_ir::FnSig { |
38 | abi: (), | 38 | abi: (), |
@@ -43,10 +43,68 @@ impl ToChalk for Ty { | |||
43 | }) | 43 | }) |
44 | .intern(&Interner) | 44 | .intern(&Interner) |
45 | } | 45 | } |
46 | _ => { | 46 | TypeCtor::AssociatedType(type_alias) => { |
47 | let name = apply_ty.ctor.to_chalk(db); | 47 | let assoc_type = TypeAliasAsAssocType(type_alias); |
48 | let assoc_type_id = assoc_type.to_chalk(db); | ||
48 | let substitution = apply_ty.parameters.to_chalk(db); | 49 | let substitution = apply_ty.parameters.to_chalk(db); |
49 | chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) | 50 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) |
51 | } | ||
52 | |||
53 | TypeCtor::OpaqueType(impl_trait_id) => { | ||
54 | let id = impl_trait_id.to_chalk(db); | ||
55 | let substitution = apply_ty.parameters.to_chalk(db); | ||
56 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) | ||
57 | } | ||
58 | |||
59 | TypeCtor::ForeignType(type_alias) => { | ||
60 | let foreign_type = TypeAliasAsForeignType(type_alias); | ||
61 | let foreign_type_id = foreign_type.to_chalk(db); | ||
62 | chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner) | ||
63 | } | ||
64 | |||
65 | TypeCtor::Bool => chalk_ir::TyKind::Scalar(Scalar::Bool).intern(&Interner), | ||
66 | TypeCtor::Char => chalk_ir::TyKind::Scalar(Scalar::Char).intern(&Interner), | ||
67 | TypeCtor::Int(int_ty) => { | ||
68 | chalk_ir::TyKind::Scalar(int_ty_to_chalk(int_ty)).intern(&Interner) | ||
69 | } | ||
70 | TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 }) => { | ||
71 | chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) | ||
72 | .intern(&Interner) | ||
73 | } | ||
74 | TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 }) => { | ||
75 | chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) | ||
76 | .intern(&Interner) | ||
77 | } | ||
78 | |||
79 | TypeCtor::Tuple { cardinality } => { | ||
80 | let substitution = apply_ty.parameters.to_chalk(db); | ||
81 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) | ||
82 | } | ||
83 | TypeCtor::RawPtr(mutability) => { | ||
84 | let ty = apply_ty.parameters[0].clone().to_chalk(db); | ||
85 | chalk_ir::TyKind::Raw(mutability.to_chalk(db), ty).intern(&Interner) | ||
86 | } | ||
87 | TypeCtor::Slice => { | ||
88 | chalk_ir::TyKind::Slice(apply_ty.parameters[0].clone().to_chalk(db)) | ||
89 | .intern(&Interner) | ||
90 | } | ||
91 | TypeCtor::Str => chalk_ir::TyKind::Str.intern(&Interner), | ||
92 | TypeCtor::FnDef(callable_def) => { | ||
93 | let id = callable_def.to_chalk(db); | ||
94 | let substitution = apply_ty.parameters.to_chalk(db); | ||
95 | chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) | ||
96 | } | ||
97 | TypeCtor::Never => chalk_ir::TyKind::Never.intern(&Interner), | ||
98 | |||
99 | TypeCtor::Closure { def, expr } => { | ||
100 | let closure_id = db.intern_closure((def, expr)); | ||
101 | let substitution = apply_ty.parameters.to_chalk(db); | ||
102 | chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) | ||
103 | } | ||
104 | |||
105 | TypeCtor::Adt(adt_id) => { | ||
106 | let substitution = apply_ty.parameters.to_chalk(db); | ||
107 | chalk_ir::TyKind::Adt(chalk_ir::AdtId(adt_id), substitution).intern(&Interner) | ||
50 | } | 108 | } |
51 | }, | 109 | }, |
52 | Ty::Projection(proj_ty) => { | 110 | Ty::Projection(proj_ty) => { |
@@ -67,7 +125,7 @@ impl ToChalk for Ty { | |||
67 | } | 125 | } |
68 | .to_ty::<Interner>(&Interner) | 126 | .to_ty::<Interner>(&Interner) |
69 | } | 127 | } |
70 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner), | 128 | Ty::Bound(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), |
71 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), | 129 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), |
72 | Ty::Dyn(predicates) => { | 130 | Ty::Dyn(predicates) => { |
73 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( | 131 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( |
@@ -78,55 +136,45 @@ impl ToChalk for Ty { | |||
78 | bounds: make_binders(where_clauses, 1), | 136 | bounds: make_binders(where_clauses, 1), |
79 | lifetime: LifetimeData::Static.intern(&Interner), | 137 | lifetime: LifetimeData::Static.intern(&Interner), |
80 | }; | 138 | }; |
81 | chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) | 139 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
82 | } | 140 | } |
83 | Ty::Opaque(opaque_ty) => { | 141 | Ty::Opaque(opaque_ty) => { |
84 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); | 142 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); |
85 | let substitution = opaque_ty.parameters.to_chalk(db); | 143 | let substitution = opaque_ty.parameters.to_chalk(db); |
86 | chalk_ir::TyData::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | 144 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { |
87 | opaque_ty_id, | 145 | opaque_ty_id, |
88 | substitution, | 146 | substitution, |
89 | })) | 147 | })) |
90 | .intern(&Interner) | 148 | .intern(&Interner) |
91 | } | 149 | } |
92 | Ty::Unknown => { | 150 | Ty::Unknown => chalk_ir::TyKind::Error.intern(&Interner), |
93 | let substitution = chalk_ir::Substitution::empty(&Interner); | ||
94 | let name = TypeName::Error; | ||
95 | chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) | ||
96 | } | ||
97 | } | 151 | } |
98 | } | 152 | } |
99 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { | 153 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { |
100 | match chalk.data(&Interner).clone() { | 154 | match chalk.data(&Interner).kind.clone() { |
101 | chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { | 155 | chalk_ir::TyKind::Error => Ty::Unknown, |
102 | TypeName::Error => Ty::Unknown, | 156 | chalk_ir::TyKind::Array(ty, _size) => { |
103 | TypeName::Ref(m) => ref_from_chalk(db, m, apply_ty.substitution), | 157 | Ty::apply(TypeCtor::Array, Substs::single(from_chalk(db, ty))) |
104 | TypeName::Array => array_from_chalk(db, apply_ty.substitution), | 158 | } |
105 | _ => { | 159 | chalk_ir::TyKind::Placeholder(idx) => { |
106 | let ctor = from_chalk(db, apply_ty.name); | ||
107 | let parameters = from_chalk(db, apply_ty.substitution); | ||
108 | Ty::Apply(ApplicationTy { ctor, parameters }) | ||
109 | } | ||
110 | }, | ||
111 | chalk_ir::TyData::Placeholder(idx) => { | ||
112 | assert_eq!(idx.ui, UniverseIndex::ROOT); | 160 | assert_eq!(idx.ui, UniverseIndex::ROOT); |
113 | let interned_id = crate::db::GlobalTypeParamId::from_intern_id( | 161 | let interned_id = crate::db::GlobalTypeParamId::from_intern_id( |
114 | crate::salsa::InternId::from(idx.idx), | 162 | crate::salsa::InternId::from(idx.idx), |
115 | ); | 163 | ); |
116 | Ty::Placeholder(db.lookup_intern_type_param_id(interned_id)) | 164 | Ty::Placeholder(db.lookup_intern_type_param_id(interned_id)) |
117 | } | 165 | } |
118 | chalk_ir::TyData::Alias(chalk_ir::AliasTy::Projection(proj)) => { | 166 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { |
119 | let associated_ty = | 167 | let associated_ty = |
120 | from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; | 168 | from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; |
121 | let parameters = from_chalk(db, proj.substitution); | 169 | let parameters = from_chalk(db, proj.substitution); |
122 | Ty::Projection(ProjectionTy { associated_ty, parameters }) | 170 | Ty::Projection(ProjectionTy { associated_ty, parameters }) |
123 | } | 171 | } |
124 | chalk_ir::TyData::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { | 172 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { |
125 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); | 173 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); |
126 | let parameters = from_chalk(db, opaque_ty.substitution); | 174 | let parameters = from_chalk(db, opaque_ty.substitution); |
127 | Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) | 175 | Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) |
128 | } | 176 | } |
129 | chalk_ir::TyData::Function(chalk_ir::FnPointer { | 177 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
130 | num_binders, | 178 | num_binders, |
131 | sig: chalk_ir::FnSig { variadic, .. }, | 179 | sig: chalk_ir::FnSig { variadic, .. }, |
132 | substitution, | 180 | substitution, |
@@ -145,9 +193,9 @@ impl ToChalk for Ty { | |||
145 | parameters, | 193 | parameters, |
146 | }) | 194 | }) |
147 | } | 195 | } |
148 | chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx), | 196 | chalk_ir::TyKind::BoundVar(idx) => Ty::Bound(idx), |
149 | chalk_ir::TyData::InferenceVar(_iv, _kind) => Ty::Unknown, | 197 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, |
150 | chalk_ir::TyData::Dyn(where_clauses) => { | 198 | chalk_ir::TyKind::Dyn(where_clauses) => { |
151 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); | 199 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); |
152 | let predicates = where_clauses | 200 | let predicates = where_clauses |
153 | .bounds | 201 | .bounds |
@@ -157,10 +205,76 @@ impl ToChalk for Ty { | |||
157 | .collect(); | 205 | .collect(); |
158 | Ty::Dyn(predicates) | 206 | Ty::Dyn(predicates) |
159 | } | 207 | } |
208 | |||
209 | chalk_ir::TyKind::Adt(struct_id, subst) => { | ||
210 | apply_ty_from_chalk(db, TypeCtor::Adt(struct_id.0), subst) | ||
211 | } | ||
212 | chalk_ir::TyKind::AssociatedType(type_id, subst) => apply_ty_from_chalk( | ||
213 | db, | ||
214 | TypeCtor::AssociatedType(from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0), | ||
215 | subst, | ||
216 | ), | ||
217 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { | ||
218 | apply_ty_from_chalk(db, TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)), subst) | ||
219 | } | ||
220 | |||
221 | chalk_ir::TyKind::Scalar(Scalar::Bool) => Ty::simple(TypeCtor::Bool), | ||
222 | chalk_ir::TyKind::Scalar(Scalar::Char) => Ty::simple(TypeCtor::Char), | ||
223 | chalk_ir::TyKind::Scalar(Scalar::Int(int_ty)) => Ty::simple(TypeCtor::Int(IntTy { | ||
224 | signedness: Signedness::Signed, | ||
225 | bitness: bitness_from_chalk_int(int_ty), | ||
226 | })), | ||
227 | chalk_ir::TyKind::Scalar(Scalar::Uint(uint_ty)) => Ty::simple(TypeCtor::Int(IntTy { | ||
228 | signedness: Signedness::Unsigned, | ||
229 | bitness: bitness_from_chalk_uint(uint_ty), | ||
230 | })), | ||
231 | chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) => { | ||
232 | Ty::simple(TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 })) | ||
233 | } | ||
234 | chalk_ir::TyKind::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) => { | ||
235 | Ty::simple(TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 })) | ||
236 | } | ||
237 | chalk_ir::TyKind::Tuple(cardinality, subst) => { | ||
238 | apply_ty_from_chalk(db, TypeCtor::Tuple { cardinality: cardinality as u16 }, subst) | ||
239 | } | ||
240 | chalk_ir::TyKind::Raw(mutability, ty) => { | ||
241 | Ty::apply_one(TypeCtor::RawPtr(from_chalk(db, mutability)), from_chalk(db, ty)) | ||
242 | } | ||
243 | chalk_ir::TyKind::Slice(ty) => Ty::apply_one(TypeCtor::Slice, from_chalk(db, ty)), | ||
244 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { | ||
245 | Ty::apply_one(TypeCtor::Ref(from_chalk(db, mutability)), from_chalk(db, ty)) | ||
246 | } | ||
247 | chalk_ir::TyKind::Str => Ty::simple(TypeCtor::Str), | ||
248 | chalk_ir::TyKind::Never => Ty::simple(TypeCtor::Never), | ||
249 | |||
250 | chalk_ir::TyKind::FnDef(fn_def_id, subst) => { | ||
251 | let callable_def = from_chalk(db, fn_def_id); | ||
252 | apply_ty_from_chalk(db, TypeCtor::FnDef(callable_def), subst) | ||
253 | } | ||
254 | |||
255 | chalk_ir::TyKind::Closure(id, subst) => { | ||
256 | let id: crate::db::ClosureId = id.into(); | ||
257 | let (def, expr) = db.lookup_intern_closure(id); | ||
258 | apply_ty_from_chalk(db, TypeCtor::Closure { def, expr }, subst) | ||
259 | } | ||
260 | |||
261 | chalk_ir::TyKind::Foreign(foreign_def_id) => Ty::simple(TypeCtor::ForeignType( | ||
262 | from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0, | ||
263 | )), | ||
264 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME | ||
265 | chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME | ||
160 | } | 266 | } |
161 | } | 267 | } |
162 | } | 268 | } |
163 | 269 | ||
270 | fn apply_ty_from_chalk( | ||
271 | db: &dyn HirDatabase, | ||
272 | ctor: TypeCtor, | ||
273 | subst: chalk_ir::Substitution<Interner>, | ||
274 | ) -> Ty { | ||
275 | Ty::Apply(ApplicationTy { ctor, parameters: from_chalk(db, subst) }) | ||
276 | } | ||
277 | |||
164 | /// We currently don't model lifetimes, but Chalk does. So, we have to insert a | 278 | /// We currently don't model lifetimes, but Chalk does. So, we have to insert a |
165 | /// fake lifetime here, because Chalks built-in logic may expect it to be there. | 279 | /// fake lifetime here, because Chalks built-in logic may expect it to be there. |
166 | fn ref_to_chalk( | 280 | fn ref_to_chalk( |
@@ -170,60 +284,21 @@ fn ref_to_chalk( | |||
170 | ) -> chalk_ir::Ty<Interner> { | 284 | ) -> chalk_ir::Ty<Interner> { |
171 | let arg = subst[0].clone().to_chalk(db); | 285 | let arg = subst[0].clone().to_chalk(db); |
172 | let lifetime = LifetimeData::Static.intern(&Interner); | 286 | let lifetime = LifetimeData::Static.intern(&Interner); |
173 | chalk_ir::ApplicationTy { | 287 | chalk_ir::TyKind::Ref(mutability.to_chalk(db), lifetime, arg).intern(&Interner) |
174 | name: TypeName::Ref(mutability.to_chalk(db)), | ||
175 | substitution: chalk_ir::Substitution::from_iter( | ||
176 | &Interner, | ||
177 | vec![lifetime.cast(&Interner), arg.cast(&Interner)], | ||
178 | ), | ||
179 | } | ||
180 | .intern(&Interner) | ||
181 | } | ||
182 | |||
183 | /// Here we remove the lifetime from the type we got from Chalk. | ||
184 | fn ref_from_chalk( | ||
185 | db: &dyn HirDatabase, | ||
186 | mutability: chalk_ir::Mutability, | ||
187 | subst: chalk_ir::Substitution<Interner>, | ||
188 | ) -> Ty { | ||
189 | let tys = subst | ||
190 | .iter(&Interner) | ||
191 | .filter_map(|p| Some(from_chalk(db, p.ty(&Interner)?.clone()))) | ||
192 | .collect(); | ||
193 | Ty::apply(TypeCtor::Ref(from_chalk(db, mutability)), Substs(tys)) | ||
194 | } | 288 | } |
195 | 289 | ||
196 | /// We currently don't model constants, but Chalk does. So, we have to insert a | 290 | /// We currently don't model constants, but Chalk does. So, we have to insert a |
197 | /// fake constant here, because Chalks built-in logic may expect it to be there. | 291 | /// fake constant here, because Chalks built-in logic may expect it to be there. |
198 | fn array_to_chalk(db: &dyn HirDatabase, subst: Substs) -> chalk_ir::Ty<Interner> { | 292 | fn array_to_chalk(db: &dyn HirDatabase, subst: Substs) -> chalk_ir::Ty<Interner> { |
199 | let arg = subst[0].clone().to_chalk(db); | 293 | let arg = subst[0].clone().to_chalk(db); |
200 | let usize_ty = chalk_ir::ApplicationTy { | 294 | let usize_ty = |
201 | name: TypeName::Scalar(Scalar::Uint(chalk_ir::UintTy::Usize)), | 295 | chalk_ir::TyKind::Scalar(Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner); |
202 | substitution: chalk_ir::Substitution::empty(&Interner), | ||
203 | } | ||
204 | .intern(&Interner); | ||
205 | let const_ = chalk_ir::ConstData { | 296 | let const_ = chalk_ir::ConstData { |
206 | ty: usize_ty, | 297 | ty: usize_ty, |
207 | value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }), | 298 | value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }), |
208 | } | 299 | } |
209 | .intern(&Interner); | 300 | .intern(&Interner); |
210 | chalk_ir::ApplicationTy { | 301 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) |
211 | name: TypeName::Array, | ||
212 | substitution: chalk_ir::Substitution::from_iter( | ||
213 | &Interner, | ||
214 | vec![arg.cast(&Interner), const_.cast(&Interner)], | ||
215 | ), | ||
216 | } | ||
217 | .intern(&Interner) | ||
218 | } | ||
219 | |||
220 | /// Here we remove the const from the type we got from Chalk. | ||
221 | fn array_from_chalk(db: &dyn HirDatabase, subst: chalk_ir::Substitution<Interner>) -> Ty { | ||
222 | let tys = subst | ||
223 | .iter(&Interner) | ||
224 | .filter_map(|p| Some(from_chalk(db, p.ty(&Interner)?.clone()))) | ||
225 | .collect(); | ||
226 | Ty::apply(TypeCtor::Array, Substs(tys)) | ||
227 | } | 302 | } |
228 | 303 | ||
229 | impl ToChalk for Substs { | 304 | impl ToChalk for Substs { |
@@ -288,124 +363,6 @@ impl ToChalk for OpaqueTyId { | |||
288 | } | 363 | } |
289 | } | 364 | } |
290 | 365 | ||
291 | impl ToChalk for TypeCtor { | ||
292 | type Chalk = TypeName<Interner>; | ||
293 | |||
294 | fn to_chalk(self, db: &dyn HirDatabase) -> TypeName<Interner> { | ||
295 | match self { | ||
296 | TypeCtor::AssociatedType(type_alias) => { | ||
297 | let assoc_type = TypeAliasAsAssocType(type_alias); | ||
298 | let assoc_type_id = assoc_type.to_chalk(db); | ||
299 | TypeName::AssociatedType(assoc_type_id) | ||
300 | } | ||
301 | |||
302 | TypeCtor::OpaqueType(impl_trait_id) => { | ||
303 | let id = impl_trait_id.to_chalk(db); | ||
304 | TypeName::OpaqueType(id) | ||
305 | } | ||
306 | |||
307 | TypeCtor::ForeignType(type_alias) => { | ||
308 | let foreign_type = TypeAliasAsForeignType(type_alias); | ||
309 | let foreign_type_id = foreign_type.to_chalk(db); | ||
310 | TypeName::Foreign(foreign_type_id) | ||
311 | } | ||
312 | |||
313 | TypeCtor::Bool => TypeName::Scalar(Scalar::Bool), | ||
314 | TypeCtor::Char => TypeName::Scalar(Scalar::Char), | ||
315 | TypeCtor::Int(int_ty) => TypeName::Scalar(int_ty_to_chalk(int_ty)), | ||
316 | TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 }) => { | ||
317 | TypeName::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) | ||
318 | } | ||
319 | TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 }) => { | ||
320 | TypeName::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) | ||
321 | } | ||
322 | |||
323 | TypeCtor::Tuple { cardinality } => TypeName::Tuple(cardinality.into()), | ||
324 | TypeCtor::RawPtr(mutability) => TypeName::Raw(mutability.to_chalk(db)), | ||
325 | TypeCtor::Slice => TypeName::Slice, | ||
326 | TypeCtor::Array => TypeName::Array, | ||
327 | TypeCtor::Ref(mutability) => TypeName::Ref(mutability.to_chalk(db)), | ||
328 | TypeCtor::Str => TypeName::Str, | ||
329 | TypeCtor::FnDef(callable_def) => { | ||
330 | let id = callable_def.to_chalk(db); | ||
331 | TypeName::FnDef(id) | ||
332 | } | ||
333 | TypeCtor::Never => TypeName::Never, | ||
334 | |||
335 | TypeCtor::Closure { def, expr } => { | ||
336 | let closure_id = db.intern_closure((def, expr)); | ||
337 | TypeName::Closure(closure_id.into()) | ||
338 | } | ||
339 | |||
340 | TypeCtor::Adt(adt_id) => TypeName::Adt(chalk_ir::AdtId(adt_id)), | ||
341 | |||
342 | TypeCtor::FnPtr { .. } => { | ||
343 | // This should not be reached, since Chalk doesn't represent | ||
344 | // function pointers with TypeName | ||
345 | unreachable!() | ||
346 | } | ||
347 | } | ||
348 | } | ||
349 | |||
350 | fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor { | ||
351 | match type_name { | ||
352 | TypeName::Adt(struct_id) => TypeCtor::Adt(struct_id.0), | ||
353 | TypeName::AssociatedType(type_id) => { | ||
354 | TypeCtor::AssociatedType(from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0) | ||
355 | } | ||
356 | TypeName::OpaqueType(opaque_type_id) => { | ||
357 | TypeCtor::OpaqueType(from_chalk(db, opaque_type_id)) | ||
358 | } | ||
359 | |||
360 | TypeName::Scalar(Scalar::Bool) => TypeCtor::Bool, | ||
361 | TypeName::Scalar(Scalar::Char) => TypeCtor::Char, | ||
362 | TypeName::Scalar(Scalar::Int(int_ty)) => TypeCtor::Int(IntTy { | ||
363 | signedness: Signedness::Signed, | ||
364 | bitness: bitness_from_chalk_int(int_ty), | ||
365 | }), | ||
366 | TypeName::Scalar(Scalar::Uint(uint_ty)) => TypeCtor::Int(IntTy { | ||
367 | signedness: Signedness::Unsigned, | ||
368 | bitness: bitness_from_chalk_uint(uint_ty), | ||
369 | }), | ||
370 | TypeName::Scalar(Scalar::Float(chalk_ir::FloatTy::F32)) => { | ||
371 | TypeCtor::Float(FloatTy { bitness: FloatBitness::X32 }) | ||
372 | } | ||
373 | TypeName::Scalar(Scalar::Float(chalk_ir::FloatTy::F64)) => { | ||
374 | TypeCtor::Float(FloatTy { bitness: FloatBitness::X64 }) | ||
375 | } | ||
376 | TypeName::Tuple(cardinality) => TypeCtor::Tuple { cardinality: cardinality as u16 }, | ||
377 | TypeName::Raw(mutability) => TypeCtor::RawPtr(from_chalk(db, mutability)), | ||
378 | TypeName::Slice => TypeCtor::Slice, | ||
379 | TypeName::Ref(mutability) => TypeCtor::Ref(from_chalk(db, mutability)), | ||
380 | TypeName::Str => TypeCtor::Str, | ||
381 | TypeName::Never => TypeCtor::Never, | ||
382 | |||
383 | TypeName::FnDef(fn_def_id) => { | ||
384 | let callable_def = from_chalk(db, fn_def_id); | ||
385 | TypeCtor::FnDef(callable_def) | ||
386 | } | ||
387 | TypeName::Array => TypeCtor::Array, | ||
388 | |||
389 | TypeName::Closure(id) => { | ||
390 | let id: crate::db::ClosureId = id.into(); | ||
391 | let (def, expr) = db.lookup_intern_closure(id); | ||
392 | TypeCtor::Closure { def, expr } | ||
393 | } | ||
394 | |||
395 | TypeName::Foreign(foreign_def_id) => { | ||
396 | TypeCtor::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0) | ||
397 | } | ||
398 | |||
399 | TypeName::Error => { | ||
400 | // this should not be reached, since we don't represent TypeName::Error with TypeCtor | ||
401 | unreachable!() | ||
402 | } | ||
403 | TypeName::Generator(_) => unimplemented!(), // FIXME | ||
404 | TypeName::GeneratorWitness(_) => unimplemented!(), // FIXME | ||
405 | } | ||
406 | } | ||
407 | } | ||
408 | |||
409 | fn bitness_from_chalk_uint(uint_ty: chalk_ir::UintTy) -> IntBitness { | 366 | fn bitness_from_chalk_uint(uint_ty: chalk_ir::UintTy) -> IntBitness { |
410 | use chalk_ir::UintTy; | 367 | use chalk_ir::UintTy; |
411 | 368 | ||
@@ -507,7 +464,7 @@ impl ToChalk for CallableDefId { | |||
507 | } | 464 | } |
508 | } | 465 | } |
509 | 466 | ||
510 | pub struct TypeAliasAsAssocType(pub TypeAliasId); | 467 | pub(crate) struct TypeAliasAsAssocType(pub(crate) TypeAliasId); |
511 | 468 | ||
512 | impl ToChalk for TypeAliasAsAssocType { | 469 | impl ToChalk for TypeAliasAsAssocType { |
513 | type Chalk = AssocTypeId; | 470 | type Chalk = AssocTypeId; |
@@ -521,7 +478,7 @@ impl ToChalk for TypeAliasAsAssocType { | |||
521 | } | 478 | } |
522 | } | 479 | } |
523 | 480 | ||
524 | pub struct TypeAliasAsForeignType(pub TypeAliasId); | 481 | pub(crate) struct TypeAliasAsForeignType(pub(crate) TypeAliasId); |
525 | 482 | ||
526 | impl ToChalk for TypeAliasAsForeignType { | 483 | impl ToChalk for TypeAliasAsForeignType { |
527 | type Chalk = ForeignDefId; | 484 | type Chalk = ForeignDefId; |
@@ -535,7 +492,7 @@ impl ToChalk for TypeAliasAsForeignType { | |||
535 | } | 492 | } |
536 | } | 493 | } |
537 | 494 | ||
538 | pub struct TypeAliasAsValue(pub TypeAliasId); | 495 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); |
539 | 496 | ||
540 | impl ToChalk for TypeAliasAsValue { | 497 | impl ToChalk for TypeAliasAsValue { |
541 | type Chalk = AssociatedTyValueId; | 498 | type Chalk = AssociatedTyValueId; |
@@ -677,9 +634,9 @@ where | |||
677 | .kinds | 634 | .kinds |
678 | .iter() | 635 | .iter() |
679 | .map(|k| match k { | 636 | .map(|k| match k { |
680 | TyKind::General => chalk_ir::TyKind::General, | 637 | TyKind::General => chalk_ir::TyVariableKind::General, |
681 | TyKind::Integer => chalk_ir::TyKind::Integer, | 638 | TyKind::Integer => chalk_ir::TyVariableKind::Integer, |
682 | TyKind::Float => chalk_ir::TyKind::Float, | 639 | TyKind::Float => chalk_ir::TyVariableKind::Float, |
683 | }) | 640 | }) |
684 | .map(|tk| { | 641 | .map(|tk| { |
685 | chalk_ir::CanonicalVarKind::new( | 642 | chalk_ir::CanonicalVarKind::new( |
@@ -700,9 +657,9 @@ where | |||
700 | .iter(&Interner) | 657 | .iter(&Interner) |
701 | .map(|k| match k.kind { | 658 | .map(|k| match k.kind { |
702 | chalk_ir::VariableKind::Ty(tk) => match tk { | 659 | chalk_ir::VariableKind::Ty(tk) => match tk { |
703 | chalk_ir::TyKind::General => TyKind::General, | 660 | chalk_ir::TyVariableKind::General => TyKind::General, |
704 | chalk_ir::TyKind::Integer => TyKind::Integer, | 661 | chalk_ir::TyVariableKind::Integer => TyKind::Integer, |
705 | chalk_ir::TyKind::Float => TyKind::Float, | 662 | chalk_ir::TyVariableKind::Float => TyKind::Float, |
706 | }, | 663 | }, |
707 | chalk_ir::VariableKind::Lifetime => panic!("unexpected lifetime from Chalk"), | 664 | chalk_ir::VariableKind::Lifetime => panic!("unexpected lifetime from Chalk"), |
708 | chalk_ir::VariableKind::Const(_) => panic!("unexpected const from Chalk"), | 665 | chalk_ir::VariableKind::Const(_) => panic!("unexpected const from Chalk"), |
@@ -768,7 +725,8 @@ where | |||
768 | chalk_ir::Binders::new( | 725 | chalk_ir::Binders::new( |
769 | chalk_ir::VariableKinds::from_iter( | 726 | chalk_ir::VariableKinds::from_iter( |
770 | &Interner, | 727 | &Interner, |
771 | std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)).take(num_vars), | 728 | std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)) |
729 | .take(num_vars), | ||
772 | ), | 730 | ), |
773 | value, | 731 | value, |
774 | ) | 732 | ) |
diff --git a/crates/hir_ty/src/traits/chalk/tls.rs b/crates/hir_ty/src/traits/chalk/tls.rs index b4568cff6..75b16172e 100644 --- a/crates/hir_ty/src/traits/chalk/tls.rs +++ b/crates/hir_ty/src/traits/chalk/tls.rs | |||
@@ -1,114 +1,32 @@ | |||
1 | //! Implementation of Chalk debug helper functions using TLS. | 1 | //! Implementation of Chalk debug helper functions using TLS. |
2 | use std::fmt; | 2 | use std::fmt; |
3 | 3 | ||
4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication, TypeName}; | 4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; |
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | 6 | ||
7 | use super::{from_chalk, Interner, TypeAliasAsAssocType}; | 7 | use super::{from_chalk, Interner, TypeAliasAsAssocType}; |
8 | use crate::{db::HirDatabase, CallableDefId, TypeCtor}; | 8 | use crate::{db::HirDatabase, CallableDefId}; |
9 | use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId}; | 9 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; |
10 | 10 | ||
11 | pub use unsafe_tls::{set_current_program, with_current_program}; | 11 | pub(crate) use unsafe_tls::{set_current_program, with_current_program}; |
12 | 12 | ||
13 | pub struct DebugContext<'a>(&'a dyn HirDatabase); | 13 | pub(crate) struct DebugContext<'a>(&'a dyn HirDatabase); |
14 | 14 | ||
15 | impl DebugContext<'_> { | 15 | impl DebugContext<'_> { |
16 | pub fn debug_struct_id( | 16 | pub(crate) fn debug_struct_id( |
17 | &self, | 17 | &self, |
18 | id: super::AdtId, | 18 | id: super::AdtId, |
19 | f: &mut fmt::Formatter<'_>, | 19 | f: &mut fmt::Formatter<'_>, |
20 | ) -> Result<(), fmt::Error> { | 20 | ) -> Result<(), fmt::Error> { |
21 | let type_ctor: TypeCtor = from_chalk(self.0, TypeName::Adt(id)); | 21 | let name = match id.0 { |
22 | match type_ctor { | 22 | AdtId::StructId(it) => self.0.struct_data(it).name.clone(), |
23 | TypeCtor::Bool => write!(f, "bool")?, | 23 | AdtId::UnionId(it) => self.0.union_data(it).name.clone(), |
24 | TypeCtor::Char => write!(f, "char")?, | 24 | AdtId::EnumId(it) => self.0.enum_data(it).name.clone(), |
25 | TypeCtor::Int(t) => write!(f, "{}", t)?, | 25 | }; |
26 | TypeCtor::Float(t) => write!(f, "{}", t)?, | 26 | write!(f, "{}", name) |
27 | TypeCtor::Str => write!(f, "str")?, | ||
28 | TypeCtor::Slice => write!(f, "slice")?, | ||
29 | TypeCtor::Array => write!(f, "array")?, | ||
30 | TypeCtor::RawPtr(m) => write!(f, "*{}", m.as_keyword_for_ptr())?, | ||
31 | TypeCtor::Ref(m) => write!(f, "&{}", m.as_keyword_for_ref())?, | ||
32 | TypeCtor::Never => write!(f, "!")?, | ||
33 | TypeCtor::Tuple { .. } => { | ||
34 | write!(f, "()")?; | ||
35 | } | ||
36 | TypeCtor::FnPtr { .. } => { | ||
37 | write!(f, "fn")?; | ||
38 | } | ||
39 | TypeCtor::FnDef(def) => { | ||
40 | let name = match def { | ||
41 | CallableDefId::FunctionId(ff) => self.0.function_data(ff).name.clone(), | ||
42 | CallableDefId::StructId(s) => self.0.struct_data(s).name.clone(), | ||
43 | CallableDefId::EnumVariantId(e) => { | ||
44 | let enum_data = self.0.enum_data(e.parent); | ||
45 | enum_data.variants[e.local_id].name.clone() | ||
46 | } | ||
47 | }; | ||
48 | match def { | ||
49 | CallableDefId::FunctionId(_) => write!(f, "{{fn {}}}", name)?, | ||
50 | CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => { | ||
51 | write!(f, "{{ctor {}}}", name)? | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | TypeCtor::Adt(def_id) => { | ||
56 | let name = match def_id { | ||
57 | AdtId::StructId(it) => self.0.struct_data(it).name.clone(), | ||
58 | AdtId::UnionId(it) => self.0.union_data(it).name.clone(), | ||
59 | AdtId::EnumId(it) => self.0.enum_data(it).name.clone(), | ||
60 | }; | ||
61 | write!(f, "{}", name)?; | ||
62 | } | ||
63 | TypeCtor::AssociatedType(type_alias) => { | ||
64 | let trait_ = match type_alias.lookup(self.0.upcast()).container { | ||
65 | AssocContainerId::TraitId(it) => it, | ||
66 | _ => panic!("not an associated type"), | ||
67 | }; | ||
68 | let trait_name = self.0.trait_data(trait_).name.clone(); | ||
69 | let name = self.0.type_alias_data(type_alias).name.clone(); | ||
70 | write!(f, "{}::{}", trait_name, name)?; | ||
71 | } | ||
72 | TypeCtor::OpaqueType(opaque_ty_id) => match opaque_ty_id { | ||
73 | crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | ||
74 | write!(f, "{{impl trait {} of {:?}}}", idx, func)?; | ||
75 | } | ||
76 | crate::OpaqueTyId::AsyncBlockTypeImplTrait(def, idx) => { | ||
77 | write!(f, "{{impl trait of async block {} of {:?}}}", idx.into_raw(), def)?; | ||
78 | } | ||
79 | }, | ||
80 | TypeCtor::ForeignType(type_alias) => { | ||
81 | let name = self.0.type_alias_data(type_alias).name.clone(); | ||
82 | write!(f, "{}", name)?; | ||
83 | } | ||
84 | TypeCtor::Closure { def, expr } => { | ||
85 | write!(f, "{{closure {:?} in ", expr.into_raw())?; | ||
86 | match def { | ||
87 | DefWithBodyId::FunctionId(func) => { | ||
88 | write!(f, "fn {}", self.0.function_data(func).name)? | ||
89 | } | ||
90 | DefWithBodyId::StaticId(s) => { | ||
91 | if let Some(name) = self.0.static_data(s).name.as_ref() { | ||
92 | write!(f, "body of static {}", name)?; | ||
93 | } else { | ||
94 | write!(f, "body of unnamed static {:?}", s)?; | ||
95 | } | ||
96 | } | ||
97 | DefWithBodyId::ConstId(c) => { | ||
98 | if let Some(name) = self.0.const_data(c).name.as_ref() { | ||
99 | write!(f, "body of const {}", name)?; | ||
100 | } else { | ||
101 | write!(f, "body of unnamed const {:?}", c)?; | ||
102 | } | ||
103 | } | ||
104 | }; | ||
105 | write!(f, "}}")?; | ||
106 | } | ||
107 | } | ||
108 | Ok(()) | ||
109 | } | 27 | } |
110 | 28 | ||
111 | pub fn debug_trait_id( | 29 | pub(crate) fn debug_trait_id( |
112 | &self, | 30 | &self, |
113 | id: super::TraitId, | 31 | id: super::TraitId, |
114 | fmt: &mut fmt::Formatter<'_>, | 32 | fmt: &mut fmt::Formatter<'_>, |
@@ -118,7 +36,7 @@ impl DebugContext<'_> { | |||
118 | write!(fmt, "{}", trait_data.name) | 36 | write!(fmt, "{}", trait_data.name) |
119 | } | 37 | } |
120 | 38 | ||
121 | pub fn debug_assoc_type_id( | 39 | pub(crate) fn debug_assoc_type_id( |
122 | &self, | 40 | &self, |
123 | id: super::AssocTypeId, | 41 | id: super::AssocTypeId, |
124 | fmt: &mut fmt::Formatter<'_>, | 42 | fmt: &mut fmt::Formatter<'_>, |
@@ -133,7 +51,7 @@ impl DebugContext<'_> { | |||
133 | write!(fmt, "{}::{}", trait_data.name, type_alias_data.name) | 51 | write!(fmt, "{}::{}", trait_data.name, type_alias_data.name) |
134 | } | 52 | } |
135 | 53 | ||
136 | pub fn debug_opaque_ty_id( | 54 | pub(crate) fn debug_opaque_ty_id( |
137 | &self, | 55 | &self, |
138 | opaque_ty_id: chalk_ir::OpaqueTyId<Interner>, | 56 | opaque_ty_id: chalk_ir::OpaqueTyId<Interner>, |
139 | fmt: &mut fmt::Formatter<'_>, | 57 | fmt: &mut fmt::Formatter<'_>, |
@@ -141,7 +59,7 @@ impl DebugContext<'_> { | |||
141 | fmt.debug_struct("OpaqueTyId").field("index", &opaque_ty_id.0).finish() | 59 | fmt.debug_struct("OpaqueTyId").field("index", &opaque_ty_id.0).finish() |
142 | } | 60 | } |
143 | 61 | ||
144 | pub fn debug_alias( | 62 | pub(crate) fn debug_alias( |
145 | &self, | 63 | &self, |
146 | alias_ty: &AliasTy<Interner>, | 64 | alias_ty: &AliasTy<Interner>, |
147 | fmt: &mut fmt::Formatter<'_>, | 65 | fmt: &mut fmt::Formatter<'_>, |
@@ -152,7 +70,7 @@ impl DebugContext<'_> { | |||
152 | } | 70 | } |
153 | } | 71 | } |
154 | 72 | ||
155 | pub fn debug_projection_ty( | 73 | pub(crate) fn debug_projection_ty( |
156 | &self, | 74 | &self, |
157 | projection_ty: &chalk_ir::ProjectionTy<Interner>, | 75 | projection_ty: &chalk_ir::ProjectionTy<Interner>, |
158 | fmt: &mut fmt::Formatter<'_>, | 76 | fmt: &mut fmt::Formatter<'_>, |
@@ -177,7 +95,7 @@ impl DebugContext<'_> { | |||
177 | write!(fmt, ">::{}", type_alias_data.name) | 95 | write!(fmt, ">::{}", type_alias_data.name) |
178 | } | 96 | } |
179 | 97 | ||
180 | pub fn debug_opaque_ty( | 98 | pub(crate) fn debug_opaque_ty( |
181 | &self, | 99 | &self, |
182 | opaque_ty: &chalk_ir::OpaqueTy<Interner>, | 100 | opaque_ty: &chalk_ir::OpaqueTy<Interner>, |
183 | fmt: &mut fmt::Formatter<'_>, | 101 | fmt: &mut fmt::Formatter<'_>, |
@@ -185,7 +103,7 @@ impl DebugContext<'_> { | |||
185 | write!(fmt, "{:?}", opaque_ty.opaque_ty_id) | 103 | write!(fmt, "{:?}", opaque_ty.opaque_ty_id) |
186 | } | 104 | } |
187 | 105 | ||
188 | pub fn debug_ty( | 106 | pub(crate) fn debug_ty( |
189 | &self, | 107 | &self, |
190 | ty: &chalk_ir::Ty<Interner>, | 108 | ty: &chalk_ir::Ty<Interner>, |
191 | fmt: &mut fmt::Formatter<'_>, | 109 | fmt: &mut fmt::Formatter<'_>, |
@@ -193,7 +111,7 @@ impl DebugContext<'_> { | |||
193 | write!(fmt, "{:?}", ty.data(&Interner)) | 111 | write!(fmt, "{:?}", ty.data(&Interner)) |
194 | } | 112 | } |
195 | 113 | ||
196 | pub fn debug_lifetime( | 114 | pub(crate) fn debug_lifetime( |
197 | &self, | 115 | &self, |
198 | lifetime: &Lifetime<Interner>, | 116 | lifetime: &Lifetime<Interner>, |
199 | fmt: &mut fmt::Formatter<'_>, | 117 | fmt: &mut fmt::Formatter<'_>, |
@@ -201,7 +119,7 @@ impl DebugContext<'_> { | |||
201 | write!(fmt, "{:?}", lifetime.data(&Interner)) | 119 | write!(fmt, "{:?}", lifetime.data(&Interner)) |
202 | } | 120 | } |
203 | 121 | ||
204 | pub fn debug_generic_arg( | 122 | pub(crate) fn debug_generic_arg( |
205 | &self, | 123 | &self, |
206 | parameter: &GenericArg<Interner>, | 124 | parameter: &GenericArg<Interner>, |
207 | fmt: &mut fmt::Formatter<'_>, | 125 | fmt: &mut fmt::Formatter<'_>, |
@@ -209,7 +127,7 @@ impl DebugContext<'_> { | |||
209 | write!(fmt, "{:?}", parameter.data(&Interner).inner_debug()) | 127 | write!(fmt, "{:?}", parameter.data(&Interner).inner_debug()) |
210 | } | 128 | } |
211 | 129 | ||
212 | pub fn debug_goal( | 130 | pub(crate) fn debug_goal( |
213 | &self, | 131 | &self, |
214 | goal: &Goal<Interner>, | 132 | goal: &Goal<Interner>, |
215 | fmt: &mut fmt::Formatter<'_>, | 133 | fmt: &mut fmt::Formatter<'_>, |
@@ -218,7 +136,7 @@ impl DebugContext<'_> { | |||
218 | write!(fmt, "{:?}", goal_data) | 136 | write!(fmt, "{:?}", goal_data) |
219 | } | 137 | } |
220 | 138 | ||
221 | pub fn debug_goals( | 139 | pub(crate) fn debug_goals( |
222 | &self, | 140 | &self, |
223 | goals: &Goals<Interner>, | 141 | goals: &Goals<Interner>, |
224 | fmt: &mut fmt::Formatter<'_>, | 142 | fmt: &mut fmt::Formatter<'_>, |
@@ -226,7 +144,7 @@ impl DebugContext<'_> { | |||
226 | write!(fmt, "{:?}", goals.debug(&Interner)) | 144 | write!(fmt, "{:?}", goals.debug(&Interner)) |
227 | } | 145 | } |
228 | 146 | ||
229 | pub fn debug_program_clause_implication( | 147 | pub(crate) fn debug_program_clause_implication( |
230 | &self, | 148 | &self, |
231 | pci: &ProgramClauseImplication<Interner>, | 149 | pci: &ProgramClauseImplication<Interner>, |
232 | fmt: &mut fmt::Formatter<'_>, | 150 | fmt: &mut fmt::Formatter<'_>, |
@@ -234,15 +152,7 @@ impl DebugContext<'_> { | |||
234 | write!(fmt, "{:?}", pci.debug(&Interner)) | 152 | write!(fmt, "{:?}", pci.debug(&Interner)) |
235 | } | 153 | } |
236 | 154 | ||
237 | pub fn debug_application_ty( | 155 | pub(crate) fn debug_substitution( |
238 | &self, | ||
239 | application_ty: &chalk_ir::ApplicationTy<Interner>, | ||
240 | fmt: &mut fmt::Formatter<'_>, | ||
241 | ) -> Result<(), fmt::Error> { | ||
242 | write!(fmt, "{:?}", application_ty.debug(&Interner)) | ||
243 | } | ||
244 | |||
245 | pub fn debug_substitution( | ||
246 | &self, | 156 | &self, |
247 | substitution: &chalk_ir::Substitution<Interner>, | 157 | substitution: &chalk_ir::Substitution<Interner>, |
248 | fmt: &mut fmt::Formatter<'_>, | 158 | fmt: &mut fmt::Formatter<'_>, |
@@ -250,7 +160,7 @@ impl DebugContext<'_> { | |||
250 | write!(fmt, "{:?}", substitution.debug(&Interner)) | 160 | write!(fmt, "{:?}", substitution.debug(&Interner)) |
251 | } | 161 | } |
252 | 162 | ||
253 | pub fn debug_separator_trait_ref( | 163 | pub(crate) fn debug_separator_trait_ref( |
254 | &self, | 164 | &self, |
255 | separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>, | 165 | separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>, |
256 | fmt: &mut fmt::Formatter<'_>, | 166 | fmt: &mut fmt::Formatter<'_>, |
@@ -258,7 +168,7 @@ impl DebugContext<'_> { | |||
258 | write!(fmt, "{:?}", separator_trait_ref.debug(&Interner)) | 168 | write!(fmt, "{:?}", separator_trait_ref.debug(&Interner)) |
259 | } | 169 | } |
260 | 170 | ||
261 | pub fn debug_fn_def_id( | 171 | pub(crate) fn debug_fn_def_id( |
262 | &self, | 172 | &self, |
263 | fn_def_id: chalk_ir::FnDefId<Interner>, | 173 | fn_def_id: chalk_ir::FnDefId<Interner>, |
264 | fmt: &mut fmt::Formatter<'_>, | 174 | fmt: &mut fmt::Formatter<'_>, |
@@ -280,7 +190,7 @@ impl DebugContext<'_> { | |||
280 | } | 190 | } |
281 | } | 191 | } |
282 | 192 | ||
283 | pub fn debug_const( | 193 | pub(crate) fn debug_const( |
284 | &self, | 194 | &self, |
285 | _constant: &chalk_ir::Const<Interner>, | 195 | _constant: &chalk_ir::Const<Interner>, |
286 | fmt: &mut fmt::Formatter<'_>, | 196 | fmt: &mut fmt::Formatter<'_>, |
@@ -288,42 +198,42 @@ impl DebugContext<'_> { | |||
288 | write!(fmt, "const") | 198 | write!(fmt, "const") |
289 | } | 199 | } |
290 | 200 | ||
291 | pub fn debug_variable_kinds( | 201 | pub(crate) fn debug_variable_kinds( |
292 | &self, | 202 | &self, |
293 | variable_kinds: &chalk_ir::VariableKinds<Interner>, | 203 | variable_kinds: &chalk_ir::VariableKinds<Interner>, |
294 | fmt: &mut fmt::Formatter<'_>, | 204 | fmt: &mut fmt::Formatter<'_>, |
295 | ) -> fmt::Result { | 205 | ) -> fmt::Result { |
296 | write!(fmt, "{:?}", variable_kinds.as_slice(&Interner)) | 206 | write!(fmt, "{:?}", variable_kinds.as_slice(&Interner)) |
297 | } | 207 | } |
298 | pub fn debug_variable_kinds_with_angles( | 208 | pub(crate) fn debug_variable_kinds_with_angles( |
299 | &self, | 209 | &self, |
300 | variable_kinds: &chalk_ir::VariableKinds<Interner>, | 210 | variable_kinds: &chalk_ir::VariableKinds<Interner>, |
301 | fmt: &mut fmt::Formatter<'_>, | 211 | fmt: &mut fmt::Formatter<'_>, |
302 | ) -> fmt::Result { | 212 | ) -> fmt::Result { |
303 | write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner)) | 213 | write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner)) |
304 | } | 214 | } |
305 | pub fn debug_canonical_var_kinds( | 215 | pub(crate) fn debug_canonical_var_kinds( |
306 | &self, | 216 | &self, |
307 | canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Interner>, | 217 | canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Interner>, |
308 | fmt: &mut fmt::Formatter<'_>, | 218 | fmt: &mut fmt::Formatter<'_>, |
309 | ) -> fmt::Result { | 219 | ) -> fmt::Result { |
310 | write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner)) | 220 | write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner)) |
311 | } | 221 | } |
312 | pub fn debug_program_clause( | 222 | pub(crate) fn debug_program_clause( |
313 | &self, | 223 | &self, |
314 | clause: &chalk_ir::ProgramClause<Interner>, | 224 | clause: &chalk_ir::ProgramClause<Interner>, |
315 | fmt: &mut fmt::Formatter<'_>, | 225 | fmt: &mut fmt::Formatter<'_>, |
316 | ) -> fmt::Result { | 226 | ) -> fmt::Result { |
317 | write!(fmt, "{:?}", clause.data(&Interner)) | 227 | write!(fmt, "{:?}", clause.data(&Interner)) |
318 | } | 228 | } |
319 | pub fn debug_program_clauses( | 229 | pub(crate) fn debug_program_clauses( |
320 | &self, | 230 | &self, |
321 | clauses: &chalk_ir::ProgramClauses<Interner>, | 231 | clauses: &chalk_ir::ProgramClauses<Interner>, |
322 | fmt: &mut fmt::Formatter<'_>, | 232 | fmt: &mut fmt::Formatter<'_>, |
323 | ) -> fmt::Result { | 233 | ) -> fmt::Result { |
324 | write!(fmt, "{:?}", clauses.as_slice(&Interner)) | 234 | write!(fmt, "{:?}", clauses.as_slice(&Interner)) |
325 | } | 235 | } |
326 | pub fn debug_quantified_where_clauses( | 236 | pub(crate) fn debug_quantified_where_clauses( |
327 | &self, | 237 | &self, |
328 | clauses: &chalk_ir::QuantifiedWhereClauses<Interner>, | 238 | clauses: &chalk_ir::QuantifiedWhereClauses<Interner>, |
329 | fmt: &mut fmt::Formatter<'_>, | 239 | fmt: &mut fmt::Formatter<'_>, |
@@ -339,7 +249,7 @@ mod unsafe_tls { | |||
339 | 249 | ||
340 | scoped_thread_local!(static PROGRAM: DebugContext); | 250 | scoped_thread_local!(static PROGRAM: DebugContext); |
341 | 251 | ||
342 | pub fn with_current_program<R>( | 252 | pub(crate) fn with_current_program<R>( |
343 | op: impl for<'a> FnOnce(Option<&'a DebugContext<'a>>) -> R, | 253 | op: impl for<'a> FnOnce(Option<&'a DebugContext<'a>>) -> R, |
344 | ) -> R { | 254 | ) -> R { |
345 | if PROGRAM.is_set() { | 255 | if PROGRAM.is_set() { |
@@ -349,7 +259,7 @@ mod unsafe_tls { | |||
349 | } | 259 | } |
350 | } | 260 | } |
351 | 261 | ||
352 | pub fn set_current_program<OP, R>(p: &dyn HirDatabase, op: OP) -> R | 262 | pub(crate) fn set_current_program<OP, R>(p: &dyn HirDatabase, op: OP) -> R |
353 | where | 263 | where |
354 | OP: FnOnce() -> R, | 264 | OP: FnOnce() -> R, |
355 | { | 265 | { |
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 0c950003e..02e17ba43 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs | |||
@@ -25,7 +25,7 @@ use crate::{diagnostics::Fix, references::rename::rename_with_semantics, FilePos | |||
25 | /// A [Diagnostic] that potentially has a fix available. | 25 | /// A [Diagnostic] that potentially has a fix available. |
26 | /// | 26 | /// |
27 | /// [Diagnostic]: hir::diagnostics::Diagnostic | 27 | /// [Diagnostic]: hir::diagnostics::Diagnostic |
28 | pub trait DiagnosticWithFix: Diagnostic { | 28 | pub(crate) trait DiagnosticWithFix: Diagnostic { |
29 | fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix>; | 29 | fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix>; |
30 | } | 30 | } |
31 | 31 | ||
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 250f10f9f..10263537a 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! Resolves and rewrites links in markdown documentation. | 1 | //! Resolves and rewrites links in markdown documentation. |
2 | 2 | ||
3 | use std::convert::TryFrom; | 3 | use std::{convert::TryFrom, iter::once}; |
4 | use std::iter::once; | ||
5 | 4 | ||
6 | use itertools::Itertools; | 5 | use itertools::Itertools; |
7 | use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag}; | 6 | use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag}; |
@@ -21,10 +20,10 @@ use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, | |||
21 | 20 | ||
22 | use crate::{FilePosition, Semantics}; | 21 | use crate::{FilePosition, Semantics}; |
23 | 22 | ||
24 | pub type DocumentationLink = String; | 23 | pub(crate) type DocumentationLink = String; |
25 | 24 | ||
26 | /// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs) | 25 | /// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs) |
27 | pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String { | 26 | pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String { |
28 | let mut cb = |link: BrokenLink| { | 27 | let mut cb = |link: BrokenLink| { |
29 | Some(( | 28 | Some(( |
30 | /*url*/ link.reference.to_owned().into(), | 29 | /*url*/ link.reference.to_owned().into(), |
@@ -63,7 +62,7 @@ pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) | |||
63 | } | 62 | } |
64 | 63 | ||
65 | /// Remove all links in markdown documentation. | 64 | /// Remove all links in markdown documentation. |
66 | pub fn remove_links(markdown: &str) -> String { | 65 | pub(crate) fn remove_links(markdown: &str) -> String { |
67 | let mut drop_link = false; | 66 | let mut drop_link = false; |
68 | 67 | ||
69 | let mut opts = Options::empty(); | 68 | let mut opts = Options::empty(); |
diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index 6168fb837..415795e8c 100644 --- a/crates/ide/src/file_structure.rs +++ b/crates/ide/src/file_structure.rs | |||
@@ -27,7 +27,7 @@ pub struct StructureNode { | |||
27 | // | 27 | // |
28 | // | VS Code | kbd:[Ctrl+Shift+O] | 28 | // | VS Code | kbd:[Ctrl+Shift+O] |
29 | // |=== | 29 | // |=== |
30 | pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> { | 30 | pub(crate) fn file_structure(file: &SourceFile) -> Vec<StructureNode> { |
31 | let mut res = Vec::new(); | 31 | let mut res = Vec::new(); |
32 | let mut stack = Vec::new(); | 32 | let mut stack = Vec::new(); |
33 | 33 | ||
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index b6113bda2..ac704ae21 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -1339,4 +1339,25 @@ fn main() { | |||
1339 | "#, | 1339 | "#, |
1340 | ); | 1340 | ); |
1341 | } | 1341 | } |
1342 | |||
1343 | #[test] | ||
1344 | fn infer_call_method_return_associated_types_with_generic() { | ||
1345 | check( | ||
1346 | r#" | ||
1347 | pub trait Default { | ||
1348 | fn default() -> Self; | ||
1349 | } | ||
1350 | pub trait Foo { | ||
1351 | type Bar: Default; | ||
1352 | } | ||
1353 | |||
1354 | pub fn quux<T: Foo>() -> T::Bar { | ||
1355 | let y = Default::default(); | ||
1356 | //^ <T as Foo>::Bar | ||
1357 | |||
1358 | y | ||
1359 | } | ||
1360 | "#, | ||
1361 | ); | ||
1362 | } | ||
1342 | } | 1363 | } |
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs index e37702acd..b5a6f66fd 100644 --- a/crates/ide/src/join_lines.rs +++ b/crates/ide/src/join_lines.rs | |||
@@ -18,7 +18,7 @@ use text_edit::{TextEdit, TextEditBuilder}; | |||
18 | // | 18 | // |
19 | // | VS Code | **Rust Analyzer: Join lines** | 19 | // | VS Code | **Rust Analyzer: Join lines** |
20 | // |=== | 20 | // |=== |
21 | pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit { | 21 | pub(crate) fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit { |
22 | let range = if range.is_empty() { | 22 | let range = if range.is_empty() { |
23 | let syntax = file.syntax(); | 23 | let syntax = file.syntax(); |
24 | let text = syntax.text().slice(range.start()..); | 24 | let text = syntax.text().slice(range.start()..); |
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 4bc733b70..6288f7ea7 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -72,18 +72,20 @@ pub use crate::{ | |||
72 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, | 72 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, |
73 | markup::Markup, | 73 | markup::Markup, |
74 | prime_caches::PrimeCachesProgress, | 74 | prime_caches::PrimeCachesProgress, |
75 | references::{ | 75 | references::{rename::RenameError, Declaration, ReferenceSearchResult}, |
76 | Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult, RenameError, | ||
77 | }, | ||
78 | runnables::{Runnable, RunnableKind, TestId}, | 76 | runnables::{Runnable, RunnableKind, TestId}, |
79 | syntax_highlighting::{ | 77 | syntax_highlighting::{ |
80 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, | 78 | tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}, |
79 | HighlightedRange, | ||
81 | }, | 80 | }, |
82 | }; | 81 | }; |
83 | pub use completion::{ | 82 | pub use completion::{ |
84 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, | 83 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, |
85 | }; | 84 | }; |
86 | pub use ide_db::call_info::CallInfo; | 85 | pub use ide_db::{ |
86 | call_info::CallInfo, | ||
87 | search::{Reference, ReferenceAccess, ReferenceKind}, | ||
88 | }; | ||
87 | 89 | ||
88 | pub use assists::{ | 90 | pub use assists::{ |
89 | utils::MergeBehaviour, Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist, | 91 | utils::MergeBehaviour, Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist, |
@@ -503,7 +505,7 @@ impl Analysis { | |||
503 | position: FilePosition, | 505 | position: FilePosition, |
504 | new_name: &str, | 506 | new_name: &str, |
505 | ) -> Cancelable<Result<RangeInfo<SourceChange>, RenameError>> { | 507 | ) -> Cancelable<Result<RangeInfo<SourceChange>, RenameError>> { |
506 | self.with_db(|db| references::rename(db, position, new_name)) | 508 | self.with_db(|db| references::rename::rename(db, position, new_name)) |
507 | } | 509 | } |
508 | 510 | ||
509 | pub fn structural_search_replace( | 511 | pub fn structural_search_replace( |
diff --git a/crates/ide/src/markdown_remove.rs b/crates/ide/src/markdown_remove.rs index 02ad39dfb..3ec5c629e 100644 --- a/crates/ide/src/markdown_remove.rs +++ b/crates/ide/src/markdown_remove.rs | |||
@@ -1,11 +1,10 @@ | |||
1 | //! Removes markdown from strings. | 1 | //! Removes markdown from strings. |
2 | |||
3 | use pulldown_cmark::{Event, Parser, Tag}; | 2 | use pulldown_cmark::{Event, Parser, Tag}; |
4 | 3 | ||
5 | /// Removes all markdown, keeping the text and code blocks | 4 | /// Removes all markdown, keeping the text and code blocks |
6 | /// | 5 | /// |
7 | /// Currently limited in styling, i.e. no ascii tables or lists | 6 | /// Currently limited in styling, i.e. no ascii tables or lists |
8 | pub fn remove_markdown(markdown: &str) -> String { | 7 | pub(crate) fn remove_markdown(markdown: &str) -> String { |
9 | let mut out = String::new(); | 8 | let mut out = String::new(); |
10 | let parser = Parser::new(markdown); | 9 | let parser = Parser::new(markdown); |
11 | 10 | ||
diff --git a/crates/ide/src/matching_brace.rs b/crates/ide/src/matching_brace.rs index cb6abb0db..d70248afe 100644 --- a/crates/ide/src/matching_brace.rs +++ b/crates/ide/src/matching_brace.rs | |||
@@ -15,7 +15,7 @@ use test_utils::mark; | |||
15 | // | 15 | // |
16 | // | VS Code | **Rust Analyzer: Find matching brace** | 16 | // | VS Code | **Rust Analyzer: Find matching brace** |
17 | // |=== | 17 | // |=== |
18 | pub fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> { | 18 | pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> { |
19 | const BRACES: &[SyntaxKind] = | 19 | const BRACES: &[SyntaxKind] = |
20 | &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]]; | 20 | &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]]; |
21 | let (brace_token, brace_idx) = file | 21 | let (brace_token, brace_idx) = file |
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index a517081d5..e05465b32 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -14,7 +14,8 @@ pub(crate) mod rename; | |||
14 | use hir::Semantics; | 14 | use hir::Semantics; |
15 | use ide_db::{ | 15 | use ide_db::{ |
16 | defs::{Definition, NameClass, NameRefClass}, | 16 | defs::{Definition, NameClass, NameRefClass}, |
17 | search::SearchScope, | 17 | search::Reference, |
18 | search::{ReferenceAccess, ReferenceKind, SearchScope}, | ||
18 | RootDatabase, | 19 | RootDatabase, |
19 | }; | 20 | }; |
20 | use syntax::{ | 21 | use syntax::{ |
@@ -25,11 +26,6 @@ use syntax::{ | |||
25 | 26 | ||
26 | use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; | 27 | use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo}; |
27 | 28 | ||
28 | pub(crate) use self::rename::rename; | ||
29 | pub use self::rename::RenameError; | ||
30 | |||
31 | pub use ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; | ||
32 | |||
33 | #[derive(Debug, Clone)] | 29 | #[derive(Debug, Clone)] |
34 | pub struct ReferenceSearchResult { | 30 | pub struct ReferenceSearchResult { |
35 | declaration: Declaration, | 31 | declaration: Declaration, |
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index eb82456ad..2bd0e86e5 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -102,6 +102,7 @@ pub(crate) fn runnable( | |||
102 | ) -> Option<Runnable> { | 102 | ) -> Option<Runnable> { |
103 | match_ast! { | 103 | match_ast! { |
104 | match item { | 104 | match item { |
105 | ast::Struct(it) => runnable_struct(sema, it, file_id), | ||
105 | ast::Fn(it) => runnable_fn(sema, it, file_id), | 106 | ast::Fn(it) => runnable_fn(sema, it, file_id), |
106 | ast::Module(it) => runnable_mod(sema, it, file_id), | 107 | ast::Module(it) => runnable_mod(sema, it, file_id), |
107 | _ => None, | 108 | _ => None, |
@@ -182,6 +183,43 @@ fn runnable_fn( | |||
182 | Some(Runnable { nav, kind, cfg }) | 183 | Some(Runnable { nav, kind, cfg }) |
183 | } | 184 | } |
184 | 185 | ||
186 | fn runnable_struct( | ||
187 | sema: &Semantics<RootDatabase>, | ||
188 | struct_def: ast::Struct, | ||
189 | file_id: FileId, | ||
190 | ) -> Option<Runnable> { | ||
191 | if !has_runnable_doc_test(&struct_def) { | ||
192 | return None; | ||
193 | } | ||
194 | let name_string = struct_def.name()?.text().to_string(); | ||
195 | |||
196 | let attrs = | ||
197 | Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def)); | ||
198 | let cfg = attrs.cfg(); | ||
199 | |||
200 | let test_id = match sema.to_def(&struct_def).map(|def| def.module(sema.db)) { | ||
201 | Some(module) => { | ||
202 | let path_iter = module | ||
203 | .path_to_root(sema.db) | ||
204 | .into_iter() | ||
205 | .rev() | ||
206 | .filter_map(|it| it.name(sema.db)) | ||
207 | .map(|name| name.to_string()); | ||
208 | let path = path_iter.chain(std::iter::once(name_string)).join("::"); | ||
209 | |||
210 | TestId::Path(path) | ||
211 | } | ||
212 | None => TestId::Name(name_string), | ||
213 | }; | ||
214 | |||
215 | let nav = NavigationTarget::from_doc_commented( | ||
216 | sema.db, | ||
217 | InFile::new(file_id.into(), &struct_def), | ||
218 | InFile::new(file_id.into(), &struct_def), | ||
219 | ); | ||
220 | Some(Runnable { nav, kind: RunnableKind::DocTest { test_id }, cfg }) | ||
221 | } | ||
222 | |||
185 | #[derive(Debug, Copy, Clone)] | 223 | #[derive(Debug, Copy, Clone)] |
186 | pub struct TestAttr { | 224 | pub struct TestAttr { |
187 | pub ignore: bool, | 225 | pub ignore: bool, |
@@ -215,8 +253,8 @@ const RUSTDOC_FENCE: &str = "```"; | |||
215 | const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] = | 253 | const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] = |
216 | &["", "rust", "should_panic", "edition2015", "edition2018"]; | 254 | &["", "rust", "should_panic", "edition2015", "edition2018"]; |
217 | 255 | ||
218 | fn has_runnable_doc_test(fn_def: &ast::Fn) -> bool { | 256 | fn has_runnable_doc_test(def: &dyn DocCommentsOwner) -> bool { |
219 | fn_def.doc_comment_text().map_or(false, |comments_text| { | 257 | def.doc_comment_text().map_or(false, |comments_text| { |
220 | let mut in_code_block = false; | 258 | let mut in_code_block = false; |
221 | 259 | ||
222 | for line in comments_text.lines() { | 260 | for line in comments_text.lines() { |
@@ -487,8 +525,14 @@ fn should_have_no_runnable_5() {} | |||
487 | /// let z = 55; | 525 | /// let z = 55; |
488 | /// ``` | 526 | /// ``` |
489 | fn should_have_no_runnable_6() {} | 527 | fn should_have_no_runnable_6() {} |
528 | |||
529 | /// ``` | ||
530 | /// let x = 5; | ||
531 | /// ``` | ||
532 | struct StructWithRunnable(String); | ||
533 | |||
490 | "#, | 534 | "#, |
491 | &[&BIN, &DOCTEST, &DOCTEST, &DOCTEST], | 535 | &[&BIN, &DOCTEST, &DOCTEST, &DOCTEST, &DOCTEST], |
492 | expect![[r#" | 536 | expect![[r#" |
493 | [ | 537 | [ |
494 | Runnable { | 538 | Runnable { |
@@ -569,6 +613,26 @@ fn should_have_no_runnable_6() {} | |||
569 | }, | 613 | }, |
570 | cfg: None, | 614 | cfg: None, |
571 | }, | 615 | }, |
616 | Runnable { | ||
617 | nav: NavigationTarget { | ||
618 | file_id: FileId( | ||
619 | 0, | ||
620 | ), | ||
621 | full_range: 756..821, | ||
622 | focus_range: None, | ||
623 | name: "StructWithRunnable", | ||
624 | kind: STRUCT, | ||
625 | container_name: None, | ||
626 | description: None, | ||
627 | docs: None, | ||
628 | }, | ||
629 | kind: DocTest { | ||
630 | test_id: Path( | ||
631 | "StructWithRunnable", | ||
632 | ), | ||
633 | }, | ||
634 | cfg: None, | ||
635 | }, | ||
572 | ] | 636 | ] |
573 | "#]], | 637 | "#]], |
574 | ); | 638 | ); |
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 624a63075..efcc8ecfe 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs | |||
@@ -2,7 +2,7 @@ mod format; | |||
2 | mod html; | 2 | mod html; |
3 | mod injection; | 3 | mod injection; |
4 | mod macro_rules; | 4 | mod macro_rules; |
5 | mod tags; | 5 | pub(crate) mod tags; |
6 | #[cfg(test)] | 6 | #[cfg(test)] |