diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-07 17:48:15 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-07 17:48:15 +0100 |
commit | 0c927b458421c488323efbf742ce7017b6da29ab (patch) | |
tree | caf82fa6db2c2f7f9293dc556445cc8b0eb47f58 /crates/ra_hir/src/code_model.rs | |
parent | 173dccc804e75da1c83532bc0dbb21f074777731 (diff) | |
parent | 4c29214bba65d23e18875bd060325c489be5a8e4 (diff) |
Merge #3882
3882: Move computation of missing fields into hir r=matklad a=matklad
cc @SomeoneToIgnore, this is that refactoring that moves computation of missing fields to hir.
it actually removes meaningful duplication between diagnostics code and the completion code. Nontheless, it's a net addition of code :(
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index c6f3bdb8e..9baebf643 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -1027,8 +1027,16 @@ impl Type { | |||
1027 | ty: Ty, | 1027 | ty: Ty, |
1028 | ) -> Option<Type> { | 1028 | ) -> Option<Type> { |
1029 | let krate = resolver.krate()?; | 1029 | let krate = resolver.krate()?; |
1030 | Some(Type::new_with_resolver_inner(db, krate, resolver, ty)) | ||
1031 | } | ||
1032 | pub(crate) fn new_with_resolver_inner( | ||
1033 | db: &dyn HirDatabase, | ||
1034 | krate: CrateId, | ||
1035 | resolver: &Resolver, | ||
1036 | ty: Ty, | ||
1037 | ) -> Type { | ||
1030 | let environment = TraitEnvironment::lower(db, &resolver); | 1038 | let environment = TraitEnvironment::lower(db, &resolver); |
1031 | Some(Type { krate, ty: InEnvironment { value: ty, environment } }) | 1039 | Type { krate, ty: InEnvironment { value: ty, environment } } |
1032 | } | 1040 | } |
1033 | 1041 | ||
1034 | fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type { | 1042 | fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type { |
@@ -1152,27 +1160,6 @@ impl Type { | |||
1152 | res | 1160 | res |
1153 | } | 1161 | } |
1154 | 1162 | ||
1155 | pub fn variant_fields( | ||
1156 | &self, | ||
1157 | db: &dyn HirDatabase, | ||
1158 | def: VariantDef, | ||
1159 | ) -> Vec<(StructField, Type)> { | ||
1160 | // FIXME: check that ty and def match | ||
1161 | match &self.ty.value { | ||
1162 | Ty::Apply(a_ty) => { | ||
1163 | let field_types = db.field_types(def.into()); | ||
1164 | def.fields(db) | ||
1165 | .into_iter() | ||
1166 | .map(|it| { | ||
1167 | let ty = field_types[it.id].clone().subst(&a_ty.parameters); | ||
1168 | (it, self.derived(ty)) | ||
1169 | }) | ||
1170 | .collect() | ||
1171 | } | ||
1172 | _ => Vec::new(), | ||
1173 | } | ||
1174 | } | ||
1175 | |||
1176 | pub fn autoderef<'a>(&'a self, db: &'a dyn HirDatabase) -> impl Iterator<Item = Type> + 'a { | 1163 | pub fn autoderef<'a>(&'a self, db: &'a dyn HirDatabase) -> impl Iterator<Item = Type> + 'a { |
1177 | // There should be no inference vars in types passed here | 1164 | // There should be no inference vars in types passed here |
1178 | // FIXME check that? | 1165 | // FIXME check that? |