diff options
-rw-r--r-- | Cargo.lock | 41 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 46 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/from_id.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir/src/generics.rs | 54 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/autoderef.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/expr.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/path.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 33 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/scope.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 107 |
15 files changed, 152 insertions, 213 deletions
diff --git a/Cargo.lock b/Cargo.lock index ef3735197..8f7783deb 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -10,7 +10,7 @@ dependencies = [ | |||
10 | 10 | ||
11 | [[package]] | 11 | [[package]] |
12 | name = "anyhow" | 12 | name = "anyhow" |
13 | version = "1.0.19" | 13 | version = "1.0.22" |
14 | source = "registry+https://github.com/rust-lang/crates.io-index" | 14 | source = "registry+https://github.com/rust-lang/crates.io-index" |
15 | 15 | ||
16 | [[package]] | 16 | [[package]] |
@@ -276,14 +276,6 @@ dependencies = [ | |||
276 | 276 | ||
277 | [[package]] | 277 | [[package]] |
278 | name = "crossbeam-queue" | 278 | name = "crossbeam-queue" |
279 | version = "0.1.2" | ||
280 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
281 | dependencies = [ | ||
282 | "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
283 | ] | ||
284 | |||
285 | [[package]] | ||
286 | name = "crossbeam-queue" | ||
287 | version = "0.2.0" | 279 | version = "0.2.0" |
288 | source = "registry+https://github.com/rust-lang/crates.io-index" | 280 | source = "registry+https://github.com/rust-lang/crates.io-index" |
289 | dependencies = [ | 281 | dependencies = [ |
@@ -292,15 +284,6 @@ dependencies = [ | |||
292 | 284 | ||
293 | [[package]] | 285 | [[package]] |
294 | name = "crossbeam-utils" | 286 | name = "crossbeam-utils" |
295 | version = "0.6.6" | ||
296 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
297 | dependencies = [ | ||
298 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", | ||
299 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
300 | ] | ||
301 | |||
302 | [[package]] | ||
303 | name = "crossbeam-utils" | ||
304 | version = "0.7.0" | 287 | version = "0.7.0" |
305 | source = "registry+https://github.com/rust-lang/crates.io-index" | 288 | source = "registry+https://github.com/rust-lang/crates.io-index" |
306 | dependencies = [ | 289 | dependencies = [ |
@@ -1092,7 +1075,7 @@ dependencies = [ | |||
1092 | "ra_syntax 0.1.0", | 1075 | "ra_syntax 0.1.0", |
1093 | "ra_text_edit 0.1.0", | 1076 | "ra_text_edit 0.1.0", |
1094 | "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1077 | "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", |
1095 | "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1078 | "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1096 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1079 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1097 | "superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1080 | "superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1098 | "test_utils 0.1.0", | 1081 | "test_utils 0.1.0", |
@@ -1371,22 +1354,22 @@ dependencies = [ | |||
1371 | 1354 | ||
1372 | [[package]] | 1355 | [[package]] |
1373 | name = "rayon" | 1356 | name = "rayon" |
1374 | version = "1.2.0" | 1357 | version = "1.2.1" |
1375 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1358 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1376 | dependencies = [ | 1359 | dependencies = [ |
1377 | "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1360 | "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", |
1378 | "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", | 1361 | "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", |
1379 | "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1362 | "rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1380 | ] | 1363 | ] |
1381 | 1364 | ||
1382 | [[package]] | 1365 | [[package]] |
1383 | name = "rayon-core" | 1366 | name = "rayon-core" |
1384 | version = "1.6.0" | 1367 | version = "1.6.1" |
1385 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1368 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1386 | dependencies = [ | 1369 | dependencies = [ |
1387 | "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1370 | "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", |
1388 | "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1371 | "crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1389 | "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", | 1372 | "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1390 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1373 | "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1391 | "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1374 | "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1392 | ] | 1375 | ] |
@@ -1833,7 +1816,7 @@ dependencies = [ | |||
1833 | name = "xtask" | 1816 | name = "xtask" |
1834 | version = "0.1.0" | 1817 | version = "0.1.0" |
1835 | dependencies = [ | 1818 | dependencies = [ |
1836 | "anyhow 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", | 1819 | "anyhow 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", |
1837 | "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1820 | "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1838 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", | 1821 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", |
1839 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1822 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1857,7 +1840,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1857 | 1840 | ||
1858 | [metadata] | 1841 | [metadata] |
1859 | "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" | 1842 | "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" |
1860 | "checksum anyhow 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "57114fc2a6cc374bce195d3482057c846e706d252ff3604363449695684d7a0d" | 1843 | "checksum anyhow 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "e19f23ab207147bbdbcdfa7f7e4ca5e84963d79bae3937074682177ab9150968" |
1861 | "checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" | 1844 | "checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" |
1862 | "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" | 1845 | "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" |
1863 | "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" | 1846 | "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" |
@@ -1887,9 +1870,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1887 | "checksum crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c" | 1870 | "checksum crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c" |
1888 | "checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" | 1871 | "checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" |
1889 | "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" | 1872 | "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" |
1890 | "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" | ||
1891 | "checksum crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfd6515864a82d2f877b42813d4553292c6659498c9a2aa31bab5a15243c2700" | 1873 | "checksum crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfd6515864a82d2f877b42813d4553292c6659498c9a2aa31bab5a15243c2700" |
1892 | "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" | ||
1893 | "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" | 1874 | "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" |
1894 | "checksum derive-new 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "71f31892cd5c62e414316f2963c5689242c43d8e7bbcaaeca97e5e28c95d91d9" | 1875 | "checksum derive-new 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "71f31892cd5c62e414316f2963c5689242c43d8e7bbcaaeca97e5e28c95d91d9" |
1895 | "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" | 1876 | "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" |
@@ -1984,8 +1965,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1984 | "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" | 1965 | "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" |
1985 | "checksum rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" | 1966 | "checksum rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" |
1986 | "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" | 1967 | "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" |
1987 | "checksum rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83a27732a533a1be0a0035a111fe76db89ad312f6f0347004c220c57f209a123" | 1968 | "checksum rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43739f8831493b276363637423d3622d4bd6394ab6f0a9c4a552e208aeb7fddd" |
1988 | "checksum rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98dcf634205083b17d0861252431eb2acbfb698ab7478a2d20de07954f47ec7b" | 1969 | "checksum rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8bf17de6f23b05473c437eb958b9c850bfc8af0961fe17b4cc92d5a627b4791" |
1989 | "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" | 1970 | "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" |
1990 | "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" | 1971 | "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" |
1991 | "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" | 1972 | "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 92860fb59..5690040a7 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -27,7 +27,6 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | |||
27 | use crate::{ | 27 | use crate::{ |
28 | db::{AstDatabase, DefDatabase, HirDatabase}, | 28 | db::{AstDatabase, DefDatabase, HirDatabase}, |
29 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, | 29 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, |
30 | generics::{GenericDef, HasGenericParams}, | ||
31 | ids::{ | 30 | ids::{ |
32 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, | 31 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, |
33 | TypeAliasId, | 32 | TypeAliasId, |
@@ -835,7 +834,7 @@ impl Trait { | |||
835 | // lifetime problems, but since there usually shouldn't be more than a | 834 | // lifetime problems, but since there usually shouldn't be more than a |
836 | // few direct traits this should be fine (we could even use some kind of | 835 | // few direct traits this should be fine (we could even use some kind of |
837 | // SmallVec if performance is a concern) | 836 | // SmallVec if performance is a concern) |
838 | self.generic_params(db) | 837 | db.generic_params(self.id.into()) |
839 | .where_predicates | 838 | .where_predicates |
840 | .iter() | 839 | .iter() |
841 | .filter_map(|pred| match &pred.type_ref { | 840 | .filter_map(|pred| match &pred.type_ref { |
@@ -975,16 +974,6 @@ pub enum AssocItem { | |||
975 | // casting them, and somehow making the constructors private, which would be annoying. | 974 | // casting them, and somehow making the constructors private, which would be annoying. |
976 | impl_froms!(AssocItem: Function, Const, TypeAlias); | 975 | impl_froms!(AssocItem: Function, Const, TypeAlias); |
977 | 976 | ||
978 | impl From<AssocItem> for crate::generics::GenericDef { | ||
979 | fn from(item: AssocItem) -> Self { | ||
980 | match item { | ||
981 | AssocItem::Function(f) => f.into(), | ||
982 | AssocItem::Const(c) => c.into(), | ||
983 | AssocItem::TypeAlias(t) => t.into(), | ||
984 | } | ||
985 | } | ||
986 | } | ||
987 | |||
988 | impl AssocItem { | 977 | impl AssocItem { |
989 | pub fn module(self, db: &impl DefDatabase) -> Module { | 978 | pub fn module(self, db: &impl DefDatabase) -> Module { |
990 | match self { | 979 | match self { |
@@ -1004,6 +993,39 @@ impl AssocItem { | |||
1004 | } | 993 | } |
1005 | } | 994 | } |
1006 | 995 | ||
996 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | ||
997 | pub enum GenericDef { | ||
998 | Function(Function), | ||
999 | Adt(Adt), | ||
1000 | Trait(Trait), | ||
1001 | TypeAlias(TypeAlias), | ||
1002 | ImplBlock(ImplBlock), | ||
1003 | // enum variants cannot have generics themselves, but their parent enums | ||
1004 | // can, and this makes some code easier to write | ||
1005 | EnumVariant(EnumVariant), | ||
1006 | // consts can have type parameters from their parents (i.e. associated consts of traits) | ||
1007 | Const(Const), | ||
1008 | } | ||
1009 | impl_froms!( | ||
1010 | GenericDef: Function, | ||
1011 | Adt(Struct, Enum, Union), | ||
1012 | Trait, | ||
1013 | TypeAlias, | ||
1014 | ImplBlock, | ||
1015 | EnumVariant, | ||
1016 | Const | ||
1017 | ); | ||
1018 | |||
1019 | impl From<AssocItem> for GenericDef { | ||
1020 | fn from(item: AssocItem) -> Self { | ||
1021 | match item { | ||
1022 | AssocItem::Function(f) => f.into(), | ||
1023 | AssocItem::Const(c) => c.into(), | ||
1024 | AssocItem::TypeAlias(t) => t.into(), | ||
1025 | } | ||
1026 | } | ||
1027 | } | ||
1028 | |||
1007 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 1029 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
1008 | pub struct Local { | 1030 | pub struct Local { |
1009 | pub(crate) parent: DefWithBody, | 1031 | pub(crate) parent: DefWithBody, |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index a9982a70f..ed0d68001 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -8,7 +8,6 @@ use ra_syntax::SmolStr; | |||
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | debug::HirDebugDatabase, | 10 | debug::HirDebugDatabase, |
11 | generics::GenericDef, | ||
12 | ids, | 11 | ids, |
13 | lang_item::{LangItemTarget, LangItems}, | 12 | lang_item::{LangItemTarget, LangItems}, |
14 | ty::{ | 13 | ty::{ |
@@ -18,8 +17,8 @@ use crate::{ | |||
18 | TypeCtor, | 17 | TypeCtor, |
19 | }, | 18 | }, |
20 | type_alias::TypeAliasData, | 19 | type_alias::TypeAliasData, |
21 | Const, ConstData, Crate, DefWithBody, FnData, Function, ImplBlock, Module, Static, StructField, | 20 | Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static, |
22 | Trait, TypeAlias, | 21 | StructField, Trait, TypeAlias, |
23 | }; | 22 | }; |
24 | 23 | ||
25 | pub use hir_def::db::{ | 24 | pub use hir_def::db::{ |
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index a3e9d8525..e8ed04056 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs | |||
@@ -9,8 +9,9 @@ use hir_def::{ | |||
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | ty::TypableDef, Adt, AssocItem, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, | 12 | ty::{CallableDef, TypableDef}, |
13 | ModuleDef, Static, TypeAlias, | 13 | Adt, AssocItem, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef, ModuleDef, |
14 | Static, TypeAlias, | ||
14 | }; | 15 | }; |
15 | 16 | ||
16 | impl From<ra_db::CrateId> for Crate { | 17 | impl From<ra_db::CrateId> for Crate { |
@@ -206,3 +207,15 @@ impl From<Adt> for GenericDefId { | |||
206 | } | 207 | } |
207 | } | 208 | } |
208 | } | 209 | } |
210 | |||
211 | impl From<CallableDef> for GenericDefId { | ||
212 | fn from(def: CallableDef) -> Self { | ||
213 | match def { | ||
214 | CallableDef::Function(it) => it.id.into(), | ||
215 | CallableDef::Struct(it) => it.id.into(), | ||
216 | CallableDef::EnumVariant(it) => { | ||
217 | EnumVariantId { parent: it.parent.id, local_id: it.id }.into() | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | } | ||
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs deleted file mode 100644 index f1bf2ee9d..000000000 --- a/crates/ra_hir/src/generics.rs +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | //! Temp module to wrap hir_def::generics | ||
2 | use std::sync::Arc; | ||
3 | |||
4 | use crate::{ | ||
5 | db::DefDatabase, Adt, Const, Container, Enum, EnumVariant, Function, ImplBlock, Struct, Trait, | ||
6 | TypeAlias, Union, | ||
7 | }; | ||
8 | |||
9 | pub use hir_def::generics::{GenericParam, GenericParams, WherePredicate}; | ||
10 | |||
11 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | ||
12 | pub enum GenericDef { | ||
13 | Function(Function), | ||
14 | Adt(Adt), | ||
15 | Trait(Trait), | ||
16 | TypeAlias(TypeAlias), | ||
17 | ImplBlock(ImplBlock), | ||
18 | // enum variants cannot have generics themselves, but their parent enums | ||
19 | // can, and this makes some code easier to write | ||
20 | EnumVariant(EnumVariant), | ||
21 | // consts can have type parameters from their parents (i.e. associated consts of traits) | ||
22 | Const(Const), | ||
23 | } | ||
24 | impl_froms!( | ||
25 | GenericDef: Function, | ||
26 | Adt(Struct, Enum, Union), | ||
27 | Trait, | ||
28 | TypeAlias, | ||
29 | ImplBlock, | ||
30 | EnumVariant, | ||
31 | Const | ||
32 | ); | ||
33 | |||
34 | impl From<Container> for GenericDef { | ||
35 | fn from(c: Container) -> Self { | ||
36 | match c { | ||
37 | Container::Trait(trait_) => trait_.into(), | ||
38 | Container::ImplBlock(impl_block) => impl_block.into(), | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | |||
43 | pub trait HasGenericParams: Copy { | ||
44 | fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams>; | ||
45 | } | ||
46 | |||
47 | impl<T> HasGenericParams for T | ||
48 | where | ||
49 | T: Into<GenericDef> + Copy, | ||
50 | { | ||
51 | fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams> { | ||
52 | db.generic_params(self.into().into()) | ||
53 | } | ||
54 | } | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 76c96bdcf..8c6834392 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -37,7 +37,6 @@ mod ty; | |||
37 | mod impl_block; | 37 | mod impl_block; |
38 | mod expr; | 38 | mod expr; |
39 | mod lang_item; | 39 | mod lang_item; |
40 | pub mod generics; | ||
41 | pub mod diagnostics; | 40 | pub mod diagnostics; |
42 | mod util; | 41 | mod util; |
43 | 42 | ||
@@ -57,13 +56,12 @@ pub use crate::{ | |||
57 | docs::{DocDef, Docs, Documentation}, | 56 | docs::{DocDef, Docs, Documentation}, |
58 | src::{HasBodySource, HasSource}, | 57 | src::{HasBodySource, HasSource}, |
59 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, | 58 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, |
60 | EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, ImplBlock, Local, | 59 | EnumVariant, FieldSource, FnData, Function, GenericDef, GenericParam, HasBody, ImplBlock, |
61 | MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait, | 60 | Local, MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, |
62 | TypeAlias, Union, VariantDef, | 61 | Trait, TypeAlias, Union, VariantDef, |
63 | }, | 62 | }, |
64 | expr::ExprScopes, | 63 | expr::ExprScopes, |
65 | from_source::FromSource, | 64 | from_source::FromSource, |
66 | generics::GenericDef, | ||
67 | ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, | 65 | ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, |
68 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, | 66 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, |
69 | ty::{ | 67 | ty::{ |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 36ece723f..95b8df181 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -17,12 +17,11 @@ use std::ops::Deref; | |||
17 | use std::sync::Arc; | 17 | use std::sync::Arc; |
18 | use std::{fmt, iter, mem}; | 18 | use std::{fmt, iter, mem}; |
19 | 19 | ||
20 | use hir_def::{generics::GenericParams, AdtId}; | ||
21 | |||
20 | use crate::{ | 22 | use crate::{ |
21 | db::HirDatabase, | 23 | db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, FloatTy, |
22 | expr::ExprId, | 24 | GenericDef, IntTy, Mutability, Name, Trait, TypeAlias, Uncertain, |
23 | generics::{GenericParams, HasGenericParams}, | ||
24 | util::make_mut_slice, | ||
25 | Adt, Crate, DefWithBody, FloatTy, IntTy, Mutability, Name, Trait, TypeAlias, Uncertain, | ||
26 | }; | 25 | }; |
27 | use display::{HirDisplay, HirFormatter}; | 26 | use display::{HirDisplay, HirFormatter}; |
28 | 27 | ||
@@ -131,15 +130,15 @@ impl TypeCtor { | |||
131 | | TypeCtor::Closure { .. } // 1 param representing the signature of the closure | 130 | | TypeCtor::Closure { .. } // 1 param representing the signature of the closure |
132 | => 1, | 131 | => 1, |
133 | TypeCtor::Adt(adt) => { | 132 | TypeCtor::Adt(adt) => { |
134 | let generic_params = adt.generic_params(db); | 133 | let generic_params = db.generic_params(AdtId::from(adt).into()); |
135 | generic_params.count_params_including_parent() | 134 | generic_params.count_params_including_parent() |
136 | } | 135 | } |
137 | TypeCtor::FnDef(callable) => { | 136 | TypeCtor::FnDef(callable) => { |
138 | let generic_params = callable.generic_params(db); | 137 | let generic_params = db.generic_params(callable.into()); |
139 | generic_params.count_params_including_parent() | 138 | generic_params.count_params_including_parent() |
140 | } | 139 | } |
141 | TypeCtor::AssociatedType(type_alias) => { | 140 | TypeCtor::AssociatedType(type_alias) => { |
142 | let generic_params = type_alias.generic_params(db); | 141 | let generic_params = db.generic_params(type_alias.id.into()); |
143 | generic_params.count_params_including_parent() | 142 | generic_params.count_params_including_parent() |
144 | } | 143 | } |
145 | TypeCtor::FnPtr { num_args } => num_args as usize + 1, | 144 | TypeCtor::FnPtr { num_args } => num_args as usize + 1, |
@@ -168,7 +167,7 @@ impl TypeCtor { | |||
168 | } | 167 | } |
169 | } | 168 | } |
170 | 169 | ||
171 | pub fn as_generic_def(self) -> Option<crate::generics::GenericDef> { | 170 | pub fn as_generic_def(self) -> Option<crate::GenericDef> { |
172 | match self { | 171 | match self { |
173 | TypeCtor::Bool | 172 | TypeCtor::Bool |
174 | | TypeCtor::Char | 173 | | TypeCtor::Char |
@@ -348,8 +347,9 @@ impl Substs { | |||
348 | ) | 347 | ) |
349 | } | 348 | } |
350 | 349 | ||
351 | pub fn build_for_def(db: &impl HirDatabase, def: impl HasGenericParams) -> SubstsBuilder { | 350 | pub fn build_for_def(db: &impl HirDatabase, def: impl Into<GenericDef>) -> SubstsBuilder { |
352 | let params = def.generic_params(db); | 351 | let def = def.into(); |
352 | let params = db.generic_params(def.into()); | ||
353 | let param_count = params.count_params_including_parent(); | 353 | let param_count = params.count_params_including_parent(); |
354 | Substs::builder(param_count) | 354 | Substs::builder(param_count) |
355 | } | 355 | } |
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 5d8518041..b60e4bb31 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs | |||
@@ -10,7 +10,7 @@ use hir_expand::name; | |||
10 | use log::{info, warn}; | 10 | use log::{info, warn}; |
11 | 11 | ||
12 | use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; | 12 | use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; |
13 | use crate::{db::HirDatabase, generics::HasGenericParams}; | 13 | use crate::db::HirDatabase; |
14 | 14 | ||
15 | const AUTODEREF_RECURSION_LIMIT: usize = 10; | 15 | const AUTODEREF_RECURSION_LIMIT: usize = 10; |
16 | 16 | ||
@@ -46,7 +46,7 @@ fn deref_by_trait( | |||
46 | }; | 46 | }; |
47 | let target = deref_trait.associated_type_by_name(db, &name::TARGET_TYPE)?; | 47 | let target = deref_trait.associated_type_by_name(db, &name::TARGET_TYPE)?; |
48 | 48 | ||
49 | let generic_params = target.generic_params(db); | 49 | let generic_params = db.generic_params(target.id.into()); |
50 | if generic_params.count_params_including_parent() != 1 { | 50 | if generic_params.count_params_including_parent() != 1 { |
51 | // the Target type + Deref trait should only have one generic parameter, | 51 | // the Target type + Deref trait should only have one generic parameter, |
52 | // namely Deref's Self type | 52 | // namely Deref's Self type |
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index ac570075f..20a7e9352 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -5,6 +5,7 @@ use std::sync::Arc; | |||
5 | 5 | ||
6 | use hir_def::{ | 6 | use hir_def::{ |
7 | builtin_type::Signedness, | 7 | builtin_type::Signedness, |
8 | generics::GenericParams, | ||
8 | path::{GenericArg, GenericArgs}, | 9 | path::{GenericArg, GenericArgs}, |
9 | resolver::resolver_for_expr, | 10 | resolver::resolver_for_expr, |
10 | }; | 11 | }; |
@@ -13,7 +14,6 @@ use hir_expand::name; | |||
13 | use crate::{ | 14 | use crate::{ |
14 | db::HirDatabase, | 15 | db::HirDatabase, |
15 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, | 16 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, |
16 | generics::{GenericParams, HasGenericParams}, | ||
17 | ty::{ | 17 | ty::{ |
18 | autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace, | 18 | autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace, |
19 | Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 19 | Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, |
@@ -534,7 +534,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
534 | ( | 534 | ( |
535 | ty, | 535 | ty, |
536 | self.db.type_for_def(func.into(), Namespace::Values), | 536 | self.db.type_for_def(func.into(), Namespace::Values), |
537 | Some(func.generic_params(self.db)), | 537 | Some(self.db.generic_params(func.id.into())), |
538 | ) | 538 | ) |
539 | } | 539 | } |
540 | None => (receiver_ty, Ty::Unknown, None), | 540 | None => (receiver_ty, Ty::Unknown, None), |
@@ -645,7 +645,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
645 | if let Some(trait_) = f.parent_trait(self.db) { | 645 | if let Some(trait_) = f.parent_trait(self.db) { |
646 | // construct a TraitDef | 646 | // construct a TraitDef |
647 | let substs = a_ty.parameters.prefix( | 647 | let substs = a_ty.parameters.prefix( |
648 | trait_.generic_params(self.db).count_params_including_parent(), | 648 | self.db |
649 | .generic_params(trait_.id.into()) | ||
650 | .count_params_including_parent(), | ||
649 | ); | 651 | ); |
650 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); | 652 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); |
651 | } | 653 | } |
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index 70136e514..ee54d8217 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs | |||
@@ -7,7 +7,6 @@ use hir_def::{ | |||
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | db::HirDatabase, | 9 | db::HirDatabase, |
10 | generics::HasGenericParams, | ||
11 | ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, | 10 | ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, |
12 | AssocItem, Container, Function, Name, Path, | 11 | AssocItem, Container, Function, Name, Path, |
13 | }; | 12 | }; |
@@ -230,7 +229,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
230 | if let ValueNs::FunctionId(func) = def { | 229 | if let ValueNs::FunctionId(func) = def { |
231 | let func = Function::from(*func); | 230 | let func = Function::from(*func); |
232 | // We only do the infer if parent has generic params | 231 | // We only do the infer if parent has generic params |
233 | let gen = func.generic_params(self.db); | 232 | let gen = self.db.generic_params(func.id.into()); |
234 | if gen.count_parent_params() == 0 { | 233 | if gen.count_parent_params() == 0 { |
235 | return None; | 234 | return None; |
236 | } | 235 | } |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index c6ad0811b..75c552569 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -10,10 +10,11 @@ use std::sync::Arc; | |||
10 | 10 | ||
11 | use hir_def::{ | 11 | use hir_def::{ |
12 | builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType}, | 12 | builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType}, |
13 | generics::WherePredicate, | ||
13 | path::{GenericArg, PathSegment}, | 14 | path::{GenericArg, PathSegment}, |
14 | resolver::{HasResolver, Resolver, TypeNs}, | 15 | resolver::{HasResolver, Resolver, TypeNs}, |
15 | type_ref::{TypeBound, TypeRef}, | 16 | type_ref::{TypeBound, TypeRef}, |
16 | GenericDefId, | 17 | AdtId, GenericDefId, |
17 | }; | 18 | }; |
18 | 19 | ||
19 | use super::{ | 20 | use super::{ |
@@ -22,15 +23,13 @@ use super::{ | |||
22 | }; | 23 | }; |
23 | use crate::{ | 24 | use crate::{ |
24 | db::HirDatabase, | 25 | db::HirDatabase, |
25 | generics::HasGenericParams, | ||
26 | generics::{GenericDef, WherePredicate}, | ||
27 | ty::{ | 26 | ty::{ |
28 | primitive::{FloatTy, IntTy, Uncertain}, | 27 | primitive::{FloatTy, IntTy, Uncertain}, |
29 | Adt, | 28 | Adt, |
30 | }, | 29 | }, |
31 | util::make_mut_slice, | 30 | util::make_mut_slice, |
32 | Const, Enum, EnumVariant, Function, ImplBlock, ModuleDef, Path, Static, Struct, StructField, | 31 | Const, Enum, EnumVariant, Function, GenericDef, ImplBlock, ModuleDef, Path, Static, Struct, |
33 | Trait, TypeAlias, Union, VariantDef, | 32 | StructField, Trait, TypeAlias, Union, VariantDef, |
34 | }; | 33 | }; |
35 | 34 | ||
36 | // FIXME: this is only really used in `type_for_def`, which contains a bunch of | 35 | // FIXME: this is only really used in `type_for_def`, which contains a bunch of |
@@ -342,7 +341,7 @@ pub(super) fn substs_from_path_segment( | |||
342 | add_self_param: bool, | 341 | add_self_param: bool, |
343 | ) -> Substs { | 342 | ) -> Substs { |
344 | let mut substs = Vec::new(); | 343 | let mut substs = Vec::new(); |
345 | let def_generics = def_generic.map(|def| def.generic_params(db)); | 344 | let def_generics = def_generic.map(|def| db.generic_params(def.into())); |
346 | 345 | ||
347 | let (parent_param_count, param_count) = | 346 | let (parent_param_count, param_count) = |
348 | def_generics.map_or((0, 0), |g| (g.count_parent_params(), g.params.len())); | 347 | def_generics.map_or((0, 0), |g| (g.count_parent_params(), g.params.len())); |
@@ -443,7 +442,7 @@ impl TraitRef { | |||
443 | } | 442 | } |
444 | 443 | ||
445 | pub(crate) fn for_trait(db: &impl HirDatabase, trait_: Trait) -> TraitRef { | 444 | pub(crate) fn for_trait(db: &impl HirDatabase, trait_: Trait) -> TraitRef { |
446 | let substs = Substs::identity(&trait_.generic_params(db)); | 445 | let substs = Substs::identity(&db.generic_params(trait_.id.into())); |
447 | TraitRef { trait_, substs } | 446 | TraitRef { trait_, substs } |
448 | } | 447 | } |
449 | 448 | ||
@@ -611,7 +610,7 @@ pub(crate) fn generic_predicates_query( | |||
611 | /// Resolve the default type params from generics | 610 | /// Resolve the default type params from generics |
612 | pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) -> Substs { | 611 | pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) -> Substs { |
613 | let resolver = GenericDefId::from(def).resolver(db); | 612 | let resolver = GenericDefId::from(def).resolver(db); |
614 | let generic_params = def.generic_params(db); | 613 | let generic_params = db.generic_params(def.into()); |
615 | 614 | ||
616 | let defaults = generic_params | 615 | let defaults = generic_params |
617 | .params_including_parent() | 616 | .params_including_parent() |
@@ -633,7 +632,7 @@ fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { | |||
633 | /// Build the declared type of a function. This should not need to look at the | 632 | /// Build the declared type of a function. This should not need to look at the |
634 | /// function body. | 633 | /// function body. |
635 | fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { | 634 | fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { |
636 | let generics = def.generic_params(db); | 635 | let generics = db.generic_params(def.id.into()); |
637 | let substs = Substs::identity(&generics); | 636 | let substs = Substs::identity(&generics); |
638 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 637 | Ty::apply(TypeCtor::FnDef(def.into()), substs) |
639 | } | 638 | } |
@@ -716,7 +715,7 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { | |||
716 | if struct_data.variant_data.fields().is_none() { | 715 | if struct_data.variant_data.fields().is_none() { |
717 | return type_for_adt(db, def); // Unit struct | 716 | return type_for_adt(db, def); // Unit struct |
718 | } | 717 | } |
719 | let generics = def.generic_params(db); | 718 | let generics = db.generic_params(def.id.into()); |
720 | let substs = Substs::identity(&generics); | 719 | let substs = Substs::identity(&generics); |
721 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 720 | Ty::apply(TypeCtor::FnDef(def.into()), substs) |
722 | } | 721 | } |
@@ -732,7 +731,7 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) | |||
732 | .iter() | 731 | .iter() |
733 | .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) | 732 | .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) |
734 | .collect::<Vec<_>>(); | 733 | .collect::<Vec<_>>(); |
735 | let generics = def.parent_enum(db).generic_params(db); | 734 | let generics = db.generic_params(def.parent_enum(db).id.into()); |
736 | let substs = Substs::identity(&generics); | 735 | let substs = Substs::identity(&generics); |
737 | let ret = type_for_adt(db, def.parent_enum(db)).subst(&substs); | 736 | let ret = type_for_adt(db, def.parent_enum(db)).subst(&substs); |
738 | FnSig::from_params_and_return(params, ret) | 737 | FnSig::from_params_and_return(params, ret) |
@@ -744,18 +743,20 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> | |||
744 | if var_data.fields().is_none() { | 743 | if var_data.fields().is_none() { |
745 | return type_for_adt(db, def.parent_enum(db)); // Unit variant | 744 | return type_for_adt(db, def.parent_enum(db)); // Unit variant |
746 | } | 745 | } |
747 | let generics = def.parent_enum(db).generic_params(db); | 746 | let generics = db.generic_params(def.parent_enum(db).id.into()); |
748 | let substs = Substs::identity(&generics); | 747 | let substs = Substs::identity(&generics); |
749 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 748 | Ty::apply(TypeCtor::FnDef(def.into()), substs) |
750 | } | 749 | } |
751 | 750 | ||
752 | fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt> + HasGenericParams) -> Ty { | 751 | fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt>) -> Ty { |
753 | let generics = adt.generic_params(db); | 752 | let adt = adt.into(); |
754 | Ty::apply(TypeCtor::Adt(adt.into()), Substs::identity(&generics)) | 753 | let adt_id: AdtId = adt.into(); |
754 | let generics = db.generic_params(adt_id.into()); | ||
755 | Ty::apply(TypeCtor::Adt(adt), Substs::identity(&generics)) | ||
755 | } | 756 | } |
756 | 757 | ||
757 | fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { | 758 | fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { |
758 | let generics = t.generic_params(db); | 759 | let generics = db.generic_params(t.id.into()); |
759 | let resolver = t.id.resolver(db); | 760 | let resolver = t.id.resolver(db); |
760 | let type_ref = t.type_ref(db); | 761 | let type_ref = t.type_ref(db); |
761 | let substs = Substs::identity(&generics); | 762 | let substs = Substs::identity(&generics); |
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 9bf93981a..88785f305 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -16,10 +16,9 @@ use ra_db::salsa::{InternId, InternKey}; | |||
16 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; | 16 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; |
17 | use crate::{ | 17 | use crate::{ |
18 | db::HirDatabase, | 18 | db::HirDatabase, |
19 | generics::{GenericDef, HasGenericParams}, | ||
20 | ty::display::HirDisplay, | 19 | ty::display::HirDisplay, |
21 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, | 20 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, |
22 | Crate, HasBody, ImplBlock, Trait, TypeAlias, | 21 | Crate, GenericDef, HasBody, ImplBlock, Trait, TypeAlias, |
23 | }; | 22 | }; |
24 | 23 | ||
25 | /// This represents a trait whose name we could not resolve. | 24 | /// This represents a trait whose name we could not resolve. |
@@ -509,7 +508,7 @@ pub(crate) fn associated_ty_data_query( | |||
509 | Some(crate::Container::Trait(t)) => t, | 508 | Some(crate::Container::Trait(t)) => t, |
510 | _ => panic!("associated type not in trait"), | 509 | _ => panic!("associated type not in trait"), |
511 | }; | 510 | }; |
512 | let generic_params = type_alias.generic_params(db); | 511 | let generic_params = db.generic_params(type_alias.id.into()); |
513 | let bound_data = chalk_rust_ir::AssociatedTyDatumBound { | 512 | let bound_data = chalk_rust_ir::AssociatedTyDatumBound { |
514 | // FIXME add bounds and where clauses | 513 | // FIXME add bounds and where clauses |
515 | bounds: vec![], | 514 | bounds: vec![], |
@@ -550,7 +549,7 @@ pub(crate) fn trait_datum_query( | |||
550 | } | 549 | } |
551 | let trait_: Trait = from_chalk(db, trait_id); | 550 | let trait_: Trait = from_chalk(db, trait_id); |
552 | debug!("trait {:?} = {:?}", trait_id, trait_.name(db)); | 551 | debug!("trait {:?} = {:?}", trait_id, trait_.name(db)); |
553 | let generic_params = trait_.generic_params(db); | 552 | let generic_params = db.generic_params(trait_.id.into()); |
554 | let bound_vars = Substs::bound_vars(&generic_params); | 553 | let bound_vars = Substs::bound_vars(&generic_params); |
555 | let flags = chalk_rust_ir::TraitFlags { | 554 | let flags = chalk_rust_ir::TraitFlags { |
556 | auto: trait_.is_auto(db), | 555 | auto: trait_.is_auto(db), |
@@ -594,7 +593,7 @@ pub(crate) fn struct_datum_query( | |||
594 | let where_clauses = type_ctor | 593 | let where_clauses = type_ctor |
595 | .as_generic_def() | 594 | .as_generic_def() |
596 | .map(|generic_def| { | 595 | .map(|generic_def| { |
597 | let generic_params = generic_def.generic_params(db); | 596 | let generic_params = db.generic_params(generic_def.into()); |
598 | let bound_vars = Substs::bound_vars(&generic_params); | 597 | let bound_vars = Substs::bound_vars(&generic_params); |
599 | convert_where_clauses(db, generic_def, &bound_vars) | 598 | convert_where_clauses(db, generic_def, &bound_vars) |
600 | }) | 599 | }) |
@@ -634,7 +633,7 @@ fn impl_block_datum( | |||
634 | impl_id: ImplId, | 633 | impl_id: ImplId, |
635 | impl_block: ImplBlock, | 634 | impl_block: ImplBlock, |
636 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { | 635 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { |
637 | let generic_params = impl_block.generic_params(db); | 636 | let generic_params = db.generic_params(impl_block.id.into()); |
638 | let bound_vars = Substs::bound_vars(&generic_params); | 637 | let bound_vars = Substs::bound_vars(&generic_params); |
639 | let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); | 638 | let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); |
640 | let trait_ = trait_ref.trait_; | 639 | let trait_ = trait_ref.trait_; |
@@ -786,7 +785,7 @@ fn type_alias_associated_ty_value( | |||
786 | let assoc_ty = trait_ | 785 | let assoc_ty = trait_ |
787 | .associated_type_by_name(db, &type_alias.name(db)) | 786 | .associated_type_by_name(db, &type_alias.name(db)) |
788 | .expect("assoc ty value should not exist"); // validated when building the impl data as well | 787 | .expect("assoc ty value should not exist"); // validated when building the impl data as well |
789 | let generic_params = impl_block.generic_params(db); | 788 | let generic_params = db.generic_params(impl_block.id.into()); |
790 | let bound_vars = Substs::bound_vars(&generic_params); | 789 | let bound_vars = Substs::bound_vars(&generic_params); |
791 | let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); | 790 | let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); |
792 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; | 791 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 77f091288..d8e911aa5 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -154,7 +154,6 @@ where | |||
154 | None => self.collect_expr_opt(condition.expr()), | 154 | None => self.collect_expr_opt(condition.expr()), |
155 | // if let -- desugar to match | 155 | // if let -- desugar to match |
156 | Some(pat) => { | 156 | Some(pat) => { |
157 | tested_by!(infer_resolve_while_let); | ||
158 | let pat = self.collect_pat(pat); | 157 | let pat = self.collect_pat(pat); |
159 | let match_expr = self.collect_expr_opt(condition.expr()); | 158 | let match_expr = self.collect_expr_opt(condition.expr()); |
160 | let placeholder_pat = self.missing_pat(); | 159 | let placeholder_pat = self.missing_pat(); |
@@ -192,6 +191,7 @@ where | |||
192 | None => self.collect_expr_opt(condition.expr()), | 191 | None => self.collect_expr_opt(condition.expr()), |
193 | // if let -- desugar to match | 192 | // if let -- desugar to match |
194 | Some(pat) => { | 193 | Some(pat) => { |
194 | tested_by!(infer_resolve_while_let); | ||
195 | let pat = self.collect_pat(pat); | 195 | let pat = self.collect_pat(pat); |
196 | let match_expr = self.collect_expr_opt(condition.expr()); | 196 | let match_expr = self.collect_expr_opt(condition.expr()); |
197 | let placeholder_pat = self.missing_pat(); | 197 | let placeholder_pat = self.missing_pat(); |
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 5d7d17231..58740b679 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs | |||
@@ -384,7 +384,7 @@ mod tests { | |||
384 | } | 384 | } |
385 | 385 | ||
386 | #[test] | 386 | #[test] |
387 | fn infer_resolve_while_let() { | 387 | fn while_let_desugaring() { |
388 | covers!(infer_resolve_while_let); | 388 | covers!(infer_resolve_while_let); |
389 | do_check_local_name( | 389 | do_check_local_name( |
390 | r#" | 390 | r#" |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 840785baa..7b5c3ec06 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -18,7 +18,7 @@ use crate::{ | |||
18 | path::{Path, PathKind}, | 18 | path::{Path, PathKind}, |
19 | AdtId, AstItemDef, ConstId, ContainerId, CrateModuleId, DefWithBodyId, EnumId, EnumVariantId, | 19 | AdtId, AstItemDef, ConstId, ContainerId, CrateModuleId, DefWithBodyId, EnumId, EnumVariantId, |
20 | FunctionId, GenericDefId, ImplId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, | 20 | FunctionId, GenericDefId, ImplId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, |
21 | TypeAliasId, UnionId, | 21 | TypeAliasId, |
22 | }; | 22 | }; |
23 | 23 | ||
24 | #[derive(Debug, Clone, Default)] | 24 | #[derive(Debug, Clone, Default)] |
@@ -369,47 +369,6 @@ impl Resolver { | |||
369 | } | 369 | } |
370 | } | 370 | } |
371 | 371 | ||
372 | impl Resolver { | ||
373 | pub(crate) fn push_scope(mut self, scope: Scope) -> Resolver { | ||
374 | self.scopes.push(scope); | ||
375 | self | ||
376 | } | ||
377 | |||
378 | pub(crate) fn push_generic_params_scope( | ||
379 | self, | ||
380 | db: &impl DefDatabase2, | ||
381 | def: GenericDefId, | ||
382 | ) -> Resolver { | ||
383 | let params = db.generic_params(def); | ||
384 | if params.params.is_empty() { | ||
385 | self | ||
386 | } else { | ||
387 | self.push_scope(Scope::GenericParams { def, params }) | ||
388 | } | ||
389 | } | ||
390 | |||
391 | pub(crate) fn push_impl_block_scope(self, impl_block: ImplId) -> Resolver { | ||
392 | self.push_scope(Scope::ImplBlockScope(impl_block)) | ||
393 | } | ||
394 | |||
395 | pub(crate) fn push_module_scope( | ||
396 | self, | ||
397 | crate_def_map: Arc<CrateDefMap>, | ||
398 | module_id: CrateModuleId, | ||
399 | ) -> Resolver { | ||
400 | self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id })) | ||
401 | } | ||
402 | |||
403 | pub(crate) fn push_expr_scope( | ||
404 | self, | ||
405 | owner: DefWithBodyId, | ||
406 | expr_scopes: Arc<ExprScopes>, | ||
407 | scope_id: ScopeId, | ||
408 | ) -> Resolver { | ||
409 | self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id })) | ||
410 | } | ||
411 | } | ||
412 | |||
413 | pub enum ScopeDef { | 372 | pub enum ScopeDef { |
414 | PerNs(PerNs), | 373 | PerNs(PerNs), |
415 | ImplSelfType(ImplId), | 374 | ImplSelfType(ImplId), |
@@ -489,6 +448,43 @@ pub fn resolver_for_scope( | |||
489 | r | 448 | r |
490 | } | 449 | } |
491 | 450 | ||
451 | impl Resolver { | ||
452 | fn push_scope(mut self, scope: Scope) -> Resolver { | ||
453 | self.scopes.push(scope); | ||
454 | self | ||
455 | } | ||
456 | |||
457 | fn push_generic_params_scope(self, db: &impl DefDatabase2, def: GenericDefId) -> Resolver { | ||
458 | let params = db.generic_params(def); | ||
459 | if params.params.is_empty() { | ||
460 | self | ||
461 | } else { | ||
462 | self.push_scope(Scope::GenericParams { def, params }) | ||
463 | } | ||
464 | } | ||
465 | |||
466 | fn push_impl_block_scope(self, impl_block: ImplId) -> Resolver { | ||
467 | self.push_scope(Scope::ImplBlockScope(impl_block)) | ||
468 | } | ||
469 | |||
470 | fn push_module_scope( | ||
471 | self, | ||
472 | crate_def_map: Arc<CrateDefMap>, | ||
473 | module_id: CrateModuleId, | ||
474 | ) -> Resolver { | ||
475 | self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id })) | ||
476 | } | ||
477 | |||
478 | fn push_expr_scope( | ||
479 | self, | ||
480 | owner: DefWithBodyId, | ||
481 | expr_scopes: Arc<ExprScopes>, | ||
482 | scope_id: ScopeId, | ||
483 | ) -> Resolver { | ||
484 | self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id })) | ||
485 | } | ||
486 | } | ||
487 | |||
492 | pub trait HasResolver { | 488 | pub trait HasResolver { |
493 | /// Builds a resolver for type references inside this def. | 489 | /// Builds a resolver for type references inside this def. |
494 | fn resolver(self, db: &impl DefDatabase2) -> Resolver; | 490 | fn resolver(self, db: &impl DefDatabase2) -> Resolver; |
@@ -507,9 +503,10 @@ impl HasResolver for TraitId { | |||
507 | } | 503 | } |
508 | } | 504 | } |
509 | 505 | ||
510 | impl HasResolver for AdtId { | 506 | impl<T: Into<AdtId>> HasResolver for T { |
511 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | 507 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { |
512 | let module = match self { | 508 | let def = self.into(); |
509 | let module = match def { | ||
513 | AdtId::StructId(it) => it.0.module(db), | 510 | AdtId::StructId(it) => it.0.module(db), |
514 | AdtId::UnionId(it) => it.0.module(db), | 511 | AdtId::UnionId(it) => it.0.module(db), |
515 | AdtId::EnumId(it) => it.module(db), | 512 | AdtId::EnumId(it) => it.module(db), |
@@ -517,26 +514,8 @@ impl HasResolver for AdtId { | |||
517 | 514 | ||
518 | module | 515 | module |
519 | .resolver(db) | 516 | .resolver(db) |
520 | .push_generic_params_scope(db, self.into()) | 517 | .push_generic_params_scope(db, def.into()) |
521 | .push_scope(Scope::AdtScope(self.into())) | 518 | .push_scope(Scope::AdtScope(def)) |
522 | } | ||
523 | } | ||
524 | |||
525 | impl HasResolver for StructId { | ||
526 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | ||
527 | AdtId::from(self).resolver(db) | ||
528 | } | ||
529 | } | ||
530 | |||
531 | impl HasResolver for UnionId { | ||
532 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | ||
533 | AdtId::from(self).resolver(db) | ||
534 | } | ||
535 | } | ||
536 | |||
537 | impl HasResolver for EnumId { | ||
538 | fn resolver(self, db: &impl DefDatabase2) -> Resolver { | ||
539 | AdtId::from(self).resolver(db) | ||
540 | } | 519 | } |
541 | } | 520 | } |
542 | 521 | ||