diff options
Diffstat (limited to 'crates/ra_hir_ty/src/infer/expr.rs')
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index b8df27706..2c296987c 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -6,7 +6,6 @@ use std::sync::Arc; | |||
6 | use hir_def::{ | 6 | use hir_def::{ |
7 | builtin_type::Signedness, | 7 | builtin_type::Signedness, |
8 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, | 8 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, |
9 | generics::GenericParams, | ||
10 | path::{GenericArg, GenericArgs}, | 9 | path::{GenericArg, GenericArgs}, |
11 | resolver::resolver_for_expr, | 10 | resolver::resolver_for_expr, |
12 | AdtId, ContainerId, Lookup, StructFieldId, | 11 | AdtId, ContainerId, Lookup, StructFieldId, |
@@ -15,7 +14,11 @@ use hir_expand::name::{self, Name}; | |||
15 | use ra_syntax::ast::RangeOp; | 14 | use ra_syntax::ast::RangeOp; |
16 | 15 | ||
17 | use crate::{ | 16 | use crate::{ |
18 | autoderef, db::HirDatabase, method_resolution, op, traits::InEnvironment, utils::variant_data, | 17 | autoderef, |
18 | db::HirDatabase, | ||
19 | method_resolution, op, | ||
20 | traits::InEnvironment, | ||
21 | utils::{generics, variant_data, Generics}, | ||
19 | CallableDef, InferTy, IntTy, Mutability, Obligation, ProjectionPredicate, ProjectionTy, Substs, | 22 | CallableDef, InferTy, IntTy, Mutability, Obligation, ProjectionPredicate, ProjectionTy, Substs, |
20 | TraitRef, Ty, TypeCtor, TypeWalk, Uncertain, | 23 | TraitRef, Ty, TypeCtor, TypeWalk, Uncertain, |
21 | }; | 24 | }; |
@@ -596,7 +599,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
596 | Some((ty, func)) => { | 599 | Some((ty, func)) => { |
597 | let ty = canonicalized_receiver.decanonicalize_ty(ty); | 600 | let ty = canonicalized_receiver.decanonicalize_ty(ty); |
598 | self.write_method_resolution(tgt_expr, func); | 601 | self.write_method_resolution(tgt_expr, func); |
599 | (ty, self.db.value_ty(func.into()), Some(self.db.generic_params(func.into()))) | 602 | (ty, self.db.value_ty(func.into()), Some(generics(self.db, func.into()))) |
600 | } | 603 | } |
601 | None => (receiver_ty, Ty::Unknown, None), | 604 | None => (receiver_ty, Ty::Unknown, None), |
602 | }; | 605 | }; |
@@ -653,16 +656,16 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
653 | 656 | ||
654 | fn substs_for_method_call( | 657 | fn substs_for_method_call( |
655 | &mut self, | 658 | &mut self, |
656 | def_generics: Option<Arc<GenericParams>>, | 659 | def_generics: Option<Generics>, |
657 | generic_args: Option<&GenericArgs>, | 660 | generic_args: Option<&GenericArgs>, |
658 | receiver_ty: &Ty, | 661 | receiver_ty: &Ty, |
659 | ) -> Substs { | 662 | ) -> Substs { |
660 | let (parent_param_count, param_count) = | 663 | let (total_len, _parent_len, child_len) = |
661 | def_generics.as_ref().map_or((0, 0), |g| (g.count_parent_params(), g.params.len())); | 664 | def_generics.as_ref().map_or((0, 0, 0), |g| g.len_split()); |
662 | let mut substs = Vec::with_capacity(parent_param_count + param_count); | 665 | let mut substs = Vec::with_capacity(total_len); |
663 | // Parent arguments are unknown, except for the receiver type | 666 | // Parent arguments are unknown, except for the receiver type |
664 | if let Some(parent_generics) = def_generics.and_then(|p| p.parent_params.clone()) { | 667 | if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { |
665 | for param in &parent_generics.params { | 668 | for (_id, param) in parent_generics { |
666 | if param.name == name::SELF_TYPE { | 669 | if param.name == name::SELF_TYPE { |
667 | substs.push(receiver_ty.clone()); | 670 | substs.push(receiver_ty.clone()); |
668 | } else { | 671 | } else { |
@@ -673,7 +676,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
673 | // handle provided type arguments | 676 | // handle provided type arguments |
674 | if let Some(generic_args) = generic_args { | 677 | if let Some(generic_args) = generic_args { |
675 | // if args are provided, it should be all of them, but we can't rely on that | 678 | // if args are provided, it should be all of them, but we can't rely on that |
676 | for arg in generic_args.args.iter().take(param_count) { | 679 | for arg in generic_args.args.iter().take(child_len) { |
677 | match arg { | 680 | match arg { |
678 | GenericArg::Type(type_ref) => { | 681 | GenericArg::Type(type_ref) => { |
679 | let ty = self.make_ty(type_ref); | 682 | let ty = self.make_ty(type_ref); |
@@ -683,10 +686,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
683 | } | 686 | } |
684 | }; | 687 | }; |
685 | let supplied_params = substs.len(); | 688 | let supplied_params = substs.len(); |
686 | for _ in supplied_params..parent_param_count + param_count { | 689 | for _ in supplied_params..total_len { |
687 | substs.push(Ty::Unknown); | 690 | substs.push(Ty::Unknown); |
688 | } | 691 | } |
689 | assert_eq!(substs.len(), parent_param_count + param_count); | 692 | assert_eq!(substs.len(), total_len); |
690 | Substs(substs.into()) | 693 | Substs(substs.into()) |
691 | } | 694 | } |
692 | 695 | ||
@@ -705,11 +708,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
705 | CallableDef::FunctionId(f) => { | 708 | CallableDef::FunctionId(f) => { |
706 | if let ContainerId::TraitId(trait_) = f.lookup(self.db).container { | 709 | if let ContainerId::TraitId(trait_) = f.lookup(self.db).container { |
707 | // construct a TraitDef | 710 | // construct a TraitDef |
708 | let substs = a_ty.parameters.prefix( | 711 | let substs = |
709 | self.db | 712 | a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); |
710 | .generic_params(trait_.into()) | ||
711 | .count_params_including_parent(), | ||
712 | ); | ||
713 | self.obligations.push(Obligation::Trait(TraitRef { | 713 | self.obligations.push(Obligation::Trait(TraitRef { |
714 | trait_: trait_.into(), | 714 | trait_: trait_.into(), |
715 | substs, | 715 | substs, |