diff options
author | Florian Diebold <[email protected]> | 2021-03-20 10:23:59 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-03-20 11:47:12 +0000 |
commit | 7ec3b66f7a3ac0a33cf435bc3596fdac542fc52a (patch) | |
tree | 70a77a26ca09d8d5cd843b1cd9d59af229cd0daf /crates/hir_ty/src/traits.rs | |
parent | 8e7e405f6ab0c1ee10bfdd3d55a97628fe4cd6dd (diff) |
Turn Obligation into something similar to chalk_ir::DomainGoal
This includes starting to make use of Chalk's `Cast` trait.
Diffstat (limited to 'crates/hir_ty/src/traits.rs')
-rw-r--r-- | crates/hir_ty/src/traits.rs | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index 87c92bd12..7dadd1ffb 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs | |||
@@ -9,8 +9,8 @@ use hir_def::{lang_item::LangItemTarget, TraitId}; | |||
9 | use stdx::panic_context; | 9 | use stdx::panic_context; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::HirDatabase, AliasTy, Canonical, DebruijnIndex, HirDisplay, Substitution, TraitRef, Ty, | 12 | db::HirDatabase, AliasTy, Canonical, DebruijnIndex, HirDisplay, Substitution, Ty, TyKind, |
13 | TyKind, TypeWalk, WhereClause, | 13 | TypeWalk, WhereClause, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | use self::chalk::{from_chalk, Interner, ToChalk}; | 16 | use self::chalk::{from_chalk, Interner, ToChalk}; |
@@ -88,20 +88,8 @@ impl<T> InEnvironment<T> { | |||
88 | /// a certain type implements a certain trait. Proving the Obligation might | 88 | /// a certain type implements a certain trait. Proving the Obligation might |
89 | /// result in additional information about inference variables. | 89 | /// result in additional information about inference variables. |
90 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | 90 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
91 | pub enum Obligation { | 91 | pub enum DomainGoal { |
92 | /// Prove that a certain type implements a trait (the type is the `Self` type | 92 | Holds(WhereClause), |
93 | /// parameter to the `TraitRef`). | ||
94 | Trait(TraitRef), | ||
95 | AliasEq(AliasEq), | ||
96 | } | ||
97 | |||
98 | impl Obligation { | ||
99 | pub fn from_predicate(predicate: WhereClause) -> Option<Obligation> { | ||
100 | match predicate { | ||
101 | WhereClause::Implemented(trait_ref) => Some(Obligation::Trait(trait_ref)), | ||
102 | WhereClause::AliasEq(alias_eq) => Some(Obligation::AliasEq(alias_eq)), | ||
103 | } | ||
104 | } | ||
105 | } | 93 | } |
106 | 94 | ||
107 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | 95 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
@@ -136,16 +124,20 @@ impl TypeWalk for AliasEq { | |||
136 | pub(crate) fn trait_solve_query( | 124 | pub(crate) fn trait_solve_query( |
137 | db: &dyn HirDatabase, | 125 | db: &dyn HirDatabase, |
138 | krate: CrateId, | 126 | krate: CrateId, |
139 | goal: Canonical<InEnvironment<Obligation>>, | 127 | goal: Canonical<InEnvironment<DomainGoal>>, |
140 | ) -> Option<Solution> { | 128 | ) -> Option<Solution> { |
141 | let _p = profile::span("trait_solve_query").detail(|| match &goal.value.value { | 129 | let _p = profile::span("trait_solve_query").detail(|| match &goal.value.value { |
142 | Obligation::Trait(it) => db.trait_data(it.hir_trait_id()).name.to_string(), | 130 | DomainGoal::Holds(WhereClause::Implemented(it)) => { |
143 | Obligation::AliasEq(_) => "alias_eq".to_string(), | 131 | db.trait_data(it.hir_trait_id()).name.to_string() |
132 | } | ||
133 | DomainGoal::Holds(WhereClause::AliasEq(_)) => "alias_eq".to_string(), | ||
144 | }); | 134 | }); |
145 | log::info!("trait_solve_query({})", goal.value.value.display(db)); | 135 | log::info!("trait_solve_query({})", goal.value.value.display(db)); |
146 | 136 | ||
147 | if let Obligation::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), .. }) = | 137 | if let DomainGoal::Holds(WhereClause::AliasEq(AliasEq { |
148 | &goal.value.value | 138 | alias: AliasTy::Projection(projection_ty), |
139 | .. | ||
140 | })) = &goal.value.value | ||
149 | { | 141 | { |
150 | if let TyKind::BoundVar(_) = &projection_ty.substitution[0].interned(&Interner) { | 142 | if let TyKind::BoundVar(_) = &projection_ty.substitution[0].interned(&Interner) { |
151 | // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible | 143 | // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible |