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/expr.rs') 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 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_ty/src/infer/expr.rs') 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) { -- 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/expr.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_ty/src/infer/expr.rs') 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); } -- 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/expr.rs') 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/expr.rs') 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/expr.rs') 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/expr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/infer/expr.rs') 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}; -- 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/expr.rs') 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/expr.rs') 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