diff options
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r-- | crates/ra_hir_ty/src/infer/coerce.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/pat.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/path.rs | 47 |
4 files changed, 35 insertions, 42 deletions
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index f68a1439f..4a0eabdfc 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs | |||
@@ -44,10 +44,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
44 | resolver: &Resolver, | 44 | resolver: &Resolver, |
45 | ) -> FxHashMap<(TypeCtor, TypeCtor), usize> { | 45 | ) -> FxHashMap<(TypeCtor, TypeCtor), usize> { |
46 | let krate = resolver.krate().unwrap(); | 46 | let krate = resolver.krate().unwrap(); |
47 | let impls = match db.lang_item(krate.into(), "coerce_unsized".into()) { | 47 | let impls = match db.lang_item(krate, "coerce_unsized".into()) { |
48 | Some(LangItemTarget::TraitId(trait_)) => { | 48 | Some(LangItemTarget::TraitId(trait_)) => db.impls_for_trait(krate, trait_), |
49 | db.impls_for_trait(krate.into(), trait_.into()) | ||
50 | } | ||
51 | _ => return FxHashMap::default(), | 49 | _ => return FxHashMap::default(), |
52 | }; | 50 | }; |
53 | 51 | ||
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 39d8bc0ca..0af94ae32 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -127,10 +127,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
127 | TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, | 127 | TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, |
128 | Substs(sig_tys.into()), | 128 | Substs(sig_tys.into()), |
129 | ); | 129 | ); |
130 | let closure_ty = Ty::apply_one( | 130 | let closure_ty = |
131 | TypeCtor::Closure { def: self.owner.into(), expr: tgt_expr }, | 131 | Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty); |
132 | sig_ty, | ||
133 | ); | ||
134 | 132 | ||
135 | // Eagerly try to relate the closure type with the expected | 133 | // Eagerly try to relate the closure type with the expected |
136 | // type, otherwise we often won't have enough information to | 134 | // type, otherwise we often won't have enough information to |
@@ -165,7 +163,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
165 | Expr::Match { expr, arms } => { | 163 | Expr::Match { expr, arms } => { |
166 | let input_ty = self.infer_expr(*expr, &Expectation::none()); | 164 | let input_ty = self.infer_expr(*expr, &Expectation::none()); |
167 | 165 | ||
168 | let mut result_ty = if arms.len() == 0 { | 166 | let mut result_ty = if arms.is_empty() { |
169 | Ty::simple(TypeCtor::Never) | 167 | Ty::simple(TypeCtor::Never) |
170 | } else { | 168 | } else { |
171 | self.table.new_type_var() | 169 | self.table.new_type_var() |
@@ -188,7 +186,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
188 | } | 186 | } |
189 | Expr::Path(p) => { | 187 | Expr::Path(p) => { |
190 | // FIXME this could be more efficient... | 188 | // FIXME this could be more efficient... |
191 | let resolver = resolver_for_expr(self.db, self.owner.into(), tgt_expr); | 189 | let resolver = resolver_for_expr(self.db, self.owner, tgt_expr); |
192 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) | 190 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) |
193 | } | 191 | } |
194 | Expr::Continue => Ty::simple(TypeCtor::Never), | 192 | Expr::Continue => Ty::simple(TypeCtor::Never), |
@@ -217,8 +215,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
217 | self.unify(&ty, &expected.ty); | 215 | self.unify(&ty, &expected.ty); |
218 | 216 | ||
219 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 217 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
220 | let field_types = | 218 | let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); |
221 | def_id.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | ||
222 | let variant_data = def_id.map(|it| variant_data(self.db, it)); | 219 | let variant_data = def_id.map(|it| variant_data(self.db, it)); |
223 | for (field_idx, field) in fields.iter().enumerate() { | 220 | for (field_idx, field) in fields.iter().enumerate() { |
224 | let field_def = | 221 | let field_def = |
@@ -264,7 +261,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
264 | .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), | 261 | .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), |
265 | TypeCtor::Adt(AdtId::StructId(s)) => { | 262 | TypeCtor::Adt(AdtId::StructId(s)) => { |
266 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { | 263 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { |
267 | let field = StructFieldId { parent: s.into(), local_id }.into(); | 264 | let field = StructFieldId { parent: s.into(), local_id }; |
268 | self.write_field_resolution(tgt_expr, field); | 265 | self.write_field_resolution(tgt_expr, field); |
269 | self.db.field_types(s.into())[field.local_id] | 266 | self.db.field_types(s.into())[field.local_id] |
270 | .clone() | 267 | .clone() |
@@ -700,10 +697,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
700 | // construct a TraitDef | 697 | // construct a TraitDef |
701 | let substs = | 698 | let substs = |
702 | a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); | 699 | a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); |
703 | self.obligations.push(Obligation::Trait(TraitRef { | 700 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); |
704 | trait_: trait_.into(), | ||
705 | substs, | ||
706 | })); | ||
707 | } | 701 | } |
708 | } | 702 | } |
709 | CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} | 703 | CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} |
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index a5dfdf6c4..a495ecbfe 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs | |||
@@ -28,7 +28,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
28 | 28 | ||
29 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 29 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
30 | 30 | ||
31 | let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | 31 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); |
32 | 32 | ||
33 | for (i, &subpat) in subpats.iter().enumerate() { | 33 | for (i, &subpat) in subpats.iter().enumerate() { |
34 | let expected_ty = var_data | 34 | let expected_ty = var_data |
@@ -60,7 +60,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
60 | 60 | ||
61 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 61 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
62 | 62 | ||
63 | let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | 63 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); |
64 | for subpat in subpats { | 64 | for subpat in subpats { |
65 | let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); | 65 | let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); |
66 | let expected_ty = | 66 | let expected_ty = |
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 686ce7a21..471d60342 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs | |||
@@ -104,8 +104,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
104 | let segment = | 104 | let segment = |
105 | remaining_segments.last().expect("there should be at least one segment here"); | 105 | remaining_segments.last().expect("there should be at least one segment here"); |
106 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); | 106 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); |
107 | let trait_ref = | 107 | let trait_ref = TraitRef::from_resolved_path(&ctx, trait_, resolved_segment, None); |
108 | TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); | ||
109 | self.resolve_trait_assoc_item(trait_ref, segment, id) | 108 | self.resolve_trait_assoc_item(trait_ref, segment, id) |
110 | } | 109 | } |
111 | (def, _) => { | 110 | (def, _) => { |
@@ -144,30 +143,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
144 | id: ExprOrPatId, | 143 | id: ExprOrPatId, |
145 | ) -> Option<(ValueNs, Option<Substs>)> { | 144 | ) -> Option<(ValueNs, Option<Substs>)> { |
146 | let trait_ = trait_ref.trait_; | 145 | let trait_ = trait_ref.trait_; |
147 | let item = self | 146 | let item = |
148 | .db | 147 | self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { |
149 | .trait_data(trait_) | 148 | match item { |
150 | .items | 149 | AssocItemId::FunctionId(func) => { |
151 | .iter() | 150 | if segment.name == &self.db.function_data(func).name { |
152 | .map(|(_name, id)| (*id).into()) | 151 | Some(AssocItemId::FunctionId(func)) |
153 | .find_map(|item| match item { | 152 | } else { |
154 | AssocItemId::FunctionId(func) => { | 153 | None |
155 | if segment.name == &self.db.function_data(func).name { | 154 | } |
156 | Some(AssocItemId::FunctionId(func)) | ||
157 | } else { | ||
158 | None | ||
159 | } | 155 | } |
160 | } | ||
161 | 156 | ||
162 | AssocItemId::ConstId(konst) => { | 157 | AssocItemId::ConstId(konst) => { |
163 | if self.db.const_data(konst).name.as_ref().map_or(false, |n| n == segment.name) | 158 | if self |
164 | { | 159 | .db |
165 | Some(AssocItemId::ConstId(konst)) | 160 | .const_data(konst) |
166 | } else { | 161 | .name |
167 | None | 162 | .as_ref() |
163 | .map_or(false, |n| n == segment.name) | ||
164 | { | ||
165 | Some(AssocItemId::ConstId(konst)) | ||
166 | } else { | ||
167 | None | ||
168 | } | ||
168 | } | 169 | } |
170 | AssocItemId::TypeAliasId(_) => None, | ||
169 | } | 171 | } |
170 | AssocItemId::TypeAliasId(_) => None, | ||
171 | })?; | 172 | })?; |
172 | let def = match item { | 173 | let def = match item { |
173 | AssocItemId::FunctionId(f) => ValueNs::FunctionId(f), | 174 | AssocItemId::FunctionId(f) => ValueNs::FunctionId(f), |
@@ -233,7 +234,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
233 | AssocContainerId::ContainerId(_) => None, | 234 | AssocContainerId::ContainerId(_) => None, |
234 | }; | 235 | }; |
235 | 236 | ||
236 | self.write_assoc_resolution(id, item.into()); | 237 | self.write_assoc_resolution(id, item); |
237 | Some((def, substs)) | 238 | Some((def, substs)) |
238 | }, | 239 | }, |
239 | ) | 240 | ) |