diff options
author | Aleksey Kladov <[email protected]> | 2019-12-07 10:50:36 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-07 12:05:56 +0000 |
commit | 8e9837df21942ca12a5aece0a868ea46eb405742 (patch) | |
tree | 664cfafc63c0895d76df5c85f6f10c0739f82275 /crates/ra_hir_ty/src/infer/expr.rs | |
parent | 30fefcc08cc0c670ce541476491238d258ca55c1 (diff) |
Remove idx and parent generics from generics
This makes `hir_def::GenericParams` flatter. The logic for
re-numbering the params is moved to hir instead.
Diffstat (limited to 'crates/ra_hir_ty/src/infer/expr.rs')
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 0c3428999..e52040eb5 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,17 @@ 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 (parent_param_count, param_count) = def_generics |
661 | def_generics.as_ref().map_or((0, 0), |g| (g.count_parent_params(), g.params.len())); | 664 | .as_ref() |
665 | .map_or((0, 0), |g| (g.count_parent_params(), g.params.params.len())); | ||
662 | let mut substs = Vec::with_capacity(parent_param_count + param_count); | 666 | let mut substs = Vec::with_capacity(parent_param_count + param_count); |
663 | // Parent arguments are unknown, except for the receiver type | 667 | // Parent arguments are unknown, except for the receiver type |
664 | if let Some(parent_generics) = def_generics.and_then(|p| p.parent_params.clone()) { | 668 | if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { |
665 | for (_id, param) in parent_generics.params.iter() { | 669 | for (_id, param) in parent_generics { |
666 | if param.name == name::SELF_TYPE { | 670 | if param.name == name::SELF_TYPE { |
667 | substs.push(receiver_ty.clone()); | 671 | substs.push(receiver_ty.clone()); |
668 | } else { | 672 | } else { |
@@ -706,9 +710,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
706 | if let ContainerId::TraitId(trait_) = f.lookup(self.db).container { | 710 | if let ContainerId::TraitId(trait_) = f.lookup(self.db).container { |
707 | // construct a TraitDef | 711 | // construct a TraitDef |
708 | let substs = a_ty.parameters.prefix( | 712 | let substs = a_ty.parameters.prefix( |
709 | self.db | 713 | generics(self.db, trait_.into()).count_params_including_parent(), |
710 | .generic_params(trait_.into()) | ||
711 | .count_params_including_parent(), | ||
712 | ); | 714 | ); |
713 | self.obligations.push(Obligation::Trait(TraitRef { | 715 | self.obligations.push(Obligation::Trait(TraitRef { |
714 | trait_: trait_.into(), | 716 | trait_: trait_.into(), |