diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/autoderef.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/expr.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/path.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 33 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 13 |
5 files changed, 31 insertions, 30 deletions
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 5d8518041..33ac782fe 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs | |||
@@ -10,7 +10,7 @@ use hir_expand::name; | |||
10 | use log::{info, warn}; | 10 | use log::{info, warn}; |
11 | 11 | ||
12 | use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; | 12 | use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; |
13 | use crate::{db::HirDatabase, generics::HasGenericParams}; | 13 | use crate::{db::HirDatabase}; |
14 | 14 | ||
15 | const AUTODEREF_RECURSION_LIMIT: usize = 10; | 15 | const AUTODEREF_RECURSION_LIMIT: usize = 10; |
16 | 16 | ||
@@ -46,7 +46,7 @@ fn deref_by_trait( | |||
46 | }; | 46 | }; |
47 | let target = deref_trait.associated_type_by_name(db, &name::TARGET_TYPE)?; | 47 | let target = deref_trait.associated_type_by_name(db, &name::TARGET_TYPE)?; |
48 | 48 | ||
49 | let generic_params = target.generic_params(db); | 49 | let generic_params = db.generic_params(target.id.into()); |
50 | if generic_params.count_params_including_parent() != 1 { | 50 | if generic_params.count_params_including_parent() != 1 { |
51 | // the Target type + Deref trait should only have one generic parameter, | 51 | // the Target type + Deref trait should only have one generic parameter, |
52 | // namely Deref's Self type | 52 | // namely Deref's Self type |
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index ac570075f..20a7e9352 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -5,6 +5,7 @@ use std::sync::Arc; | |||
5 | 5 | ||
6 | use hir_def::{ | 6 | use hir_def::{ |
7 | builtin_type::Signedness, | 7 | builtin_type::Signedness, |
8 | generics::GenericParams, | ||
8 | path::{GenericArg, GenericArgs}, | 9 | path::{GenericArg, GenericArgs}, |
9 | resolver::resolver_for_expr, | 10 | resolver::resolver_for_expr, |
10 | }; | 11 | }; |
@@ -13,7 +14,6 @@ use hir_expand::name; | |||
13 | use crate::{ | 14 | use crate::{ |
14 | db::HirDatabase, | 15 | db::HirDatabase, |
15 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, | 16 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, |
16 | generics::{GenericParams, HasGenericParams}, | ||
17 | ty::{ | 17 | ty::{ |
18 | autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace, | 18 | autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace, |
19 | Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 19 | Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, |
@@ -534,7 +534,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
534 | ( | 534 | ( |
535 | ty, | 535 | ty, |
536 | self.db.type_for_def(func.into(), Namespace::Values), | 536 | self.db.type_for_def(func.into(), Namespace::Values), |
537 | Some(func.generic_params(self.db)), | 537 | Some(self.db.generic_params(func.id.into())), |
538 | ) | 538 | ) |
539 | } | 539 | } |
540 | None => (receiver_ty, Ty::Unknown, None), | 540 | None => (receiver_ty, Ty::Unknown, None), |
@@ -645,7 +645,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
645 | if let Some(trait_) = f.parent_trait(self.db) { | 645 | if let Some(trait_) = f.parent_trait(self.db) { |
646 | // construct a TraitDef | 646 | // construct a TraitDef |
647 | let substs = a_ty.parameters.prefix( | 647 | let substs = a_ty.parameters.prefix( |
648 | trait_.generic_params(self.db).count_params_including_parent(), | 648 | self.db |
649 | .generic_params(trait_.id.into()) | ||
650 | .count_params_including_parent(), | ||
649 | ); | 651 | ); |
650 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); | 652 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); |
651 | } | 653 | } |
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index 70136e514..ee54d8217 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs | |||
@@ -7,7 +7,6 @@ use hir_def::{ | |||
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | db::HirDatabase, | 9 | db::HirDatabase, |
10 | generics::HasGenericParams, | ||
11 | ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, | 10 | ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, |
12 | AssocItem, Container, Function, Name, Path, | 11 | AssocItem, Container, Function, Name, Path, |
13 | }; | 12 | }; |
@@ -230,7 +229,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
230 | if let ValueNs::FunctionId(func) = def { | 229 | if let ValueNs::FunctionId(func) = def { |
231 | let func = Function::from(*func); | 230 | let func = Function::from(*func); |
232 | // We only do the infer if parent has generic params | 231 | // We only do the infer if parent has generic params |
233 | let gen = func.generic_params(self.db); | 232 | let gen = self.db.generic_params(func.id.into()); |
234 | if gen.count_parent_params() == 0 { | 233 | if gen.count_parent_params() == 0 { |
235 | return None; | 234 | return None; |
236 | } | 235 | } |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index c6ad0811b..75c552569 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -10,10 +10,11 @@ use std::sync::Arc; | |||
10 | 10 | ||
11 | use hir_def::{ | 11 | use hir_def::{ |
12 | builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType}, | 12 | builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType}, |
13 | generics::WherePredicate, | ||
13 | path::{GenericArg, PathSegment}, | 14 | path::{GenericArg, PathSegment}, |
14 | resolver::{HasResolver, Resolver, TypeNs}, | 15 | resolver::{HasResolver, Resolver, TypeNs}, |
15 | type_ref::{TypeBound, TypeRef}, | 16 | type_ref::{TypeBound, TypeRef}, |
16 | GenericDefId, | 17 | AdtId, GenericDefId, |
17 | }; | 18 | }; |
18 | 19 | ||
19 | use super::{ | 20 | use super::{ |
@@ -22,15 +23,13 @@ use super::{ | |||
22 | }; | 23 | }; |
23 | use crate::{ | 24 | use crate::{ |
24 | db::HirDatabase, | 25 | db::HirDatabase, |
25 | generics::HasGenericParams, | ||
26 | generics::{GenericDef, WherePredicate}, | ||
27 | ty::{ | 26 | ty::{ |
28 | primitive::{FloatTy, IntTy, Uncertain}, | 27 | primitive::{FloatTy, IntTy, Uncertain}, |
29 | Adt, | 28 | Adt, |
30 | }, | 29 | }, |
31 | util::make_mut_slice, | 30 | util::make_mut_slice, |
32 | Const, Enum, EnumVariant, Function, ImplBlock, ModuleDef, Path, Static, Struct, StructField, | 31 | Const, Enum, EnumVariant, Function, GenericDef, ImplBlock, ModuleDef, Path, Static, Struct, |
33 | Trait, TypeAlias, Union, VariantDef, | 32 | StructField, Trait, TypeAlias, Union, VariantDef, |
34 | }; | 33 | }; |
35 | 34 | ||
36 | // FIXME: this is only really used in `type_for_def`, which contains a bunch of | 35 | // FIXME: this is only really used in `type_for_def`, which contains a bunch of |
@@ -342,7 +341,7 @@ pub(super) fn substs_from_path_segment( | |||
342 | add_self_param: bool, | 341 | add_self_param: bool, |
343 | ) -> Substs { | 342 | ) -> Substs { |
344 | let mut substs = Vec::new(); | 343 | let mut substs = Vec::new(); |
345 | let def_generics = def_generic.map(|def| def.generic_params(db)); | 344 | let def_generics = def_generic.map(|def| db.generic_params(def.into())); |
346 | 345 | ||
347 | let (parent_param_count, param_count) = | 346 | let (parent_param_count, param_count) = |
348 | def_generics.map_or((0, 0), |g| (g.count_parent_params(), g.params.len())); | 347 | def_generics.map_or((0, 0), |g| (g.count_parent_params(), g.params.len())); |
@@ -443,7 +442,7 @@ impl TraitRef { | |||
443 | } | 442 | } |
444 | 443 | ||
445 | pub(crate) fn for_trait(db: &impl HirDatabase, trait_: Trait) -> TraitRef { | 444 | pub(crate) fn for_trait(db: &impl HirDatabase, trait_: Trait) -> TraitRef { |
446 | let substs = Substs::identity(&trait_.generic_params(db)); | 445 | let substs = Substs::identity(&db.generic_params(trait_.id.into())); |
447 | TraitRef { trait_, substs } | 446 | TraitRef { trait_, substs } |
448 | } | 447 | } |
449 | 448 | ||
@@ -611,7 +610,7 @@ pub(crate) fn generic_predicates_query( | |||
611 | /// Resolve the default type params from generics | 610 | /// Resolve the default type params from generics |
612 | pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) -> Substs { | 611 | pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) -> Substs { |
613 | let resolver = GenericDefId::from(def).resolver(db); | 612 | let resolver = GenericDefId::from(def).resolver(db); |
614 | let generic_params = def.generic_params(db); | 613 | let generic_params = db.generic_params(def.into()); |
615 | 614 | ||
616 | let defaults = generic_params | 615 | let defaults = generic_params |
617 | .params_including_parent() | 616 | .params_including_parent() |
@@ -633,7 +632,7 @@ fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { | |||
633 | /// Build the declared type of a function. This should not need to look at the | 632 | /// Build the declared type of a function. This should not need to look at the |
634 | /// function body. | 633 | /// function body. |
635 | fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { | 634 | fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { |
636 | let generics = def.generic_params(db); | 635 | let generics = db.generic_params(def.id.into()); |
637 | let substs = Substs::identity(&generics); | 636 | let substs = Substs::identity(&generics); |
638 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 637 | Ty::apply(TypeCtor::FnDef(def.into()), substs) |
639 | } | 638 | } |
@@ -716,7 +715,7 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { | |||
716 | if struct_data.variant_data.fields().is_none() { | 715 | if struct_data.variant_data.fields().is_none() { |
717 | return type_for_adt(db, def); // Unit struct | 716 | return type_for_adt(db, def); // Unit struct |
718 | } | 717 | } |
719 | let generics = def.generic_params(db); | 718 | let generics = db.generic_params(def.id.into()); |
720 | let substs = Substs::identity(&generics); | 719 | let substs = Substs::identity(&generics); |
721 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 720 | Ty::apply(TypeCtor::FnDef(def.into()), substs) |
722 | } | 721 | } |
@@ -732,7 +731,7 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) | |||
732 | .iter() | 731 | .iter() |
733 | .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) | 732 | .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) |
734 | .collect::<Vec<_>>(); | 733 | .collect::<Vec<_>>(); |
735 | let generics = def.parent_enum(db).generic_params(db); | 734 | let generics = db.generic_params(def.parent_enum(db).id.into()); |
736 | let substs = Substs::identity(&generics); | 735 | let substs = Substs::identity(&generics); |
737 | let ret = type_for_adt(db, def.parent_enum(db)).subst(&substs); | 736 | let ret = type_for_adt(db, def.parent_enum(db)).subst(&substs); |
738 | FnSig::from_params_and_return(params, ret) | 737 | FnSig::from_params_and_return(params, ret) |
@@ -744,18 +743,20 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> | |||
744 | if var_data.fields().is_none() { | 743 | if var_data.fields().is_none() { |
745 | return type_for_adt(db, def.parent_enum(db)); // Unit variant | 744 | return type_for_adt(db, def.parent_enum(db)); // Unit variant |
746 | } | 745 | } |
747 | let generics = def.parent_enum(db).generic_params(db); | 746 | let generics = db.generic_params(def.parent_enum(db).id.into()); |
748 | let substs = Substs::identity(&generics); | 747 | let substs = Substs::identity(&generics); |
749 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 748 | Ty::apply(TypeCtor::FnDef(def.into()), substs) |
750 | } | 749 | } |
751 | 750 | ||
752 | fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt> + HasGenericParams) -> Ty { | 751 | fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt>) -> Ty { |
753 | let generics = adt.generic_params(db); | 752 | let adt = adt.into(); |
754 | Ty::apply(TypeCtor::Adt(adt.into()), Substs::identity(&generics)) | 753 | let adt_id: AdtId = adt.into(); |
754 | let generics = db.generic_params(adt_id.into()); | ||
755 | Ty::apply(TypeCtor::Adt(adt), Substs::identity(&generics)) | ||
755 | } | 756 | } |
756 | 757 | ||
757 | fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { | 758 | fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { |
758 | let generics = t.generic_params(db); | 759 | let generics = db.generic_params(t.id.into()); |
759 | let resolver = t.id.resolver(db); | 760 | let resolver = t.id.resolver(db); |
760 | let type_ref = t.type_ref(db); | 761 | let type_ref = t.type_ref(db); |
761 | let substs = Substs::identity(&generics); | 762 | let substs = Substs::identity(&generics); |
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 9bf93981a..88785f305 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -16,10 +16,9 @@ use ra_db::salsa::{InternId, InternKey}; | |||
16 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; | 16 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; |
17 | use crate::{ | 17 | use crate::{ |
18 | db::HirDatabase, | 18 | db::HirDatabase, |
19 | generics::{GenericDef, HasGenericParams}, | ||
20 | ty::display::HirDisplay, | 19 | ty::display::HirDisplay, |
21 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, | 20 | ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, |
22 | Crate, HasBody, ImplBlock, Trait, TypeAlias, | 21 | Crate, GenericDef, HasBody, ImplBlock, Trait, TypeAlias, |
23 | }; | 22 | }; |
24 | 23 | ||
25 | /// This represents a trait whose name we could not resolve. | 24 | /// This represents a trait whose name we could not resolve. |
@@ -509,7 +508,7 @@ pub(crate) fn associated_ty_data_query( | |||
509 | Some(crate::Container::Trait(t)) => t, | 508 | Some(crate::Container::Trait(t)) => t, |
510 | _ => panic!("associated type not in trait"), | 509 | _ => panic!("associated type not in trait"), |
511 | }; | 510 | }; |
512 | let generic_params = type_alias.generic_params(db); | 511 | let generic_params = db.generic_params(type_alias.id.into()); |
513 | let bound_data = chalk_rust_ir::AssociatedTyDatumBound { | 512 | let bound_data = chalk_rust_ir::AssociatedTyDatumBound { |
514 | // FIXME add bounds and where clauses | 513 | // FIXME add bounds and where clauses |
515 | bounds: vec![], | 514 | bounds: vec![], |
@@ -550,7 +549,7 @@ pub(crate) fn trait_datum_query( | |||
550 | } | 549 | } |
551 | let trait_: Trait = from_chalk(db, trait_id); | 550 | let trait_: Trait = from_chalk(db, trait_id); |
552 | debug!("trait {:?} = {:?}", trait_id, trait_.name(db)); | 551 | debug!("trait {:?} = {:?}", trait_id, trait_.name(db)); |
553 | let generic_params = trait_.generic_params(db); | 552 | let generic_params = db.generic_params(trait_.id.into()); |
554 | let bound_vars = Substs::bound_vars(&generic_params); | 553 | let bound_vars = Substs::bound_vars(&generic_params); |
555 | let flags = chalk_rust_ir::TraitFlags { | 554 | let flags = chalk_rust_ir::TraitFlags { |
556 | auto: trait_.is_auto(db), | 555 | auto: trait_.is_auto(db), |
@@ -594,7 +593,7 @@ pub(crate) fn struct_datum_query( | |||
594 | let where_clauses = type_ctor | 593 | let where_clauses = type_ctor |
595 | .as_generic_def() | 594 | .as_generic_def() |
596 | .map(|generic_def| { | 595 | .map(|generic_def| { |
597 | let generic_params = generic_def.generic_params(db); | 596 | let generic_params = db.generic_params(generic_def.into()); |
598 | let bound_vars = Substs::bound_vars(&generic_params); | 597 | let bound_vars = Substs::bound_vars(&generic_params); |
599 | convert_where_clauses(db, generic_def, &bound_vars) | 598 | convert_where_clauses(db, generic_def, &bound_vars) |
600 | }) | 599 | }) |
@@ -634,7 +633,7 @@ fn impl_block_datum( | |||
634 | impl_id: ImplId, | 633 | impl_id: ImplId, |
635 | impl_block: ImplBlock, | 634 | impl_block: ImplBlock, |
636 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { | 635 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { |
637 | let generic_params = impl_block.generic_params(db); | 636 | let generic_params = db.generic_params(impl_block.id.into()); |
638 | let bound_vars = Substs::bound_vars(&generic_params); | 637 | let bound_vars = Substs::bound_vars(&generic_params); |
639 | let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); | 638 | let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); |
640 | let trait_ = trait_ref.trait_; | 639 | let trait_ = trait_ref.trait_; |
@@ -786,7 +785,7 @@ fn type_alias_associated_ty_value( | |||
786 | let assoc_ty = trait_ | 785 | let assoc_ty = trait_ |
787 | .associated_type_by_name(db, &type_alias.name(db)) | 786 | .associated_type_by_name(db, &type_alias.name(db)) |
788 | .expect("assoc ty value should not exist"); // validated when building the impl data as well | 787 | .expect("assoc ty value should not exist"); // validated when building the impl data as well |
789 | let generic_params = impl_block.generic_params(db); | 788 | let generic_params = db.generic_params(impl_block.id.into()); |
790 | let bound_vars = Substs::bound_vars(&generic_params); | 789 | let bound_vars = Substs::bound_vars(&generic_params); |
791 | let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); | 790 | let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); |
792 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; | 791 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; |