From f854a29c9adcfeaa7164928ff91daab9ca9a063c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 6 Jul 2019 17:43:13 +0200 Subject: Make EnumVariant a GenericDef and simplify some code --- crates/ra_hir/src/ty/infer.rs | 7 +------ crates/ra_hir/src/ty/lower.rs | 10 ++++++++++ crates/ra_hir/src/ty/traits/chalk.rs | 6 +----- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index f5d8cd4b1..e79e5e223 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -849,12 +849,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn register_obligations_for_call(&mut self, callable_ty: &Ty) { if let Ty::Apply(a_ty) = callable_ty { if let TypeCtor::FnDef(def) = a_ty.ctor { - let generic_predicates = self.db.generic_predicates(match def { - // TODO add helper function - CallableDef::Function(f) => f.into(), - CallableDef::Struct(s) => s.into(), - CallableDef::EnumVariant(_e) => unimplemented!(), - }); + let generic_predicates = self.db.generic_predicates(def.into()); for predicate in generic_predicates.iter() { let predicate = predicate.clone().subst(&a_ty.parameters); if let Some(obligation) = Obligation::from_predicate(predicate) { diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 24755c6aa..b48ada760 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -509,3 +509,13 @@ pub enum CallableDef { EnumVariant(EnumVariant), } impl_froms!(CallableDef: Function, Struct, EnumVariant); + +impl From for GenericDef { + fn from(def: CallableDef) -> GenericDef { + match def { + CallableDef::Function(f) => f.into(), + CallableDef::Struct(s) => s.into(), + CallableDef::EnumVariant(e) => e.into(), + } + } +} diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 2a0537bc3..4c3744b44 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -428,11 +428,7 @@ pub(crate) fn struct_datum_query( CallableDef::Struct(s) => s.module(db).krate(db), CallableDef::EnumVariant(v) => v.parent_enum(db).module(db).krate(db), } != Some(krate); - let generic_def: GenericDef = match callable { - CallableDef::Function(f) => f.into(), - CallableDef::Struct(s) => s.into(), - CallableDef::EnumVariant(v) => v.parent_enum(db).into(), - }; + let generic_def: GenericDef = callable.into(); let generic_params = generic_def.generic_params(db); let bound_vars = Substs::bound_vars(&generic_params); let where_clauses = convert_where_clauses(db, generic_def, &bound_vars); -- cgit v1.2.3