From 5f39c5794ec2521e9bb4c108771a1644269859ab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 25 Nov 2019 15:41:53 +0300 Subject: Use GenericDefIdMore --- crates/ra_hir/src/ty/infer/path.rs | 2 +- crates/ra_hir/src/ty/lower.rs | 32 ++++++++++++++++--------------- crates/ra_hir/src/ty/method_resolution.rs | 2 +- crates/ra_hir/src/ty/traits/chalk.rs | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index ee54d8217..6165eba4f 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs @@ -203,7 +203,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Container::ImplBlock(_) => self.find_self_types(&def, ty.clone()), Container::Trait(t) => { // we're picking this method - let trait_substs = Substs::build_for_def(self.db, t) + let trait_substs = Substs::build_for_def(self.db, t.id) .push(ty.clone()) .fill(std::iter::repeat_with(|| self.new_type_var())) .build(); diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index da3c8e94a..1ceafd9b1 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -29,8 +29,8 @@ use crate::{ Adt, }, util::make_mut_slice, - Const, Enum, EnumVariant, Function, GenericDef, ImplBlock, ModuleDef, Path, Static, Struct, - Trait, TypeAlias, Union, + Const, Enum, EnumVariant, Function, ImplBlock, ModuleDef, Path, Static, Struct, Trait, + TypeAlias, Union, }; // FIXME: this is only really used in `type_for_def`, which contains a bunch of @@ -261,8 +261,10 @@ impl Ty { let traits = traits_from_env.flat_map(|t| t.all_super_traits(db)); for t in traits { if let Some(associated_ty) = t.associated_type_by_name(db, &segment.name) { - let substs = - Substs::build_for_def(db, t).push(self_ty.clone()).fill_with_unknown().build(); + let substs = Substs::build_for_def(db, t.id) + .push(self_ty.clone()) + .fill_with_unknown() + .build(); // FIXME handle type parameters on the segment return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); } @@ -287,11 +289,11 @@ impl Ty { segment: &PathSegment, resolved: TypableDef, ) -> Substs { - let def_generic: Option = match resolved { - TypableDef::Function(func) => Some(func.into()), + let def_generic: Option = match resolved { + TypableDef::Function(func) => Some(func.id.into()), TypableDef::Adt(adt) => Some(adt.into()), - TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), - TypableDef::TypeAlias(t) => Some(t.into()), + TypableDef::EnumVariant(var) => Some(var.parent_enum(db).id.into()), + TypableDef::TypeAlias(t) => Some(t.id.into()), TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None, }; substs_from_path_segment(db, resolver, segment, def_generic, false) @@ -338,7 +340,7 @@ pub(super) fn substs_from_path_segment( db: &impl HirDatabase, resolver: &Resolver, segment: &PathSegment, - def_generic: Option, + def_generic: Option, add_self_param: bool, ) -> Substs { let mut substs = Vec::new(); @@ -376,7 +378,7 @@ pub(super) fn substs_from_path_segment( // handle defaults if let Some(def_generic) = def_generic { - let default_substs = db.generic_defaults(def_generic); + let default_substs = db.generic_defaults(def_generic.into()); assert_eq!(substs.len(), default_substs.len()); for (i, default_ty) in default_substs.iter().enumerate() { @@ -439,7 +441,7 @@ impl TraitRef { ) -> Substs { let has_self_param = segment.args_and_bindings.as_ref().map(|a| a.has_self_type).unwrap_or(false); - substs_from_path_segment(db, resolver, segment, Some(resolved.into()), !has_self_param) + substs_from_path_segment(db, resolver, segment, Some(resolved.id.into()), !has_self_param) } pub(crate) fn for_trait(db: &impl HirDatabase, trait_: Trait) -> TraitRef { @@ -579,10 +581,10 @@ pub(crate) fn field_types_query( /// these are fine: `T: Foo, U: Foo<()>`. pub(crate) fn generic_predicates_for_param_query( db: &impl HirDatabase, - def: GenericDef, + def: GenericDefId, param_idx: u32, ) -> Arc<[GenericPredicate]> { - let resolver = GenericDefId::from(def).resolver(db); + let resolver = def.resolver(db); resolver .where_predicates_in_scope() // we have to filter out all other predicates *first*, before attempting to lower them @@ -615,8 +617,8 @@ 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); +pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { + let resolver = def.resolver(db); let generic_params = db.generic_params(def.into()); let defaults = generic_params diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index f7905b5ff..c5ab690eb 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -365,7 +365,7 @@ fn generic_implements_goal( self_ty: Canonical, ) -> Canonical> { let num_vars = self_ty.num_vars; - let substs = super::Substs::build_for_def(db, trait_) + let substs = super::Substs::build_for_def(db, trait_.id) .push(self_ty.value) .fill_with_bound_vars(num_vars as u32) .build(); diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index a0dbf6305..0272dd9ae 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -736,7 +736,7 @@ fn closure_fn_trait_impl_datum( let trait_ref = TraitRef { trait_, - substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), + substs: Substs::build_for_def(db, trait_.id).push(self_ty).push(arg_ty).build(), }; let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()).to_chalk(db); -- cgit v1.2.3