diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-27 13:41:55 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-27 13:41:55 +0000 |
commit | 2798beeeb05ab0e71773a2ed51b7b0c90bf6b06a (patch) | |
tree | 55f1a6eddc328b20e3a4f71036d59a9573bfaa9c /crates/ra_hir/src/ty/infer/expr.rs | |
parent | 35f57f35ec484422f06772ebe109c8fd28966ec5 (diff) | |
parent | 12501fcdd02fec9d43dfd810d65e927ddebb1b56 (diff) |
Merge #2428
2428: Remove TypableDef r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/infer/expr.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer/expr.rs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index 57f845dfa..f9ededa23 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -16,9 +16,9 @@ use hir_expand::name::{self, Name}; | |||
16 | use crate::{ | 16 | use crate::{ |
17 | db::HirDatabase, | 17 | db::HirDatabase, |
18 | ty::{ | 18 | ty::{ |
19 | autoderef, method_resolution, op, traits::InEnvironment, CallableDef, InferTy, IntTy, | 19 | autoderef, method_resolution, op, traits::InEnvironment, utils::variant_data, CallableDef, |
20 | Mutability, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, | 20 | InferTy, IntTy, Mutability, Obligation, ProjectionPredicate, ProjectionTy, Substs, |
21 | TypeWalk, Uncertain, | 21 | TraitRef, Ty, TypeCtor, TypeWalk, Uncertain, |
22 | }, | 22 | }, |
23 | }; | 23 | }; |
24 | 24 | ||
@@ -100,7 +100,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
100 | let projection = ProjectionPredicate { | 100 | let projection = ProjectionPredicate { |
101 | ty: pat_ty.clone(), | 101 | ty: pat_ty.clone(), |
102 | projection_ty: ProjectionTy { | 102 | projection_ty: ProjectionTy { |
103 | associated_ty: into_iter_item_alias.id, | 103 | associated_ty: into_iter_item_alias, |
104 | parameters: Substs::single(iterable_ty), | 104 | parameters: Substs::single(iterable_ty), |
105 | }, | 105 | }, |
106 | }; | 106 | }; |
@@ -218,22 +218,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
218 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 218 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
219 | let field_types = | 219 | let field_types = |
220 | def_id.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | 220 | def_id.map(|it| self.db.field_types(it.into())).unwrap_or_default(); |
221 | let variant_data = def_id.map(|it| variant_data(self.db, it)); | ||
221 | for (field_idx, field) in fields.iter().enumerate() { | 222 | for (field_idx, field) in fields.iter().enumerate() { |
222 | let field_def = def_id.and_then(|it| match it.field(self.db, &field.name) { | 223 | let field_def = |
223 | Some(field) => Some(field), | 224 | variant_data.as_ref().and_then(|it| match it.field(&field.name) { |
224 | None => { | 225 | Some(local_id) => { |
225 | self.push_diagnostic(InferenceDiagnostic::NoSuchField { | 226 | Some(StructFieldId { parent: def_id.unwrap(), local_id }) |
226 | expr: tgt_expr, | 227 | } |
227 | field: field_idx, | 228 | None => { |
228 | }); | 229 | self.push_diagnostic(InferenceDiagnostic::NoSuchField { |
229 | None | 230 | expr: tgt_expr, |
230 | } | 231 | field: field_idx, |
231 | }); | 232 | }); |
233 | None | ||
234 | } | ||
235 | }); | ||
232 | if let Some(field_def) = field_def { | 236 | if let Some(field_def) = field_def { |
233 | self.result.record_field_resolutions.insert(field.expr, field_def); | 237 | self.result.record_field_resolutions.insert(field.expr, field_def); |
234 | } | 238 | } |
235 | let field_ty = field_def | 239 | let field_ty = field_def |
236 | .map_or(Ty::Unknown, |it| field_types[it.id].clone()) | 240 | .map_or(Ty::Unknown, |it| field_types[it.local_id].clone()) |
237 | .subst(&substs); | 241 | .subst(&substs); |
238 | self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty)); | 242 | self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty)); |
239 | } | 243 | } |
@@ -262,7 +266,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
262 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { | 266 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { |
263 | let field = StructFieldId { parent: s.into(), local_id }.into(); | 267 | let field = StructFieldId { parent: s.into(), local_id }.into(); |
264 | self.write_field_resolution(tgt_expr, field); | 268 | self.write_field_resolution(tgt_expr, field); |
265 | self.db.field_types(s.into())[field.id] | 269 | self.db.field_types(s.into())[field.local_id] |
266 | .clone() | 270 | .clone() |
267 | .subst(&a_ty.parameters) | 271 | .subst(&a_ty.parameters) |
268 | }) | 272 | }) |
@@ -285,7 +289,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
285 | let projection = ProjectionPredicate { | 289 | let projection = ProjectionPredicate { |
286 | ty: ty.clone(), | 290 | ty: ty.clone(), |
287 | projection_ty: ProjectionTy { | 291 | projection_ty: ProjectionTy { |
288 | associated_ty: future_future_output_alias.id, | 292 | associated_ty: future_future_output_alias, |
289 | parameters: Substs::single(inner_ty), | 293 | parameters: Substs::single(inner_ty), |
290 | }, | 294 | }, |
291 | }; | 295 | }; |
@@ -304,7 +308,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
304 | let projection = ProjectionPredicate { | 308 | let projection = ProjectionPredicate { |
305 | ty: ty.clone(), | 309 | ty: ty.clone(), |
306 | projection_ty: ProjectionTy { | 310 | projection_ty: ProjectionTy { |
307 | associated_ty: ops_try_ok_alias.id, | 311 | associated_ty: ops_try_ok_alias, |
308 | parameters: Substs::single(inner_ty), | 312 | parameters: Substs::single(inner_ty), |
309 | }, | 313 | }, |
310 | }; | 314 | }; |
@@ -557,7 +561,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
557 | Some((ty, func)) => { | 561 | Some((ty, func)) => { |
558 | let ty = canonicalized_receiver.decanonicalize_ty(ty); | 562 | let ty = canonicalized_receiver.decanonicalize_ty(ty); |
559 | self.write_method_resolution(tgt_expr, func); | 563 | self.write_method_resolution(tgt_expr, func); |
560 | (ty, self.db.value_ty(func.id.into()), Some(self.db.generic_params(func.id.into()))) | 564 | (ty, self.db.value_ty(func.into()), Some(self.db.generic_params(func.into()))) |
561 | } | 565 | } |
562 | None => (receiver_ty, Ty::Unknown, None), | 566 | None => (receiver_ty, Ty::Unknown, None), |
563 | }; | 567 | }; |