From 22a65b11b3a69b3dae561b34c6b28cb2107169d1 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 24 Jan 2020 14:32:47 +0100 Subject: Introduce TyLoweringContext --- crates/ra_hir_ty/src/infer/path.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 2c1d4831d..132f3d6f2 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs @@ -11,7 +11,7 @@ use hir_expand::name::Name; use crate::{db::HirDatabase, method_resolution, Substs, Ty, TypeWalk, ValueTyDefId}; -use super::{ExprOrPatId, InferenceContext, TraitEnvironment, TraitRef}; +use super::{ExprOrPatId, InferenceContext, TraitRef}; impl<'a, D: HirDatabase> InferenceContext<'a, D> { pub(super) fn infer_path( @@ -39,7 +39,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } let ty = self.make_ty(type_ref); let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1); - let ty = Ty::from_type_relative_path(self.db, resolver, ty, remaining_segments_for_ty); + let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &resolver }; + let ty = Ty::from_type_relative_path(&ctx, ty, remaining_segments_for_ty); self.resolve_ty_assoc_item( ty, &path.segments().last().expect("path had at least one segment").name, @@ -73,7 +74,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { if let Some(self_subst) = self_subst { ty = ty.subst(&self_subst); } - let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable); + let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; + let substs = Ty::substs_from_path(&ctx, path, typable); let ty = ty.subst(&substs); Some(ty) } @@ -98,13 +100,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { (TypeNs::TraitId(trait_), true) => { let segment = remaining_segments.last().expect("there should be at least one segment here"); - let trait_ref = TraitRef::from_resolved_path( - self.db, - &self.resolver, - trait_.into(), - resolved_segment, - None, - ); + let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; + let trait_ref = + TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); self.resolve_trait_assoc_item(trait_ref, segment, id) } (def, _) => { @@ -114,9 +112,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // as Iterator>::Item::default`) let remaining_segments_for_ty = remaining_segments.take(remaining_segments.len() - 1); + let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; let ty = Ty::from_partly_resolved_hir_path( - self.db, - &self.resolver, + &ctx, def, resolved_segment, remaining_segments_for_ty, @@ -193,14 +191,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } let canonical_ty = self.canonicalizer().canonicalize_ty(ty.clone()); - let env = TraitEnvironment::lower(self.db, &self.resolver); let krate = self.resolver.krate()?; let traits_in_scope = self.resolver.traits_in_scope(self.db); method_resolution::iterate_method_candidates( &canonical_ty.value, self.db, - env, + self.trait_env.clone(), krate, &traits_in_scope, Some(name), -- cgit v1.2.3 From 7ea4bce1b292d455c313f914b3aa3051293c502b Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 24 Jan 2020 15:22:00 +0100 Subject: Add impl trait lowering mode --- crates/ra_hir_ty/src/infer/path.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 132f3d6f2..02fc99288 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs @@ -9,7 +9,10 @@ use hir_def::{ }; use hir_expand::name::Name; -use crate::{db::HirDatabase, method_resolution, Substs, Ty, TypeWalk, ValueTyDefId}; +use crate::{ + db::HirDatabase, lower::ImplTraitLoweringMode, method_resolution, Substs, Ty, TypeWalk, + ValueTyDefId, +}; use super::{ExprOrPatId, InferenceContext, TraitRef}; @@ -39,7 +42,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } let ty = self.make_ty(type_ref); let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1); - let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &resolver }; + let ctx = crate::lower::TyLoweringContext { + db: self.db, + resolver: &resolver, + impl_trait_mode: ImplTraitLoweringMode::Disallowed, + }; let ty = Ty::from_type_relative_path(&ctx, ty, remaining_segments_for_ty); self.resolve_ty_assoc_item( ty, @@ -74,7 +81,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { if let Some(self_subst) = self_subst { ty = ty.subst(&self_subst); } - let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; + let ctx = crate::lower::TyLoweringContext { + db: self.db, + resolver: &self.resolver, + impl_trait_mode: ImplTraitLoweringMode::Disallowed, + }; let substs = Ty::substs_from_path(&ctx, path, typable); let ty = ty.subst(&substs); Some(ty) @@ -100,7 +111,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { (TypeNs::TraitId(trait_), true) => { let segment = remaining_segments.last().expect("there should be at least one segment here"); - let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; + let ctx = crate::lower::TyLoweringContext { + db: self.db, + resolver: &self.resolver, + impl_trait_mode: ImplTraitLoweringMode::Disallowed, + }; let trait_ref = TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); self.resolve_trait_assoc_item(trait_ref, segment, id) @@ -112,7 +127,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // as Iterator>::Item::default`) let remaining_segments_for_ty = remaining_segments.take(remaining_segments.len() - 1); - let ctx = crate::lower::TyLoweringContext { db: self.db, resolver: &self.resolver }; + let ctx = crate::lower::TyLoweringContext { + db: self.db, + resolver: &self.resolver, + impl_trait_mode: ImplTraitLoweringMode::Disallowed, + }; let ty = Ty::from_partly_resolved_hir_path( &ctx, def, -- cgit v1.2.3 From 93aa166748eef9560df2435391dc3f3b53f8262d Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 24 Jan 2020 19:35:09 +0100 Subject: wip lower impl trait to type args --- crates/ra_hir_ty/src/infer/expr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 31259a01d..97cb20cea 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -10,7 +10,7 @@ use hir_def::{ resolver::resolver_for_expr, AdtId, AssocContainerId, Lookup, StructFieldId, }; -use hir_expand::name::{name, Name}; +use hir_expand::name::Name; use ra_syntax::ast::RangeOp; use crate::{ @@ -654,7 +654,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // Parent arguments are unknown, except for the receiver type if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { for (_id, param) in parent_generics { - if param.name == name![Self] { + if param.provenance == hir_def::generics::TypeParamProvenance::TraitSelf { substs.push(receiver_ty.clone()); } else { substs.push(Ty::Unknown); -- cgit v1.2.3 From 16c69374471a0072541c21a5551b4fd97f7e12ba Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 25 Jan 2020 23:38:33 +0100 Subject: Lower impl trait to variables, move away from using placeholders where they don't belong --- crates/ra_hir_ty/src/infer/expr.rs | 6 ++--- crates/ra_hir_ty/src/infer/path.rs | 55 ++++++++++++-------------------------- 2 files changed, 20 insertions(+), 41 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 97cb20cea..e1fdb356d 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -20,7 +20,7 @@ use crate::{ traits::InEnvironment, utils::{generics, variant_data, Generics}, ApplicationTy, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, Ty, - TypeCtor, TypeWalk, Uncertain, + TypeCtor, TypeWalk, Uncertain, Binders, }; use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; @@ -588,10 +588,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.write_method_resolution(tgt_expr, func); (ty, self.db.value_ty(func.into()), Some(generics(self.db, func.into()))) } - None => (receiver_ty, Ty::Unknown, None), + None => (receiver_ty, Binders::new(0, Ty::Unknown), None), }; let substs = self.substs_for_method_call(def_generics, generic_args, &derefed_receiver_ty); - let method_ty = method_ty.apply_substs(substs); + let method_ty = method_ty.subst(&substs); let method_ty = self.insert_type_vars(method_ty); self.register_obligations_for_call(&method_ty); let (expected_receiver_ty, param_tys, ret_ty) = match method_ty.callable_sig(self.db) { diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 02fc99288..39aa346eb 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs @@ -10,8 +10,8 @@ use hir_def::{ use hir_expand::name::Name; use crate::{ - db::HirDatabase, lower::ImplTraitLoweringMode, method_resolution, Substs, Ty, TypeWalk, - ValueTyDefId, + db::HirDatabase, method_resolution, Substs, Ty, + ValueTyDefId }; use super::{ExprOrPatId, InferenceContext, TraitRef}; @@ -42,11 +42,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } let ty = self.make_ty(type_ref); let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1); - let ctx = crate::lower::TyLoweringContext { - db: self.db, - resolver: &resolver, - impl_trait_mode: ImplTraitLoweringMode::Disallowed, - }; + let ctx = crate::lower::TyLoweringContext::new(self.db, &resolver); let ty = Ty::from_type_relative_path(&ctx, ty, remaining_segments_for_ty); self.resolve_ty_assoc_item( ty, @@ -77,17 +73,16 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { ValueNs::EnumVariantId(it) => it.into(), }; - let mut ty = self.db.value_ty(typable); - if let Some(self_subst) = self_subst { - ty = ty.subst(&self_subst); - } - let ctx = crate::lower::TyLoweringContext { - db: self.db, - resolver: &self.resolver, - impl_trait_mode: ImplTraitLoweringMode::Disallowed, - }; + let ty = self.db.value_ty(typable); + // self_subst is just for the parent + let parent_substs = self_subst.unwrap_or_else(Substs::empty); + let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); let substs = Ty::substs_from_path(&ctx, path, typable); - let ty = ty.subst(&substs); + let full_substs = Substs::builder(substs.len()) + .use_parent_substs(&parent_substs) + .fill(substs.0[parent_substs.len()..].iter().cloned()) + .build(); + let ty = ty.subst(&full_substs); Some(ty) } @@ -111,11 +106,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { (TypeNs::TraitId(trait_), true) => { let segment = remaining_segments.last().expect("there should be at least one segment here"); - let ctx = crate::lower::TyLoweringContext { - db: self.db, - resolver: &self.resolver, - impl_trait_mode: ImplTraitLoweringMode::Disallowed, - }; + let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); let trait_ref = TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); self.resolve_trait_assoc_item(trait_ref, segment, id) @@ -127,11 +118,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // as Iterator>::Item::default`) let remaining_segments_for_ty = remaining_segments.take(remaining_segments.len() - 1); - let ctx = crate::lower::TyLoweringContext { - db: self.db, - resolver: &self.resolver, - impl_trait_mode: ImplTraitLoweringMode::Disallowed, - }; + let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); let ty = Ty::from_partly_resolved_hir_path( &ctx, def, @@ -235,12 +222,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { .fill(iter::repeat_with(|| self.table.new_type_var())) .build(); let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs); - let substs = Substs::build_for_def(self.db, item) - .use_parent_substs(&impl_substs) - .fill_with_params() - .build(); self.unify(&impl_self_ty, &ty); - Some(substs) + Some(impl_substs) } AssocContainerId::TraitId(trait_) => { // we're picking this method @@ -248,15 +231,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { .push(ty.clone()) .fill(std::iter::repeat_with(|| self.table.new_type_var())) .build(); - let substs = Substs::build_for_def(self.db, item) - .use_parent_substs(&trait_substs) - .fill_with_params() - .build(); self.obligations.push(super::Obligation::Trait(TraitRef { trait_, - substs: trait_substs, + substs: trait_substs.clone(), })); - Some(substs) + Some(trait_substs) } AssocContainerId::ContainerId(_) => None, }; -- cgit v1.2.3 From 4a8279a21ad75ae2cb6d96746b8a880038ec0455 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 31 Jan 2020 15:34:43 +0100 Subject: Fix another test --- crates/ra_hir_ty/src/infer/path.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 39aa346eb..fcf13b0b3 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs @@ -177,13 +177,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { AssocItemId::ConstId(c) => ValueNs::ConstId(c), AssocItemId::TypeAliasId(_) => unreachable!(), }; - let substs = Substs::build_for_def(self.db, item) - .use_parent_substs(&trait_ref.substs) - .fill_with_params() - .build(); self.write_assoc_resolution(id, item); - Some((def, Some(substs))) + Some((def, Some(trait_ref.substs))) } fn resolve_ty_assoc_item( -- cgit v1.2.3 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 From 86348f5994cdc3831edf3a5582d6d9d576fd1d80 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 2 Feb 2020 13:43:04 +0100 Subject: Comment fixes / todos --- crates/ra_hir_ty/src/infer/expr.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 8b8378499..b32df8e90 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -587,6 +587,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.write_method_resolution(tgt_expr, func); (ty, self.db.value_ty(func.into()), Some(generics(self.db, func.into()))) } + // TODO fix this None => (receiver_ty, Binders::new(0, Ty::Unknown), None), }; let substs = self.substs_for_method_call(def_generics, generic_args, &derefed_receiver_ty); -- cgit v1.2.3 From a3d8cffde39bfb0d50b87a8ded5e0534adec4cd5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 2 Feb 2020 17:11:54 +0100 Subject: Use variables in predicates as well --- crates/ra_hir_ty/src/infer/expr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index b32df8e90..b69785e55 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -20,7 +20,7 @@ use crate::{ traits::InEnvironment, utils::{generics, variant_data, Generics}, ApplicationTy, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, Ty, - TypeCtor, TypeWalk, Uncertain, Binders, + TypeCtor, Uncertain, Binders, }; use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; @@ -686,7 +686,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_type_params(self.db, def.into(), &a_ty.parameters); + let predicate = predicate.clone().subst(&a_ty.parameters); if let Some(obligation) = Obligation::from_predicate(predicate) { self.obligations.push(obligation); } -- cgit v1.2.3 From 6787f124b5557120cd1e4557cbdb59aa7f215be6 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 15:13:00 +0100 Subject: Clean up RPIT a bit --- crates/ra_hir_ty/src/infer/expr.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index b69785e55..6222bd90e 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -635,7 +635,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { continue; } - let param_ty = self.insert_vars_for_impl_trait(param_ty); let param_ty = self.normalize_associated_types_in(param_ty); self.infer_expr_coerce(arg, &Expectation::has_type(param_ty.clone())); } -- cgit v1.2.3 From dded90a748737c3661aad043524f2248e324c867 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 15:13:15 +0100 Subject: Formatting --- crates/ra_hir_ty/src/infer/coerce.rs | 8 ++------ crates/ra_hir_ty/src/infer/expr.rs | 4 ++-- crates/ra_hir_ty/src/infer/path.rs | 5 +---- 3 files changed, 5 insertions(+), 12 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 2a9567898..f68a1439f 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs @@ -66,9 +66,7 @@ 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::Bound(idx1), Ty::Bound(idx2)) - if idx1 != idx2 => - { + (Ty::Bound(idx1), Ty::Bound(idx2)) if idx1 != idx2 => { Some(((*ctor1, *ctor2), i)) } _ => None, @@ -277,9 +275,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let mut multiple_used = false; fields.for_each(|(field_id, _data)| { field_tys[field_id].value.walk(&mut |ty| match ty { - &Ty::Bound(idx) if idx == unsize_generic_index => { - multiple_used = true - } + &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 6222bd90e..8c360bcad 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -19,8 +19,8 @@ use crate::{ method_resolution, op, traits::InEnvironment, utils::{generics, variant_data, Generics}, - ApplicationTy, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, Ty, - TypeCtor, Uncertain, Binders, + ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, + Ty, TypeCtor, Uncertain, }; use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index fcf13b0b3..686ce7a21 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs @@ -9,10 +9,7 @@ use hir_def::{ }; use hir_expand::name::Name; -use crate::{ - db::HirDatabase, method_resolution, Substs, Ty, - ValueTyDefId -}; +use crate::{db::HirDatabase, method_resolution, Substs, Ty, ValueTyDefId}; use super::{ExprOrPatId, InferenceContext, TraitRef}; -- cgit v1.2.3 From 6c70619b0126bc0e40bd9df39dcd6e711cac69c5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 16:24:09 +0100 Subject: Deal better with implicit type parameters and argument lists --- crates/ra_hir_ty/src/infer/expr.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 8c360bcad..00ae35953 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -647,8 +647,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { generic_args: Option<&GenericArgs>, receiver_ty: &Ty, ) -> Substs { - let (total_len, _parent_len, child_len) = - def_generics.as_ref().map_or((0, 0, 0), |g| g.len_split()); + let (parent_params, self_params, type_params, impl_trait_params) = + def_generics.as_ref().map_or((0, 0, 0, 0), |g| g.provenance_split()); + assert_eq!(self_params, 0); // method shouldn't have another Self param + let total_len = parent_params + type_params + impl_trait_params; let mut substs = Vec::with_capacity(total_len); // Parent arguments are unknown, except for the receiver type if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { @@ -663,7 +665,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // handle provided type arguments if let Some(generic_args) = generic_args { // if args are provided, it should be all of them, but we can't rely on that - for arg in generic_args.args.iter().take(child_len) { + for arg in generic_args.args.iter().take(type_params) { match arg { GenericArg::Type(type_ref) => { let ty = self.make_ty(type_ref); -- cgit v1.2.3 From 9d6061f3bb935c914a6d58df803dd42770f2f7e2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 18:17:23 +0100 Subject: Fix some TODOs --- crates/ra_hir_ty/src/infer/expr.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 00ae35953..3c9c02d03 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -587,7 +587,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.write_method_resolution(tgt_expr, func); (ty, self.db.value_ty(func.into()), Some(generics(self.db, func.into()))) } - // TODO fix this None => (receiver_ty, Binders::new(0, Ty::Unknown), None), }; let substs = self.substs_for_method_call(def_generics, generic_args, &derefed_receiver_ty); -- cgit v1.2.3