aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock42
-rw-r--r--crates/ra_hir/src/adt.rs176
-rw-r--r--crates/ra_hir/src/code_model.rs31
-rw-r--r--crates/ra_hir/src/code_model/src.rs42
-rw-r--r--crates/ra_hir/src/db.rs15
-rw-r--r--crates/ra_hir/src/ty/lower.rs8
-rw-r--r--crates/ra_hir_def/src/adt.rs114
-rw-r--r--crates/ra_hir_def/src/db.rs12
-rw-r--r--crates/ra_hir_def/src/lib.rs17
9 files changed, 240 insertions, 217 deletions
diff --git a/Cargo.lock b/Cargo.lock
index fdacd82a7..10f51403a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -272,7 +272,7 @@ dependencies = [
272 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 272 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
273 "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", 273 "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
274 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 274 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
275 "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 275 "memoffset 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
276 "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 276 "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
277] 277]
278 278
@@ -455,7 +455,15 @@ name = "heck"
455version = "0.3.1" 455version = "0.3.1"
456source = "registry+https://github.com/rust-lang/crates.io-index" 456source = "registry+https://github.com/rust-lang/crates.io-index"
457dependencies = [ 457dependencies = [
458 "unicode-segmentation 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 458 "unicode-segmentation 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
459]
460
461[[package]]
462name = "hermit-abi"
463version = "0.1.3"
464source = "registry+https://github.com/rust-lang/crates.io-index"
465dependencies = [
466 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
459] 467]
460 468
461[[package]] 469[[package]]
@@ -664,7 +672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
664 672
665[[package]] 673[[package]]
666name = "memoffset" 674name = "memoffset"
667version = "0.5.1" 675version = "0.5.2"
668source = "registry+https://github.com/rust-lang/crates.io-index" 676source = "registry+https://github.com/rust-lang/crates.io-index"
669dependencies = [ 677dependencies = [
670 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 678 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -761,9 +769,10 @@ dependencies = [
761 769
762[[package]] 770[[package]]
763name = "num_cpus" 771name = "num_cpus"
764version = "1.10.1" 772version = "1.11.0"
765source = "registry+https://github.com/rust-lang/crates.io-index" 773source = "registry+https://github.com/rust-lang/crates.io-index"
766dependencies = [ 774dependencies = [
775 "hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
767 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 776 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
768] 777]
769 778
@@ -802,7 +811,7 @@ dependencies = [
802 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 811 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
803 "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", 812 "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
804 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 813 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
805 "smallvec 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", 814 "smallvec 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
806 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 815 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
807] 816]
808 817
@@ -1111,7 +1120,7 @@ dependencies = [
1111 "ra_syntax 0.1.0", 1120 "ra_syntax 0.1.0",
1112 "ra_tt 0.1.0", 1121 "ra_tt 0.1.0",
1113 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 1122 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1114 "smallvec 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", 1123 "smallvec 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
1115 "test_utils 0.1.0", 1124 "test_utils 0.1.0",
1116] 1125]
1117 1126
@@ -1364,7 +1373,7 @@ dependencies = [
1364 "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 1373 "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
1365 "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", 1374 "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
1366 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1375 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1367 "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", 1376 "num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
1368] 1377]
1369 1378
1370[[package]] 1379[[package]]
@@ -1476,7 +1485,7 @@ dependencies = [
1476 "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 1485 "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
1477 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 1486 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1478 "salsa-macros 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", 1487 "salsa-macros 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
1479 "smallvec 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", 1488 "smallvec 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
1480] 1489]
1481 1490
1482[[package]] 1491[[package]]
@@ -1573,7 +1582,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1573 1582
1574[[package]] 1583[[package]]
1575name = "smallvec" 1584name = "smallvec"
1576version = "0.6.11" 1585version = "0.6.12"
1577source = "registry+https://github.com/rust-lang/crates.io-index" 1586source = "registry+https://github.com/rust-lang/crates.io-index"
1578 1587
1579[[package]] 1588[[package]]
@@ -1659,7 +1668,7 @@ name = "threadpool"
1659version = "1.7.1" 1668version = "1.7.1"
1660source = "registry+https://github.com/rust-lang/crates.io-index" 1669source = "registry+https://github.com/rust-lang/crates.io-index"
1661dependencies = [ 1670dependencies = [
1662 "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", 1671 "num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
1663] 1672]
1664 1673
1665[[package]] 1674[[package]]
@@ -1693,12 +1702,12 @@ name = "unicode-normalization"
1693version = "0.1.8" 1702version = "0.1.8"
1694source = "registry+https://github.com/rust-lang/crates.io-index" 1703source = "registry+https://github.com/rust-lang/crates.io-index"
1695dependencies = [ 1704dependencies = [
1696 "smallvec 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", 1705 "smallvec 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
1697] 1706]
1698 1707
1699[[package]] 1708[[package]]
1700name = "unicode-segmentation" 1709name = "unicode-segmentation"
1701version = "1.4.0" 1710version = "1.5.0"
1702source = "registry+https://github.com/rust-lang/crates.io-index" 1711source = "registry+https://github.com/rust-lang/crates.io-index"
1703 1712
1704[[package]] 1713[[package]]
@@ -1879,6 +1888,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1879"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" 1888"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
1880"checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" 1889"checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2"
1881"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 1890"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
1891"checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120"
1882"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" 1892"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
1883"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" 1893"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2"
1884"checksum indicatif 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8d596a9576eaa1446996092642d72bfef35cf47243129b7ab883baf5faec31e" 1894"checksum indicatif 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8d596a9576eaa1446996092642d72bfef35cf47243129b7ab883baf5faec31e"
@@ -1905,7 +1915,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1905"checksum lsp-types 0.61.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa3268fbe8beb2795c2fb327bf44f4f3d24f5fe9ebc18d7e2980afd444d72bcf" 1915"checksum lsp-types 0.61.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa3268fbe8beb2795c2fb327bf44f4f3d24f5fe9ebc18d7e2980afd444d72bcf"
1906"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" 1916"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
1907"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" 1917"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
1908"checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f" 1918"checksum memoffset 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a85c1a8c329f11437034d7313dca647c79096523533a1c79e86f1d0f657c7cc"
1909"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" 1919"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23"
1910"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" 1920"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40"
1911"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" 1921"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
@@ -1914,7 +1924,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1914"checksum notify 4.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "199628fc33b21bc767baa057490b00b382ecbae030803a7b36292422d15b778b" 1924"checksum notify 4.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "199628fc33b21bc767baa057490b00b382ecbae030803a7b36292422d15b778b"
1915"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" 1925"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
1916"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" 1926"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
1917"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" 1927"checksum num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "155394f924cdddf08149da25bfb932d226b4a593ca7468b08191ff6335941af5"
1918"checksum number_prefix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" 1928"checksum number_prefix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a"
1919"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed" 1929"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed"
1920"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" 1930"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
@@ -1975,7 +1985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1975"checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" 1985"checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573"
1976"checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35" 1986"checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35"
1977"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" 1987"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
1978"checksum smallvec 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cefaa50e76a6f10b86f36e640eb1739eafbd4084865067778463913e43a77ff3" 1988"checksum smallvec 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "533e29e15d0748f28afbaf4ff7cab44d73e483a8e50b38c40bd13b7f3d48f542"
1979"checksum smol_str 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "34836c9a295c62c2ce3514471117c5cb269891e8421b2aafdd910050576c4d8b" 1989"checksum smol_str 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "34836c9a295c62c2ce3514471117c5cb269891e8421b2aafdd910050576c4d8b"
1980"checksum stacker 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d96fc4f13a0ac088e9a3cd9af1cc8c5cc1ab5deb2145cef661267dfc9c542f8a" 1990"checksum stacker 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d96fc4f13a0ac088e9a3cd9af1cc8c5cc1ab5deb2145cef661267dfc9c542f8a"
1981"checksum superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" 1991"checksum superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
@@ -1989,7 +1999,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1989"checksum unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150" 1999"checksum unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150"
1990"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" 2000"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
1991"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" 2001"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426"
1992"checksum unicode-segmentation 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc5415c074426c7c65db13bd647c23d78c0fb2e10dca0b8fb0f40058a59bccdf" 2002"checksum unicode-segmentation 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49f5526225fd8b77342d5986ab5f6055552e9c0776193b5b63fd53b46debfad7"
1993"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" 2003"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
1994"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" 2004"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
1995"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" 2005"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61"
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 4fa2062bd..0436d20b7 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -3,152 +3,16 @@
3 3
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use hir_def::{type_ref::TypeRef, LocalEnumVariantId}; 6use hir_def::adt::VariantData;
7use hir_expand::name::AsName;
8use ra_arena::{impl_arena_id, Arena, RawId};
9use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner};
10 7
11use crate::{ 8use crate::{
12 db::{AstDatabase, DefDatabase, HirDatabase}, 9 db::{DefDatabase, HirDatabase},
13 Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField, 10 EnumVariant, Module, Name, Struct, StructField,
14}; 11};
15 12
16impl Struct { 13impl Struct {
17 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { 14 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
18 db.struct_data(self).variant_data.clone() 15 db.struct_data(self.id).variant_data.clone()
19 }
20}
21
22/// Note that we use `StructData` for unions as well!
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct StructData {
25 pub(crate) name: Option<Name>,
26 pub(crate) variant_data: Arc<VariantData>,
27}
28
29impl StructData {
30 fn new(struct_def: &ast::StructDef) -> StructData {
31 let name = struct_def.name().map(|n| n.as_name());
32 let variant_data = VariantData::new(struct_def.kind());
33 let variant_data = Arc::new(variant_data);
34 StructData { name, variant_data }
35 }
36
37 pub(crate) fn struct_data_query(
38 db: &(impl DefDatabase + AstDatabase),
39 struct_: Struct,
40 ) -> Arc<StructData> {
41 let src = struct_.source(db);
42 Arc::new(StructData::new(&src.ast))
43 }
44}
45
46fn variants(enum_def: &ast::EnumDef) -> impl Iterator<Item = ast::EnumVariant> {
47 enum_def.variant_list().into_iter().flat_map(|it| it.variants())
48}
49
50impl EnumVariant {
51 pub(crate) fn source_impl(
52 self,
53 db: &(impl DefDatabase + AstDatabase),
54 ) -> Source<ast::EnumVariant> {
55 let src = self.parent.source(db);
56 let ast = variants(&src.ast)
57 .zip(db.enum_data(self.parent).variants.iter())
58 .find(|(_syntax, (id, _))| *id == self.id)
59 .unwrap()
60 .0;
61 Source { file_id: src.file_id, ast }
62 }
63 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
64 db.enum_data(self.parent).variants[self.id].variant_data.clone()
65 }
66}
67
68#[derive(Debug, Clone, PartialEq, Eq)]
69pub struct EnumData {
70 pub(crate) name: Option<Name>,
71 pub(crate) variants: Arena<LocalEnumVariantId, EnumVariantData>,
72}
73
74impl EnumData {
75 pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
76 let src = e.source(db);
77 let name = src.ast.name().map(|n| n.as_name());
78 let variants = variants(&src.ast)
79 .map(|var| EnumVariantData {
80 name: var.name().map(|it| it.as_name()),
81 variant_data: Arc::new(VariantData::new(var.kind())),
82 })
83 .collect();
84 Arc::new(EnumData { name, variants })
85 }
86}
87
88#[derive(Debug, Clone, PartialEq, Eq)]
89pub(crate) struct EnumVariantData {
90 pub(crate) name: Option<Name>,
91 variant_data: Arc<VariantData>,
92}
93
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
95pub(crate) struct StructFieldId(RawId);
96impl_arena_id!(StructFieldId);
97
98/// A single field of an enum variant or struct
99#[derive(Debug, Clone, PartialEq, Eq)]
100pub struct StructFieldData {
101 pub(crate) name: Name,
102 pub(crate) type_ref: TypeRef,
103}
104
105/// Fields of an enum variant or struct
106#[derive(Debug, Clone, PartialEq, Eq)]
107pub(crate) struct VariantData(VariantDataInner);
108
109#[derive(Debug, Clone, PartialEq, Eq)]
110enum VariantDataInner {
111 Struct(Arena<StructFieldId, StructFieldData>),
112 Tuple(Arena<StructFieldId, StructFieldData>),
113 Unit,
114}
115
116impl VariantData {
117 pub(crate) fn fields(&self) -> Option<&Arena<StructFieldId, StructFieldData>> {
118 match &self.0 {
119 VariantDataInner::Struct(fields) | VariantDataInner::Tuple(fields) => Some(fields),
120 _ => None,
121 }
122 }
123}
124
125impl VariantData {
126 fn new(flavor: StructKind) -> Self {
127 let inner = match flavor {
128 ast::StructKind::Tuple(fl) => {
129 let fields = fl
130 .fields()
131 .enumerate()
132 .map(|(i, fd)| StructFieldData {
133 name: Name::new_tuple_field(i),
134 type_ref: TypeRef::from_ast_opt(fd.type_ref()),
135 })
136 .collect();
137 VariantDataInner::Tuple(fields)
138 }
139 ast::StructKind::Named(fl) => {
140 let fields = fl
141 .fields()
142 .map(|fd| StructFieldData {
143 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
144 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
145 })
146 .collect();
147 VariantDataInner::Struct(fields)
148 }
149 ast::StructKind::Unit => VariantDataInner::Unit,
150 };
151 VariantData(inner)
152 } 16 }
153} 17}
154 18
@@ -188,35 +52,3 @@ impl VariantDef {
188 } 52 }
189 } 53 }
190} 54}
191
192impl StructField {
193 pub(crate) fn source_impl(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> {
194 let var_data = self.parent.variant_data(db);
195 let fields = var_data.fields().unwrap();
196 let ss;
197 let es;
198 let (file_id, struct_kind) = match self.parent {
199 VariantDef::Struct(s) => {
200 ss = s.source(db);
201 (ss.file_id, ss.ast.kind())
202 }
203 VariantDef::EnumVariant(e) => {
204 es = e.source(db);
205 (es.file_id, es.ast.kind())
206 }
207 };
208
209 let field_sources = match struct_kind {
210 ast::StructKind::Tuple(fl) => fl.fields().map(|it| FieldSource::Pos(it)).collect(),
211 ast::StructKind::Named(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(),
212 ast::StructKind::Unit => Vec::new(),
213 };
214 let ast = field_sources
215 .into_iter()
216 .zip(fields.iter())
217 .find(|(_syntax, (id, _))| *id == self.id)
218 .unwrap()
219 .0;
220 Source { file_id, ast }
221 }
222}
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index b32aa145e..ae6ef7606 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -6,16 +6,17 @@ pub(crate) mod docs;
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use hir_def::{ 8use hir_def::{
9 adt::VariantData,
9 builtin_type::BuiltinType, 10 builtin_type::BuiltinType,
10 type_ref::{Mutability, TypeRef}, 11 type_ref::{Mutability, TypeRef},
11 CrateModuleId, LocalEnumVariantId, ModuleId, 12 CrateModuleId, LocalEnumVariantId, LocalStructFieldId, ModuleId,
12}; 13};
13use hir_expand::name::{self, AsName}; 14use hir_expand::name::{self, AsName};
14use ra_db::{CrateId, Edition}; 15use ra_db::{CrateId, Edition};
15use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 16use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
16 17
17use crate::{ 18use crate::{
18 adt::{StructFieldId, VariantDef}, 19 adt::VariantDef,
19 db::{AstDatabase, DefDatabase, HirDatabase}, 20 db::{AstDatabase, DefDatabase, HirDatabase},
20 diagnostics::DiagnosticSink, 21 diagnostics::DiagnosticSink,
21 expr::{validation::ExprValidator, Body, BodySourceMap}, 22 expr::{validation::ExprValidator, Body, BodySourceMap},
@@ -250,7 +251,7 @@ impl Module {
250#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 251#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
251pub struct StructField { 252pub struct StructField {
252 pub(crate) parent: VariantDef, 253 pub(crate) parent: VariantDef,
253 pub(crate) id: StructFieldId, 254 pub(crate) id: LocalStructFieldId,
254} 255}
255 256
256#[derive(Debug, PartialEq, Eq)] 257#[derive(Debug, PartialEq, Eq)]
@@ -288,11 +289,11 @@ impl Struct {
288 } 289 }
289 290
290 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 291 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
291 db.struct_data(self).name.clone() 292 db.struct_data(self.id).name.clone()
292 } 293 }
293 294
294 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { 295 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
295 db.struct_data(self) 296 db.struct_data(self.id)
296 .variant_data 297 .variant_data
297 .fields() 298 .fields()
298 .into_iter() 299 .into_iter()
@@ -302,7 +303,7 @@ impl Struct {
302 } 303 }
303 304
304 pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> { 305 pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
305 db.struct_data(self) 306 db.struct_data(self.id)
306 .variant_data 307 .variant_data
307 .fields() 308 .fields()
308 .into_iter() 309 .into_iter()
@@ -338,7 +339,7 @@ pub struct Union {
338 339
339impl Union { 340impl Union {
340 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 341 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
341 db.struct_data(Struct { id: self.id }).name.clone() 342 db.struct_data(self.id).name.clone()
342 } 343 }
343 344
344 pub fn module(self, db: &impl HirDatabase) -> Module { 345 pub fn module(self, db: &impl HirDatabase) -> Module {
@@ -376,15 +377,19 @@ impl Enum {
376 } 377 }
377 378
378 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 379 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
379 db.enum_data(self).name.clone() 380 db.enum_data(self.id).name.clone()
380 } 381 }
381 382
382 pub fn variants(self, db: &impl DefDatabase) -> Vec<EnumVariant> { 383 pub fn variants(self, db: &impl DefDatabase) -> Vec<EnumVariant> {
383 db.enum_data(self).variants.iter().map(|(id, _)| EnumVariant { parent: self, id }).collect() 384 db.enum_data(self.id)
385 .variants
386 .iter()
387 .map(|(id, _)| EnumVariant { parent: self, id })
388 .collect()
384 } 389 }
385 390
386 pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> { 391 pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> {
387 db.enum_data(self) 392 db.enum_data(self.id)
388 .variants 393 .variants
389 .iter() 394 .iter()
390 .find(|(_id, data)| data.name.as_ref() == Some(name)) 395 .find(|(_id, data)| data.name.as_ref() == Some(name))
@@ -422,7 +427,7 @@ impl EnumVariant {
422 } 427 }
423 428
424 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 429 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
425 db.enum_data(self.parent).variants[self.id].name.clone() 430 db.enum_data(self.parent.id).variants[self.id].name.clone()
426 } 431 }
427 432
428 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { 433 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
@@ -442,6 +447,10 @@ impl EnumVariant {
442 .find(|(_id, data)| data.name == *name) 447 .find(|(_id, data)| data.name == *name)
443 .map(|(id, _)| StructField { parent: self.into(), id }) 448 .map(|(id, _)| StructField { parent: self.into(), id })
444 } 449 }
450
451 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
452 db.enum_data(self.parent.id).variants[self.id].variant_data.clone()
453 }
445} 454}
446 455
447/// A Data Type 456/// A Data Type
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 5c7f61eef..0f4c78df7 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -3,6 +3,7 @@
3use ra_syntax::ast::{self, AstNode}; 3use ra_syntax::ast::{self, AstNode};
4 4
5use crate::{ 5use crate::{
6 adt::VariantDef,
6 db::{AstDatabase, DefDatabase, HirDatabase}, 7 db::{AstDatabase, DefDatabase, HirDatabase},
7 ids::AstItemDef, 8 ids::AstItemDef,
8 Const, Either, Enum, EnumVariant, FieldSource, Function, HasBody, HirFileId, MacroDef, Module, 9 Const, Either, Enum, EnumVariant, FieldSource, Function, HasBody, HirFileId, MacroDef, Module,
@@ -45,7 +46,33 @@ impl Module {
45impl HasSource for StructField { 46impl HasSource for StructField {
46 type Ast = FieldSource; 47 type Ast = FieldSource;
47 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> { 48 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> {
48 self.source_impl(db) 49 let var_data = self.parent.variant_data(db);
50 let fields = var_data.fields().unwrap();
51 let ss;
52 let es;
53 let (file_id, struct_kind) = match self.parent {
54 VariantDef::Struct(s) => {
55 ss = s.source(db);
56 (ss.file_id, ss.ast.kind())
57 }
58 VariantDef::EnumVariant(e) => {
59 es = e.source(db);
60 (es.file_id, es.ast.kind())
61 }
62 };
63
64 let field_sources = match struct_kind {
65 ast::StructKind::Tuple(fl) => fl.fields().map(|it| FieldSource::Pos(it)).collect(),
66 ast::StructKind::Named(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(),
67 ast::StructKind::Unit => Vec::new(),
68 };
69 let ast = field_sources
70 .into_iter()
71 .zip(fields.iter())
72 .find(|(_syntax, (id, _))| *id == self.id)
73 .unwrap()
74 .0;
75 Source { file_id, ast }
49 } 76 }
50} 77}
51impl HasSource for Struct { 78impl HasSource for Struct {
@@ -69,7 +96,18 @@ impl HasSource for Enum {
69impl HasSource for EnumVariant { 96impl HasSource for EnumVariant {
70 type Ast = ast::EnumVariant; 97 type Ast = ast::EnumVariant;
71 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::EnumVariant> { 98 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::EnumVariant> {
72 self.source_impl(db) 99 let enum_data = db.enum_data(self.parent.id);
100 let src = self.parent.id.source(db);
101 let ast = src
102 .ast
103 .variant_list()
104 .into_iter()
105 .flat_map(|it| it.variants())
106 .zip(enum_data.variants.iter())
107 .find(|(_syntax, (id, _))| *id == self.id)
108 .unwrap()
109 .0;
110 Source { file_id: src.file_id, ast }
73 } 111 }
74} 112}
75impl HasSource for Function { 113impl HasSource for Function {
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index ebfd970eb..89ca4e39f 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -6,7 +6,6 @@ use ra_db::salsa;
6use ra_syntax::SmolStr; 6use ra_syntax::SmolStr;
7 7
8use crate::{ 8use crate::{
9 adt::{EnumData, StructData},
10 debug::HirDebugDatabase, 9 debug::HirDebugDatabase,
11 generics::{GenericDef, GenericParams}, 10 generics::{GenericDef, GenericParams},
12 ids, 11 ids,
@@ -19,13 +18,13 @@ use crate::{
19 InferenceResult, Substs, Ty, TypableDef, TypeCtor, 18 InferenceResult, Substs, Ty, TypableDef, TypeCtor,
20 }, 19 },
21 type_alias::TypeAliasData, 20 type_alias::TypeAliasData,
22 Const, ConstData, Crate, DefWithBody, Enum, ExprScopes, FnData, Function, Module, Static, 21 Const, ConstData, Crate, DefWithBody, ExprScopes, FnData, Function, Module, Static,
23 Struct, StructField, Trait, TypeAlias, 22 StructField, Trait, TypeAlias,
24}; 23};
25 24
26pub use hir_def::db::{ 25pub use hir_def::db::{
27 DefDatabase2, DefDatabase2Storage, InternDatabase, InternDatabaseStorage, RawItemsQuery, 26 DefDatabase2, DefDatabase2Storage, EnumDataQuery, InternDatabase, InternDatabaseStorage,
28 RawItemsWithSourceMapQuery, 27 RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery,
29}; 28};
30pub use hir_expand::db::{ 29pub use hir_expand::db::{
31 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, 30 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
@@ -36,12 +35,6 @@ pub use hir_expand::db::{
36#[salsa::query_group(DefDatabaseStorage)] 35#[salsa::query_group(DefDatabaseStorage)]
37#[salsa::requires(AstDatabase)] 36#[salsa::requires(AstDatabase)]
38pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { 37pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
39 #[salsa::invoke(crate::adt::StructData::struct_data_query)]
40 fn struct_data(&self, s: Struct) -> Arc<StructData>;
41
42 #[salsa::invoke(crate::adt::EnumData::enum_data_query)]
43 fn enum_data(&self, e: Enum) -> Arc<EnumData>;
44
45 #[salsa::invoke(crate::traits::TraitData::trait_data_query)] 38 #[salsa::invoke(crate::traits::TraitData::trait_data_query)]
46 fn trait_data(&self, t: Trait) -> Arc<TraitData>; 39 fn trait_data(&self, t: Trait) -> Arc<TraitData>;
47 40
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index dd7cd979f..8e2834307 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -655,8 +655,8 @@ fn type_for_builtin(def: BuiltinType) -> Ty {
655} 655}
656 656
657fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { 657fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig {
658 let var_data = def.variant_data(db); 658 let struct_data = db.struct_data(def.id);
659 let fields = match var_data.fields() { 659 let fields = match struct_data.variant_data.fields() {
660 Some(fields) => fields, 660 Some(fields) => fields,
661 None => panic!("fn_sig_for_struct_constructor called on unit struct"), 661 None => panic!("fn_sig_for_struct_constructor called on unit struct"),
662 }; 662 };
@@ -671,8 +671,8 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig {
671 671
672/// Build the type of a tuple struct constructor. 672/// Build the type of a tuple struct constructor.
673fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { 673fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty {
674 let var_data = def.variant_data(db); 674 let struct_data = db.struct_data(def.id);
675 if var_data.fields().is_none() { 675 if struct_data.variant_data.fields().is_none() {
676 return type_for_adt(db, def); // Unit struct 676 return type_for_adt(db, def); // Unit struct
677 } 677 }
678 let generics = def.generic_params(db); 678 let generics = def.generic_params(db);
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
new file mode 100644
index 000000000..22bd469f0
--- /dev/null
+++ b/crates/ra_hir_def/src/adt.rs
@@ -0,0 +1,114 @@
1//! Defines hir-level representation of structs, enums and unions
2
3use std::sync::Arc;
4
5use hir_expand::name::{AsName, Name};
6use ra_arena::Arena;
7use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
8
9use crate::{
10 db::DefDatabase2, type_ref::TypeRef, AstItemDef, EnumId, LocalEnumVariantId,
11 LocalStructFieldId, StructId,
12};
13
14/// Note that we use `StructData` for unions as well!
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct StructData {
17 pub name: Option<Name>,
18 pub variant_data: Arc<VariantData>,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct EnumData {
23 pub name: Option<Name>,
24 pub variants: Arena<LocalEnumVariantId, EnumVariantData>,
25}
26
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct EnumVariantData {
29 pub name: Option<Name>,
30 pub variant_data: Arc<VariantData>,
31}
32
33/// Fields of an enum variant or struct
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct VariantData(VariantDataInner);
36
37#[derive(Debug, Clone, PartialEq, Eq)]
38enum VariantDataInner {
39 Struct(Arena<LocalStructFieldId, StructFieldData>),
40 Tuple(Arena<LocalStructFieldId, StructFieldData>),
41 Unit,
42}
43
44/// A single field of an enum variant or struct
45#[derive(Debug, Clone, PartialEq, Eq)]
46pub struct StructFieldData {
47 pub name: Name,
48 pub type_ref: TypeRef,
49}
50
51impl StructData {
52 pub(crate) fn struct_data_query(db: &impl DefDatabase2, struct_: StructId) -> Arc<StructData> {
53 let src = struct_.source(db);
54 let name = src.ast.name().map(|n| n.as_name());
55 let variant_data = VariantData::new(src.ast.kind());
56 let variant_data = Arc::new(variant_data);
57 Arc::new(StructData { name, variant_data })
58 }
59}
60
61impl EnumData {
62 pub(crate) fn enum_data_query(db: &impl DefDatabase2, e: EnumId) -> Arc<EnumData> {
63 let src = e.source(db);
64 let name = src.ast.name().map(|n| n.as_name());
65 let variants = src
66 .ast
67 .variant_list()
68 .into_iter()
69 .flat_map(|it| it.variants())
70 .map(|var| EnumVariantData {
71 name: var.name().map(|it| it.as_name()),
72 variant_data: Arc::new(VariantData::new(var.kind())),
73 })
74 .collect();
75 Arc::new(EnumData { name, variants })
76 }
77}
78
79impl VariantData {
80 fn new(flavor: ast::StructKind) -> Self {
81 let inner = match flavor {
82 ast::StructKind::Tuple(fl) => {
83 let fields = fl
84 .fields()
85 .enumerate()
86 .map(|(i, fd)| StructFieldData {
87 name: Name::new_tuple_field(i),
88 type_ref: TypeRef::from_ast_opt(fd.type_ref()),
89 })
90 .collect();
91 VariantDataInner::Tuple(fields)
92 }
93 ast::StructKind::Named(fl) => {
94 let fields = fl
95 .fields()
96 .map(|fd| StructFieldData {
97 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
98 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
99 })
100 .collect();
101 VariantDataInner::Struct(fields)
102 }
103 ast::StructKind::Unit => VariantDataInner::Unit,
104 };
105 VariantData(inner)
106 }
107
108 pub fn fields(&self) -> Option<&Arena<LocalStructFieldId, StructFieldData>> {
109 match &self.0 {
110 VariantDataInner::Struct(fields) | VariantDataInner::Tuple(fields) => Some(fields),
111 _ => None,
112 }
113 }
114}
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index b271636b0..f6027013f 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -5,7 +5,11 @@ use hir_expand::{db::AstDatabase, HirFileId};
5use ra_db::{salsa, SourceDatabase}; 5use ra_db::{salsa, SourceDatabase};
6use ra_syntax::ast; 6use ra_syntax::ast;
7 7
8use crate::nameres::raw::{ImportSourceMap, RawItems}; 8use crate::{
9 adt::{EnumData, StructData},
10 nameres::raw::{ImportSourceMap, RawItems},
11 EnumId, StructId,
12};
9 13
10#[salsa::query_group(InternDatabaseStorage)] 14#[salsa::query_group(InternDatabaseStorage)]
11pub trait InternDatabase: SourceDatabase { 15pub trait InternDatabase: SourceDatabase {
@@ -37,4 +41,10 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
37 41
38 #[salsa::invoke(RawItems::raw_items_query)] 42 #[salsa::invoke(RawItems::raw_items_query)]
39 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; 43 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
44
45 #[salsa::invoke(StructData::struct_data_query)]
46 fn struct_data(&self, s: StructId) -> Arc<StructData>;
47
48 #[salsa::invoke(EnumData::enum_data_query)]
49 fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
40} 50}
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 93ad40005..76d5f1852 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -12,6 +12,7 @@ pub mod attr;
12pub mod path; 12pub mod path;
13pub mod type_ref; 13pub mod type_ref;
14pub mod builtin_type; 14pub mod builtin_type;
15pub mod adt;
15 16
16// FIXME: this should be private 17// FIXME: this should be private
17pub mod nameres; 18pub mod nameres;
@@ -260,6 +261,22 @@ pub struct LocalEnumVariantId(RawId);
260impl_arena_id!(LocalEnumVariantId); 261impl_arena_id!(LocalEnumVariantId);
261 262
262#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 263#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
264pub enum VariantId {
265 EnumVariantId(EnumVariantId),
266 StructId(StructId),
267}
268
269#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
270pub struct StructFieldId {
271 parent: VariantId,
272 local_id: LocalStructFieldId,
273}
274
275#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
276pub struct LocalStructFieldId(RawId);
277impl_arena_id!(LocalStructFieldId);
278
279#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
263pub struct ConstId(salsa::InternId); 280pub struct ConstId(salsa::InternId);
264impl_intern_key!(ConstId); 281impl_intern_key!(ConstId);
265impl AstItemDef<ast::ConstDef> for ConstId { 282impl AstItemDef<ast::ConstDef> for ConstId {