diff options
Diffstat (limited to 'crates/ra_hir/src/ty/infer')
-rw-r--r-- | crates/ra_hir/src/ty/infer/coerce.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/expr.rs | 21 |
2 files changed, 18 insertions, 15 deletions
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs index bb9a2e427..5ed4470af 100644 --- a/crates/ra_hir/src/ty/infer/coerce.rs +++ b/crates/ra_hir/src/ty/infer/coerce.rs | |||
@@ -4,14 +4,14 @@ | |||
4 | //! | 4 | //! |
5 | //! See: https://doc.rust-lang.org/nomicon/coercions.html | 5 | //! See: https://doc.rust-lang.org/nomicon/coercions.html |
6 | 6 | ||
7 | use hir_def::{lang_item::LangItemTarget, resolver::Resolver}; | 7 | use hir_def::{lang_item::LangItemTarget, resolver::Resolver, AdtId}; |
8 | use rustc_hash::FxHashMap; | 8 | use rustc_hash::FxHashMap; |
9 | use test_utils::tested_by; | 9 | use test_utils::tested_by; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::HirDatabase, | 12 | db::HirDatabase, |
13 | ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, | 13 | ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, |
14 | Adt, Mutability, | 14 | Mutability, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; | 17 | use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; |
@@ -242,11 +242,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
242 | // - T is not part of the type of any other fields | 242 | // - T is not part of the type of any other fields |
243 | // - Bar<T>: Unsize<Bar<U>>, if the last field of Foo has type Bar<T> | 243 | // - Bar<T>: Unsize<Bar<U>>, if the last field of Foo has type Bar<T> |
244 | ( | 244 | ( |
245 | ty_app!(TypeCtor::Adt(Adt::Struct(struct1)), st1), | 245 | ty_app!(TypeCtor::Adt(AdtId::StructId(struct1)), st1), |
246 | ty_app!(TypeCtor::Adt(Adt::Struct(struct2)), st2), | 246 | ty_app!(TypeCtor::Adt(AdtId::StructId(struct2)), st2), |
247 | ) if struct1 == struct2 => { | 247 | ) if struct1 == struct2 => { |
248 | let field_tys = self.db.field_types(struct1.id.into()); | 248 | let field_tys = self.db.field_types((*struct1).into()); |
249 | let struct_data = self.db.struct_data(struct1.id); | 249 | let struct_data = self.db.struct_data(*struct1); |
250 | 250 | ||
251 | let mut fields = struct_data.variant_data.fields().iter(); | 251 | let mut fields = struct_data.variant_data.fields().iter(); |
252 | let (last_field_id, _data) = fields.next_back()?; | 252 | let (last_field_id, _data) = fields.next_back()?; |
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index 316cdc880..3d0895dc6 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -8,7 +8,7 @@ use hir_def::{ | |||
8 | generics::GenericParams, | 8 | generics::GenericParams, |
9 | path::{GenericArg, GenericArgs}, | 9 | path::{GenericArg, GenericArgs}, |
10 | resolver::resolver_for_expr, | 10 | resolver::resolver_for_expr, |
11 | ContainerId, Lookup, | 11 | AdtId, ContainerId, Lookup, StructFieldId, |
12 | }; | 12 | }; |
13 | use hir_expand::name; | 13 | use hir_expand::name; |
14 | 14 | ||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | Mutability, Namespace, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, | 20 | Mutability, Namespace, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, |
21 | TypeCtor, TypeWalk, Uncertain, | 21 | TypeCtor, TypeWalk, Uncertain, |
22 | }, | 22 | }, |
23 | Adt, Name, | 23 | Name, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; | 26 | use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; |
@@ -259,14 +259,17 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
259 | TypeCtor::Tuple { .. } => name | 259 | TypeCtor::Tuple { .. } => name |
260 | .as_tuple_index() | 260 | .as_tuple_index() |
261 | .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), | 261 | .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), |
262 | TypeCtor::Adt(Adt::Struct(s)) => s.field(self.db, name).map(|field| { | 262 | TypeCtor::Adt(AdtId::StructId(s)) => { |
263 | self.write_field_resolution(tgt_expr, field); | 263 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { |
264 | self.db.field_types(s.id.into())[field.id] | 264 | let field = StructFieldId { parent: s.into(), local_id }.into(); |
265 | .clone() | 265 | self.write_field_resolution(tgt_expr, field); |
266 | .subst(&a_ty.parameters) | 266 | self.db.field_types(s.into())[field.id] |
267 | }), | 267 | .clone() |
268 | .subst(&a_ty.parameters) | ||
269 | }) | ||
270 | } | ||
268 | // FIXME: | 271 | // FIXME: |
269 | TypeCtor::Adt(Adt::Union(_)) => None, | 272 | TypeCtor::Adt(AdtId::UnionId(_)) => None, |
270 | _ => None, | 273 | _ => None, |
271 | }, | 274 | }, |
272 | _ => None, | 275 | _ => None, |