From ed25cf70d5e0df9c7a33deb503ea14c2d97bd7a7 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 31 Jan 2020 16:52:43 +0100 Subject: Change Ty::Param to contain param ID --- crates/ra_hir_ty/src/infer/coerce.rs | 16 ++++++++-------- crates/ra_hir_ty/src/infer/expr.rs | 5 ++--- crates/ra_hir_ty/src/infer/pat.rs | 7 +++---- 3 files changed, 13 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index 83c0c2c3f..2a9567898 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs @@ -57,8 +57,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let trait_ref = db.impl_trait(impl_id)?; // `CoerseUnsized` has one generic parameter for the target type. - let cur_from_ty = trait_ref.substs.0.get(0)?; - let cur_to_ty = trait_ref.substs.0.get(1)?; + let cur_from_ty = trait_ref.value.substs.0.get(0)?; + let cur_to_ty = trait_ref.value.substs.0.get(1)?; match (&cur_from_ty, cur_to_ty) { (ty_app!(ctor1, st1), ty_app!(ctor2, st2)) => { @@ -66,8 +66,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // This works for smart-pointer-like coercion, which covers all impls from std. st1.iter().zip(st2.iter()).enumerate().find_map(|(i, (ty1, ty2))| { match (ty1, ty2) { - (Ty::Param { idx: p1, .. }, Ty::Param { idx: p2, .. }) - if p1 != p2 => + (Ty::Bound(idx1), Ty::Bound(idx2)) + if idx1 != idx2 => { Some(((*ctor1, *ctor2), i)) } @@ -256,8 +256,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let unsize_generic_index = { let mut index = None; let mut multiple_param = false; - field_tys[last_field_id].walk(&mut |ty| match ty { - &Ty::Param { idx, .. } => { + field_tys[last_field_id].value.walk(&mut |ty| match ty { + &Ty::Bound(idx) => { if index.is_none() { index = Some(idx); } else if Some(idx) != index { @@ -276,8 +276,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // Check other fields do not involve it. let mut multiple_used = false; fields.for_each(|(field_id, _data)| { - field_tys[field_id].walk(&mut |ty| match ty { - &Ty::Param { idx, .. } if idx == unsize_generic_index => { + field_tys[field_id].value.walk(&mut |ty| match ty { + &Ty::Bound(idx) if idx == unsize_generic_index => { multiple_used = true } _ => {} diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index e1fdb356d..8b8378499 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -236,8 +236,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.result.record_field_resolutions.insert(field.expr, field_def); } let field_ty = field_def - .map_or(Ty::Unknown, |it| field_types[it.local_id].clone()) - .subst(&substs); + .map_or(Ty::Unknown, |it| field_types[it.local_id].clone().subst(&substs)); self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty)); } if let Some(expr) = spread { @@ -686,7 +685,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { if let TypeCtor::FnDef(def) = a_ty.ctor { let generic_predicates = self.db.generic_predicates(def.into()); for predicate in generic_predicates.iter() { - let predicate = predicate.clone().subst(&a_ty.parameters); + let predicate = predicate.clone().subst_type_params(self.db, def.into(), &a_ty.parameters); if let Some(obligation) = Obligation::from_predicate(predicate) { self.obligations.push(obligation); } diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index a14662884..e7283f24c 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -12,7 +12,7 @@ use hir_expand::name::Name; use test_utils::tested_by; use super::{BindingMode, InferenceContext}; -use crate::{db::HirDatabase, utils::variant_data, Substs, Ty, TypeCtor, TypeWalk}; +use crate::{db::HirDatabase, utils::variant_data, Substs, Ty, TypeCtor}; impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn infer_tuple_struct_pat( @@ -34,8 +34,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let expected_ty = var_data .as_ref() .and_then(|d| d.field(&Name::new_tuple_field(i))) - .map_or(Ty::Unknown, |field| field_tys[field].clone()) - .subst(&substs); + .map_or(Ty::Unknown, |field| field_tys[field].clone().subst(&substs)); let expected_ty = self.normalize_associated_types_in(expected_ty); self.infer_pat(subpat, &expected_ty, default_bm); } @@ -65,7 +64,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { for subpat in subpats { let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); let expected_ty = - matching_field.map_or(Ty::Unknown, |field| field_tys[field].clone()).subst(&substs); + matching_field.map_or(Ty::Unknown, |field| field_tys[field].clone().subst(&substs)); let expected_ty = self.normalize_associated_types_in(expected_ty); self.infer_pat(subpat.pat, &expected_ty, default_bm); } -- cgit v1.2.3