diff options
author | Florian Diebold <[email protected]> | 2019-07-06 16:43:13 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-07-06 16:43:13 +0100 |
commit | f854a29c9adcfeaa7164928ff91daab9ca9a063c (patch) | |
tree | cce758eabcbcfbb1bc1673601477a9c86580cb2b /crates/ra_hir/src/ty | |
parent | 065d3987012b138b123f0544de193f8bb560b1b5 (diff) |
Make EnumVariant a GenericDef and simplify some code
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 6 |
3 files changed, 12 insertions, 11 deletions
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> { | |||
849 | fn register_obligations_for_call(&mut self, callable_ty: &Ty) { | 849 | fn register_obligations_for_call(&mut self, callable_ty: &Ty) { |
850 | if let Ty::Apply(a_ty) = callable_ty { | 850 | if let Ty::Apply(a_ty) = callable_ty { |
851 | if let TypeCtor::FnDef(def) = a_ty.ctor { | 851 | if let TypeCtor::FnDef(def) = a_ty.ctor { |
852 | let generic_predicates = self.db.generic_predicates(match def { | 852 | let generic_predicates = self.db.generic_predicates(def.into()); |
853 | // TODO add helper function | ||
854 | CallableDef::Function(f) => f.into(), | ||
855 | CallableDef::Struct(s) => s.into(), | ||
856 | CallableDef::EnumVariant(_e) => unimplemented!(), | ||
857 | }); | ||
858 | for predicate in generic_predicates.iter() { | 853 | for predicate in generic_predicates.iter() { |
859 | let predicate = predicate.clone().subst(&a_ty.parameters); | 854 | let predicate = predicate.clone().subst(&a_ty.parameters); |
860 | if let Some(obligation) = Obligation::from_predicate(predicate) { | 855 | 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 { | |||
509 | EnumVariant(EnumVariant), | 509 | EnumVariant(EnumVariant), |
510 | } | 510 | } |
511 | impl_froms!(CallableDef: Function, Struct, EnumVariant); | 511 | impl_froms!(CallableDef: Function, Struct, EnumVariant); |
512 | |||
513 | impl From<CallableDef> for GenericDef { | ||
514 | fn from(def: CallableDef) -> GenericDef { | ||
515 | match def { | ||
516 | CallableDef::Function(f) => f.into(), | ||
517 | CallableDef::Struct(s) => s.into(), | ||
518 | CallableDef::EnumVariant(e) => e.into(), | ||
519 | } | ||
520 | } | ||
521 | } | ||
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( | |||
428 | CallableDef::Struct(s) => s.module(db).krate(db), | 428 | CallableDef::Struct(s) => s.module(db).krate(db), |
429 | CallableDef::EnumVariant(v) => v.parent_enum(db).module(db).krate(db), | 429 | CallableDef::EnumVariant(v) => v.parent_enum(db).module(db).krate(db), |
430 | } != Some(krate); | 430 | } != Some(krate); |
431 | let generic_def: GenericDef = match callable { | 431 | let generic_def: GenericDef = callable.into(); |
432 | CallableDef::Function(f) => f.into(), | ||
433 | CallableDef::Struct(s) => s.into(), | ||
434 | CallableDef::EnumVariant(v) => v.parent_enum(db).into(), | ||
435 | }; | ||
436 | let generic_params = generic_def.generic_params(db); | 432 | let generic_params = generic_def.generic_params(db); |
437 | let bound_vars = Substs::bound_vars(&generic_params); | 433 | let bound_vars = Substs::bound_vars(&generic_params); |
438 | let where_clauses = convert_where_clauses(db, generic_def, &bound_vars); | 434 | let where_clauses = convert_where_clauses(db, generic_def, &bound_vars); |