From 4daf931111029cee9bb43691f88c32f0aa47a802 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Nov 2019 16:23:02 +0300 Subject: Remove old hir::generics module --- crates/ra_hir/src/ty/autoderef.rs | 4 ++-- crates/ra_hir/src/ty/infer/expr.rs | 8 +++++--- crates/ra_hir/src/ty/infer/path.rs | 3 +-- crates/ra_hir/src/ty/lower.rs | 33 +++++++++++++++++---------------- crates/ra_hir/src/ty/traits/chalk.rs | 13 ++++++------- 5 files changed, 31 insertions(+), 30 deletions(-) (limited to 'crates/ra_hir/src/ty') 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; use log::{info, warn}; use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; -use crate::{db::HirDatabase, generics::HasGenericParams}; +use crate::{db::HirDatabase}; const AUTODEREF_RECURSION_LIMIT: usize = 10; @@ -46,7 +46,7 @@ fn deref_by_trait( }; let target = deref_trait.associated_type_by_name(db, &name::TARGET_TYPE)?; - let generic_params = target.generic_params(db); + let generic_params = db.generic_params(target.id.into()); if generic_params.count_params_including_parent() != 1 { // the Target type + Deref trait should only have one generic parameter, // 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; use hir_def::{ builtin_type::Signedness, + generics::GenericParams, path::{GenericArg, GenericArgs}, resolver::resolver_for_expr, }; @@ -13,7 +14,6 @@ use hir_expand::name; use crate::{ db::HirDatabase, expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, - generics::{GenericParams, HasGenericParams}, ty::{ autoderef, method_resolution, op, CallableDef, InferTy, IntTy, Mutability, Namespace, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, @@ -534,7 +534,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { ( ty, self.db.type_for_def(func.into(), Namespace::Values), - Some(func.generic_params(self.db)), + Some(self.db.generic_params(func.id.into())), ) } None => (receiver_ty, Ty::Unknown, None), @@ -645,7 +645,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { if let Some(trait_) = f.parent_trait(self.db) { // construct a TraitDef let substs = a_ty.parameters.prefix( - trait_.generic_params(self.db).count_params_including_parent(), + self.db + .generic_params(trait_.id.into()) + .count_params_including_parent(), ); self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); } 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::{ use crate::{ db::HirDatabase, - generics::HasGenericParams, ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, AssocItem, Container, Function, Name, Path, }; @@ -230,7 +229,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { if let ValueNs::FunctionId(func) = def { let func = Function::from(*func); // We only do the infer if parent has generic params - let gen = func.generic_params(self.db); + let gen = self.db.generic_params(func.id.into()); if gen.count_parent_params() == 0 { return None; } 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; use hir_def::{ builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType}, + generics::WherePredicate, path::{GenericArg, PathSegment}, resolver::{HasResolver, Resolver, TypeNs}, type_ref::{TypeBound, TypeRef}, - GenericDefId, + AdtId, GenericDefId, }; use super::{ @@ -22,15 +23,13 @@ use super::{ }; use crate::{ db::HirDatabase, - generics::HasGenericParams, - generics::{GenericDef, WherePredicate}, ty::{ primitive::{FloatTy, IntTy, Uncertain}, Adt, }, util::make_mut_slice, - Const, Enum, EnumVariant, Function, ImplBlock, ModuleDef, Path, Static, Struct, StructField, - Trait, TypeAlias, Union, VariantDef, + Const, Enum, EnumVariant, Function, GenericDef, ImplBlock, ModuleDef, Path, Static, Struct, + StructField, Trait, TypeAlias, Union, VariantDef, }; // 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( add_self_param: bool, ) -> Substs { let mut substs = Vec::new(); - let def_generics = def_generic.map(|def| def.generic_params(db)); + let def_generics = def_generic.map(|def| db.generic_params(def.into())); let (parent_param_count, param_count) = def_generics.map_or((0, 0), |g| (g.count_parent_params(), g.params.len())); @@ -443,7 +442,7 @@ impl TraitRef { } pub(crate) fn for_trait(db: &impl HirDatabase, trait_: Trait) -> TraitRef { - let substs = Substs::identity(&trait_.generic_params(db)); + let substs = Substs::identity(&db.generic_params(trait_.id.into())); TraitRef { trait_, substs } } @@ -611,7 +610,7 @@ pub(crate) fn generic_predicates_query( /// Resolve the default type params from generics pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) -> Substs { let resolver = GenericDefId::from(def).resolver(db); - let generic_params = def.generic_params(db); + let generic_params = db.generic_params(def.into()); let defaults = generic_params .params_including_parent() @@ -633,7 +632,7 @@ fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { /// Build the declared type of a function. This should not need to look at the /// function body. fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { - let generics = def.generic_params(db); + let generics = db.generic_params(def.id.into()); let substs = Substs::identity(&generics); Ty::apply(TypeCtor::FnDef(def.into()), substs) } @@ -716,7 +715,7 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { if struct_data.variant_data.fields().is_none() { return type_for_adt(db, def); // Unit struct } - let generics = def.generic_params(db); + let generics = db.generic_params(def.id.into()); let substs = Substs::identity(&generics); Ty::apply(TypeCtor::FnDef(def.into()), substs) } @@ -732,7 +731,7 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) .iter() .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) .collect::>(); - let generics = def.parent_enum(db).generic_params(db); + let generics = db.generic_params(def.parent_enum(db).id.into()); let substs = Substs::identity(&generics); let ret = type_for_adt(db, def.parent_enum(db)).subst(&substs); FnSig::from_params_and_return(params, ret) @@ -744,18 +743,20 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> if var_data.fields().is_none() { return type_for_adt(db, def.parent_enum(db)); // Unit variant } - let generics = def.parent_enum(db).generic_params(db); + let generics = db.generic_params(def.parent_enum(db).id.into()); let substs = Substs::identity(&generics); Ty::apply(TypeCtor::FnDef(def.into()), substs) } -fn type_for_adt(db: &impl HirDatabase, adt: impl Into + HasGenericParams) -> Ty { - let generics = adt.generic_params(db); - Ty::apply(TypeCtor::Adt(adt.into()), Substs::identity(&generics)) +fn type_for_adt(db: &impl HirDatabase, adt: impl Into) -> Ty { + let adt = adt.into(); + let adt_id: AdtId = adt.into(); + let generics = db.generic_params(adt_id.into()); + Ty::apply(TypeCtor::Adt(adt), Substs::identity(&generics)) } fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { - let generics = t.generic_params(db); + let generics = db.generic_params(t.id.into()); let resolver = t.id.resolver(db); let type_ref = t.type_ref(db); 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}; use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; use crate::{ db::HirDatabase, - generics::{GenericDef, HasGenericParams}, ty::display::HirDisplay, ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, - Crate, HasBody, ImplBlock, Trait, TypeAlias, + Crate, GenericDef, HasBody, ImplBlock, Trait, TypeAlias, }; /// This represents a trait whose name we could not resolve. @@ -509,7 +508,7 @@ pub(crate) fn associated_ty_data_query( Some(crate::Container::Trait(t)) => t, _ => panic!("associated type not in trait"), }; - let generic_params = type_alias.generic_params(db); + let generic_params = db.generic_params(type_alias.id.into()); let bound_data = chalk_rust_ir::AssociatedTyDatumBound { // FIXME add bounds and where clauses bounds: vec![], @@ -550,7 +549,7 @@ pub(crate) fn trait_datum_query( } let trait_: Trait = from_chalk(db, trait_id); debug!("trait {:?} = {:?}", trait_id, trait_.name(db)); - let generic_params = trait_.generic_params(db); + let generic_params = db.generic_params(trait_.id.into()); let bound_vars = Substs::bound_vars(&generic_params); let flags = chalk_rust_ir::TraitFlags { auto: trait_.is_auto(db), @@ -594,7 +593,7 @@ pub(crate) fn struct_datum_query( let where_clauses = type_ctor .as_generic_def() .map(|generic_def| { - let generic_params = generic_def.generic_params(db); + let generic_params = db.generic_params(generic_def.into()); let bound_vars = Substs::bound_vars(&generic_params); convert_where_clauses(db, generic_def, &bound_vars) }) @@ -634,7 +633,7 @@ fn impl_block_datum( impl_id: ImplId, impl_block: ImplBlock, ) -> Option>> { - let generic_params = impl_block.generic_params(db); + let generic_params = db.generic_params(impl_block.id.into()); let bound_vars = Substs::bound_vars(&generic_params); let trait_ref = impl_block.target_trait_ref(db)?.subst(&bound_vars); let trait_ = trait_ref.trait_; @@ -786,7 +785,7 @@ fn type_alias_associated_ty_value( let assoc_ty = trait_ .associated_type_by_name(db, &type_alias.name(db)) .expect("assoc ty value should not exist"); // validated when building the impl data as well - let generic_params = impl_block.generic_params(db); + let generic_params = db.generic_params(impl_block.id.into()); let bound_vars = Substs::bound_vars(&generic_params); let ty = db.type_for_def(type_alias.into(), crate::ty::Namespace::Types).subst(&bound_vars); let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; -- cgit v1.2.3